我正在努力将我的项目的测试套件迁移到rspec。我试图访问我的灯具时出现以下错误:
未定义的方法`[]'为零:NilClass
以下是一个示例规范文件:
require 'rails_helper'
feature "edit contacts" do
fixtures :contacts
before(:all) do
@thing = contacts(:two)
end
scenario "do a thing" do
visit new_contact_path
end
end
我在调用before
contacts(:two)
块中收到错误消息
这是来自rails_helper.rb的配置信息
RSpec.configure do |config|
config.infer_spec_type_from_file_location!
config.fixture_path = "#{::Rails.root}/spec/fixtures"
end
以下是Gemfile.lock的版本信息:
rails (4.0.13)
rspec-core (3.2.2)
rspec-expectations (3.2.0)
rspec-mocks (3.2.1)
rspec-rails (3.2.1)
rspec-support (3.2.2)
如果需要,我很乐意提供任何其他支持信息。谢谢你看一看,感谢任何帮助!
答案 0 :(得分:0)
before(:each)
代替before(:all)
。
显然,使用:每个触发'before_setup' ActiveRecord :: FixtureSet中的回调设置所有灯具,并且:所有灯具都没有。
根据docs:
之前(:每个)块在每个示例之前运行之前(:all)块在组中的所有示例之前运行一次