Ruby on rails rspec新手,期待<&引用;索引“&燃气轮机;但是使用<&引用&引用&燃气轮机;
卡控制器规范rbRuby on rails rspec新手,期待<&引用;索引“&燃气轮机;但是使用<&引用&引用&燃气轮机;,ruby-on-rails,ruby,rspec,Ruby On Rails,Ruby,Rspec,卡控制器规范rb FactoryGirl.define do factory :card do card_no '6217920016000864' factory :invalid_card do card_no nil end end end describe CardsController do describe 'GET #index' do it 'assigns card' do card = create(:c
FactoryGirl.define do
factory :card do
card_no '6217920016000864'
factory :invalid_card do
card_no nil
end
end
end
describe CardsController do
describe 'GET #index' do
it 'assigns card' do
card = create(:card)
get :index
expect(assigns(:card)).to eq([card])
end
it 'show index' do
expect(response).to render_template("index")
end
end
end
cards\u controller.rb
FactoryGirl.define do
factory :card do
card_no '6217920016000864'
factory :invalid_card do
card_no nil
end
end
end
describe CardsController do
describe 'GET #index' do
it 'assigns card' do
card = create(:card)
get :index
expect(assigns(:card)).to eq([card])
end
it 'show index' do
expect(response).to render_template("index")
end
end
end
class CardsController
像这样的两个错误expecting但使用
和expected(分配(:卡片))渲染。到eq([card])得到零
帮帮我,谢谢 这个
class CardsController < ApplicationController
def index
if current_user.login_name=="admin"
#admin
@cardlist = set_paginate Card
else
#普通管理员
@restaurant_ids = Restaurant.where('parent_id = ? or id = ?', current_user.restaurant.id, current_user.restaurant.id).collect { |r| r.id }
@cardlist = set_paginate Card.where('restaurant_id in (?) ', @restaurant_ids)
end
end
end
因为我相信您将数据分配给卡
(更新问题后:卡列表
)
这个
应为,但呈现为
因为您没有在测试中调用get:index
class CardsController < ApplicationController
def index
if current_user.login_name=="admin"
#admin
@cardlist = set_paginate Card
else
#普通管理员
@restaurant_ids = Restaurant.where('parent_id = ? or id = ?', current_user.restaurant.id, current_user.restaurant.id).collect { |r| r.id }
@cardlist = set_paginate Card.where('restaurant_id in (?) ', @restaurant_ids)
end
end
end
因为我相信您将数据分配给卡
(更新问题后:卡列表
)
这个
应为,但呈现为
因为您没有在测试中调用get:index
class CardsController < ApplicationController
def index
if current_user.login_name=="admin"
#admin
@cardlist = set_paginate Card
else
#普通管理员
@restaurant_ids = Restaurant.where('parent_id = ? or id = ?', current_user.restaurant.id, current_user.restaurant.id).collect { |r| r.id }
@cardlist = set_paginate Card.where('restaurant_id in (?) ', @restaurant_ids)
end
end
end
因为我相信您将数据分配给卡
(更新问题后:卡列表
)
这个
应为,但呈现为
因为您没有在测试中调用get:index
class CardsController < ApplicationController
def index
if current_user.login_name=="admin"
#admin
@cardlist = set_paginate Card
else
#普通管理员
@restaurant_ids = Restaurant.where('parent_id = ? or id = ?', current_user.restaurant.id, current_user.restaurant.id).collect { |r| r.id }
@cardlist = set_paginate Card.where('restaurant_id in (?) ', @restaurant_ids)
end
end
end
因为我相信您将数据分配给卡
(更新问题后:卡列表
)
这个
应为,但呈现为
因为您没有在test中调用
get:index
第一个test是针对data controller向视图提供的内容。查看您拥有的控制器,您应该检查分配(:cartdlist)
我认为。并使用match_array
而不是eq
第二个测试不会呈现任何内容,因为它不会去任何地方(您的get
仅用于第一个it
块)。所以试试这个:
expecting <"index"> but rendering with <"">
在您的情况下,这可能不是问题所在,因为您遇到了不同的错误,但要允许expect语法,您的spec_helper.rb文件应该包含:
describe CardsController do
describe 'GET #index' do
before do
card = create(:card)
get :index
end
it 'assigns card' do
expect(assigns(:cardlist)).to match_array([card])
end
it 'show index' do
expect(response).to render_template("index")
end
end
end
或
c.syntax=[:应该,:期望]
对于这两种情况,第一个测试是针对data controller向视图提供的内容。查看您拥有的控制器,您应该检查
分配(:cartdlist)
我认为。并使用match_array
而不是eq
第二个测试不会呈现任何内容,因为它不会去任何地方(您的get
仅用于第一个it
块)。所以试试这个:
expecting <"index"> but rendering with <"">
在您的情况下,这可能不是问题所在,因为您遇到了不同的错误,但要允许expect语法,您的spec_helper.rb文件应该包含:
describe CardsController do
describe 'GET #index' do
before do
card = create(:card)
get :index
end
it 'assigns card' do
expect(assigns(:cardlist)).to match_array([card])
end
it 'show index' do
expect(response).to render_template("index")
end
end
end
或
c.syntax=[:应该,:期望]
对于这两种情况,第一个测试是针对data controller向视图提供的内容。查看您拥有的控制器,您应该检查
分配(:cartdlist)
我认为。并使用match_array
而不是eq
第二个测试不会呈现任何内容,因为它不会去任何地方(您的get
仅用于第一个it
块)。所以试试这个:
expecting <"index"> but rendering with <"">
在您的情况下,这可能不是问题所在,因为您遇到了不同的错误,但要允许expect语法,您的spec_helper.rb文件应该包含:
describe CardsController do
describe 'GET #index' do
before do
card = create(:card)
get :index
end
it 'assigns card' do
expect(assigns(:cardlist)).to match_array([card])
end
it 'show index' do
expect(response).to render_template("index")
end
end
end
或
c.syntax=[:应该,:期望]
对于这两种情况,第一个测试是针对data controller向视图提供的内容。查看您拥有的控制器,您应该检查
分配(:cartdlist)
我认为。并使用match_array
而不是eq
第二个测试不会呈现任何内容,因为它不会去任何地方(您的get
仅用于第一个it
块)。所以试试这个:
expecting <"index"> but rendering with <"">
在您的情况下,这可能不是问题所在,因为您遇到了不同的错误,但要允许expect语法,您的spec_helper.rb文件应该包含:
describe CardsController do
describe 'GET #index' do
before do
card = create(:card)
get :index
end
it 'assigns card' do
expect(assigns(:cardlist)).to match_array([card])
end
it 'show index' do
expect(response).to render_template("index")
end
end
end
或
c.syntax=[:应该,:期望]
对于这两个请修复格式并包含部分控制器。您的
索引
操作似乎无法按预期工作。如果您希望人们对您的CardsController#index
操作发表评论,您应该发布该操作的代码。是的,请共享您的控制器代码。同时测试单卡在索引中的动作也不正常;索引通常是一个卡片列表(@cards
)。单卡@card
是您在show action中所期望的。在spec\u helper.rb
中有此设置config.render\u views
?请修复格式并包括您所拥有的控制器的一部分。您的index
操作似乎无法按预期工作。如果您希望人们对您的CardsController#index
操作发表评论,您应该发布该操作的代码。是的,请共享您的控制器代码。同时测试单卡在索引中的动作也不正常;索引通常是一个卡片列表(@cards
)。单卡@card
是您在show action中所期望的。在spec\u helper.rb
中有此设置config.render\u views
?请修复格式并包括您所拥有的控制器的一部分。您的index
操作似乎无法按预期工作。如果您希望人们对您的CardsController#index
操作发表评论,您应该发布该操作的代码。是的,请共享您的控制器代码。同时测试单卡在索引中的动作也不正常;索引通常是一个卡片列表(@cards
)。单卡@card
是您在显示操作中所期望的。在spec\u helper.rb
中有此设置config.render\u views
?请修复格式