Rails 应该和factory_girl 设置
我已经安装了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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
需要检查的几件事:
--source=http://gems.github.com
。这已被 gemcutter.org 弃用。sudo gem installfactory_girl shoulda
config.gem 'factory_girl'
。Couple things to check:
--source=http://gems.github.com
anymore. This has been deprecated in favor for gemcutter.orgsudo gem install factory_girl shoulda
config.gem 'factory_girl'
in your config/environments/test.rb file.如果您正在使用 spork,请确保重新启动它。我花了一些时间才意识到这一点。
if you are using spork, make sure to restart it. Took me a few moments to realize that.