运行rspec时,我收到以下错误:
/2.2.0/rubygems/core_ext/kernel_require.rb:54:in require': cannot load such file -- factory_girl_rails (LoadError) from /Users/radhikabhatt/.rbenv/versions/2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:inrequire'
from /Users/radhikabhatt/Desktop/work/cl_portalmiudla/spec/spec_helper.rb:19:in <top (required)>' from /Users/radhikabhatt/.rbenv/versions/2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:inrequire'
from /Users/radhikabhatt/.rbenv/versions/2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
我的gemfile.lock看起来像:
factory_girl (4.5.0)
activesupport (>= 3.0.0)
factory_girl_rails (4.5.0)
factory_girl (~> 4.5.0)
spec_helper.rb有一行require 'factory_girl_rails'
。如果我在这里错过了什么,请告诉我。
答案 0 :(得分:0)
factory_girl_rails
是一个railtie
gem,这意味着它将挂钩到rails生命周期并注册自己。所以你不需要隐含地要求它。事实上,你甚至不能要求它,这是你的问题中的错误原因。您需要做的就是将它包含在Gemfile中并捆绑它。然后你就可以获得factory_girl的生成器了。
为了将factory_girl
用于rspec,您可以添加spec_helper.rb,如下所示:
# RSpec
# spec/support/factory_girl.rb
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
end