Rails 应该和factory_girl 设置

发布于 2024-09-04 19:21:23 字数 970 浏览 7 评论 0原文

我已经安装了shoulda和factory_girl,我可以很好地运行shoulda,但是当我将以下内容添加

require 'factory_girl'

Factory.define :user do |u|
  u.mail '[email protected]'
  u.pass 'secret'
end

到我的test/test_helper.rb时,我收到此错误:

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

当我执行 rake test:units 时,

我已经使用以下命令安装了两个 gem:

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

并可以看到两者它们安装得很好。

  • 顺便说一句,这也可以正常工作:

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

<块引用>

需要“工厂女孩” => []

所以需要宝石似乎有效

I have installed both shoulda and factory_girl, I can run shoulda just fine, but when I add this:

require 'factory_girl'

Factory.define :user do |u|
  u.mail '[email protected]'
  u.pass 'secret'
end

to my test/test_helper.rb I'm getting this error:

/test/test_helper.rb:1:in `require': no such file to load -- factory_girl (LoadError)

when I execute rake test:units

I have installed both gems using:

sudo gem install thoughtbot-shoulda --source=http://gems.github.com
sudo gem install thoughtbot-factory_girl --source=http://gems.github.com

and can see both of them being installed fine.

  • And by the way, this works fine as well:

script/console
Loading development environment (Rails 2.3.8)

require 'factory_girl'
=> []

so requiring the gems seems to be working

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无所的.畏惧 2024-09-11 19:21:23

需要检查的几件事:

  • 不要再使用 --source=http://gems.github.com 。这已被 gemcutter.org 弃用。
  • 不要使用“thoughtbot-gem_name” - 这又被 gemcutter.org 弃用。只需执行 sudo gem installfactory_girl shoulda
  • 确保您的 config/environments/test.rb 文件中有 config.gem 'factory_girl'

Couple things to check:

  • Don't use --source=http://gems.github.com anymore. This has been deprecated in favor for gemcutter.org
  • Don't use "thoughtbot-gem_name" - again this was deprecated by gemcutter.org. Just do sudo gem install factory_girl shoulda
  • Make sure you have config.gem 'factory_girl' in your config/environments/test.rb file.
南巷近海 2024-09-11 19:21:23

如果您正在使用 spork,请确保重新启动它。我花了一些时间才意识到这一点。

if you are using spork, make sure to restart it. Took me a few moments to realize that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文