0

我在rails 3.2.8 中的新项目中使用Factory_girl_rails。我收到上述错误。谁能建议我该怎么做。

/home/sandhya/.rvm/gems/ruby-1.9.3-p0@robly/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require': cannot load such file -- /home/sandhya/robly/spec/factories (LoadError)
    from /home/sandhya/.rvm/gems/ruby-1.9.3-p0@robly/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `block in require'
    from /home/sandhya/.rvm/gems/ruby-1.9.3-p0@robly/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /home/sandhya/.rvm/gems/ruby-1.9.3-p0@robly/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require'
    from /home/sandhya/robly/spec/spec_helper.rb:6:in `<top (required)>'
    from /home/sandhya/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/sandhya/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/sandhya/robly/spec/models/address_spec.rb:1:in `<top (required)>'
    from /home/sandhya/.rvm/gems/ruby-1.9.3-p0@robly/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `load'
    from /home/sandhya/.rvm/gems/ruby-1.9.3-p0@robly/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `block in load_spec_files'
    from /home/sandhya/.rvm/gems/ruby-1.9.3-p0@robly/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `map'
    from /home/sandhya/.rvm/gems/ruby-1.9.3-p0@robly/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `load_spec_files'
    from /home/sandhya/.rvm/gems/ruby-1.9.3-p0@robly/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:22:in `run'
    from /home/sandhya/.rvm/gems/ruby-1.9.3-p0@robly/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:69:in `run'
    from /home/sandhya/.rvm/gems/ruby-1.9.3-p0@robly/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:8:in `block in autorun'

我的 gemfile 是这样的:

团体 :

test do
  gem 'rspec-rails'
  gem "factory_girl_rails"
  gem "capybara"
end

在我的 factory.rb 我有

FactoryGirl.define do
  factory :address do |v|
    v.email "test@email.com"
    v.state "Karnataka"
    v.country "India"
    v.zip_code "560061"
    v.office_mobiel "9999999999"
    v.company "Some Company"
    v.city "Bangalore"
  end
end
4

2 回答 2

0

通常,FactoryGirl 应该自己加载 factory.rb。但是您是否在您的 spec_helper.rb 文件中包含了 FactoryGirl?

如果是,则需要更多信息,至少是堆栈跟踪中提到的两个文件的内容:/spec/spec_helper.rb 和 /spec/models/address_spec.rb

于 2012-11-01T12:11:41.147 回答
0

当我将 factory_girl 从 3.5.0 升级到 4.1.0 时,我也遇到了这个错误。我曾经在 3.5.0 上写过“require 'factories'”,没有出现错误。也许你在 4.1.0 上不需要“require 'factories'”

于 2012-12-01T00:57:35.280 回答