出于某种原因,我的规范没有通过。看来 @categories
没有达到规范。
这是 Controller :
class CategoriesController < ApplicationController
def index
@categories = Category.all
end
end
我的规范:
require 'spec_helper'
describe CategoriesController do
describe "GET #index" do
category = FactoryGirl.create(:category)
subject { get :index }
it { @categories.should include category }
end
end
错误:
Failure/Error: @categories.should include category
NoMethodError:
undefined method `include?' for nil:NilClass
最佳答案
不,但您可以使用 assigns
访问它们规范助手:
require 'spec_helper'
describe CategoriesController do
describe "GET #index" do
category = FactoryGirl.create(:category)
subject { get :index }
it { assigns(:categories).should include category }
end
end
关于ruby-on-rails - Controller 中的实例变量是否传递到 Rails 中的规范?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10960086/