让factory_girl在Rails3中工作
在我的一生中,我无法让 factory_girl
在 Rails3 中工作。我创建了一个全新的应用程序。我的 Gemfile:
gem "rspec"
gem "rspec-rails"
gem "factory_girl_rails"
application.rb
中的生成器如下所示:
config.generators do |g|
g.test_framework :rspec, :fixture => true, :views => false, :fixture_replacement => :factory_girl
end
然后,使用生成器创建一个新模型:
> rails g model Addon name:string
invoke active_record
create db/migrate/20101223205918_create_addons.rb
create app/models/addon.rb
invoke rspec
create spec/models/addon_spec.rb
error factory_girl [not found]
我错过了什么?当然,我确实运行了bundle install
...我尝试环顾四周,但找不到有关factory_girl和rails3的任何像样的文档。
For the life of me, I can't get factory_girl
to work in Rails3. I created a brand new application. My Gemfile:
gem "rspec"
gem "rspec-rails"
gem "factory_girl_rails"
The generators in application.rb
like so:
config.generators do |g|
g.test_framework :rspec, :fixture => true, :views => false, :fixture_replacement => :factory_girl
end
Then, using the generator to create a new model:
> rails g model Addon name:string
invoke active_record
create db/migrate/20101223205918_create_addons.rb
create app/models/addon.rb
invoke rspec
create spec/models/addon_spec.rb
error factory_girl [not found]
What'd I miss? I did run bundle install
of course... I tried looking around, but can't find any decent documentation on factory_girl and rails3.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要的是 https://github.com/indirect/rails3-generators。
What you need is https://github.com/indirect/rails3-generators.
这是迄今为止 Rails 3.2 中的正确方法:
This is the proper approach in Rails 3.2 as of today:
某些用户可能正在使用
factory_girl
。确保您使用的是factory_girl_rails
。Some users may be using
factory_girl
. Make sure that you are usingfactory_girl_rails
.