无法加载此类文件 - / home / sandhya / robly / spec / factories(LoadError)

时间:2012-10-27 07:15:24

标签: ruby-on-rails-3.2 factory-bot rspec-rails

我在我的新项目中使用Factory_girl_rails,这是在rails 3.2.8中。我收到了上述错误。 任何人都可以建议我做什么。

/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

在我的工厂里。我有

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

2 个答案:

答案 0 :(得分:0)

通常,FactoryGirl应自行加载factories.rb。但是你在spec_helper.rb文件中包含了FactoryGirl吗?

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

答案 1 :(得分:0)

当我将factory_girl从3.5.0升级到4.1.0时,我也遇到了这个错误。 我过去常常在3.5.0上写“require'stage'”并且没有发生错误。 也许你不需要4.1.0上的“需要'工厂'”