0

我已经安装了 shoulda 和 factory_girl,我可以很好地运行 shoulda,但是当我添加这个时:

require 'factory_girl'

Factory.define :user do |u|
  u.mail 'test@example.com'
  u.pass 'secret'
end

到我的 test/test_helper.rb 我收到这个错误:

/test/test_helper.rb:1:in `require': 没有要加载的文件 -- factory_girl (LoadError)

当我执行 rake test:units

我已经使用以下方法安装了两个 gem:

sudo gem installthoughtbot-should --source= http://gems.github.com sudo gem installthoughtbot-factory_girl --source= http://gems.github.com

并且可以看到它们都安装得很好。

  • 顺便说一句,这也很好用:

脚本/控制台加载开发环境(Rails 2.3.8)

需要'factory_girl' => []

所以要求宝石似乎有效

4

2 回答 2

2

几件事情要检查:

  • 不要再使用--source=http://gems.github.com了。这已被 gemcutter.org 弃用
  • 不要使用“thoughtbot-gem_name”——这又被 gemcutter.org 弃用了。做就是了sudo gem install factory_girl shoulda
  • 确保您config.gem 'factory_girl'的 config/environments/test.rb 文件中有。
于 2010-06-07T20:47:24.473 回答
1

如果您使用的是 spork,请确保重新启动它。我花了几分钟才意识到这一点。

于 2010-12-03T05:51:07.540 回答