Rails生成器无法生成正确的测试模板 [英] Rails generators not generating the proper test templates

查看:100
本文介绍了Rails生成器无法生成正确的测试模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目住在这里: https://github.com/jonesdeini/ICanHazSandvich

我正在使用minitest-rails进行设置,但是我无法让生成器生成正确的测试模板.

I'm getting setup using minitest-rails add I can't get the generators to generate the correct test templates.

从我的application.rb:

from my application.rb:

config.generators do |g|
  g.test_framework :mini_test, :spec => true, :fixture => false
end

即使使用"g.test_framework nil",我仍然会生成相同的测试模板:

even with "g.test_framework nil" I still get the same test templates generated:

输出:

rails g model Foo
    invoke  active_record
    create    db/migrate/20120827160129_create_foos.rb
    create    app/models/foo.rb
    invoke    test_unit
    create      test/unit/foo_test.rb
    invoke      factory_girl
    create        test/factories/foos.rb

即使使用"rails g model Foo --spec",也会生成相同的文件. 我正在使用Rails 3.2.8和ruby-1.9.3-p194

Even with "rails g model Foo --spec" the same files are generated. I'm using rails 3.2.8 and ruby-1.9.3-p194

感谢您的帮助!

宝石文件:

group :development, :test do
  gem 'factory_girl_rails'
  gem 'minitest-rails'
  gem 'minitest-rails-capybara'
 end

已针对此问题提交了拉取请求 https://github.com/thoughtbot/factory_girl_rails/pull/68

A pull request has been submitted for this issue https://github.com/thoughtbot/factory_girl_rails/pull/68

推荐答案

问题是factory_girl_rails gem.该轨道假定为rspectest_unit,并且其配置与您的配置冲突.这是我要解决的方法:

The problem is the factory_girl_rails gem. That railtie is assuming either rspec or test_unit, and its configuration is conflicting with your configuration. Here is how I would resolve this:

将依赖关系更改为Gemfile文件中的factory_girl gem:

Change the dependency to the factory_girl gem in your Gemfile file:

group :development, :test do
  gem 'factory_girl'
  gem 'minitest-rails'
  gem 'minitest-rails-capybara'
end

配置您的应用以在config/application.rb文件中使用FactoryGirl:

Configure your app to use FactoryGirl in your config/application.rb file:

config.generators do |g|
  g.test_framework :mini_test, spec: true, fixture: false,
                               fixture_replacement: :factory_girl
end

嗯,那不是完全正确的.我要如何解决,是彻底删除FactoryGirl,但这是对另一个问题的答案...

Well, that's not entirely true. How I would really resolve it is to remove FactoryGirl completely, but that's an answer to a different question...

这篇关于Rails生成器无法生成正确的测试模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆