我忘了使用-T参数创建我的应用程序,现在它已经安装了test :: unit。在创建应用程序之后,如何删除test :: unit并阻止它为生成的每个控制器/模型创建测试?谢谢
答案 0 :(得分:12)
在你的config / application.rb中试试
config.generators do |g|
g.test_framework :rspec #=> or whatever
end
回复评论
尝试
config.generators do |g|
g.test_framework nil
end
可能不是“最合适”或Rails-ish方式,但它可以正常工作
<强>更新强>
我今天正在阅读Rails初始化指南,并意识到Test :: Unit最可能的原因仍然是这一行:
require 'rails/all'
可以替换为:
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
这应该解决这个问题。如果您使用的是Rails 3.1.x,那么您还需要包含
require "sprockets/railtie"
如果您打算使用资产管道。
更新2
对于Rails 3.2,你应该使用它:
config.app_generators do |c|
c.test_framework :rspec, :fixture => true,
:fixture_replacement => nil
c.integration_tool :rspec
c.performance_tool :rspec
end
答案 1 :(得分:7)
删除测试:Rails 4中的单位:
从 config / application.rb :
替换以下行require 'rails/all'
使用:
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "sprockets/railtie"
您也可以安全地删除测试目录。
答案 2 :(得分:6)
在 Rails 4 中使用rails new APP_NAME --skip-test-unit
构建新应用程序会导致:
require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "sprockets/railtie"
# require "rails/test_unit/railtie"
答案 3 :(得分:5)
On Rails 5.1和Rails 5.2
config/application.rb
中的
删除或注释
require 'rails/all'
然后包括
require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "action_cable/engine"
require "sprockets/railtie"
# require "rails/test_unit/railtie"
此外,如果您不希望生成系统测试文件,请添加以下内容:
# Don't generate system test files.
config.generators.system_tests = nil
完成此操作后,您可以删除test
目录
答案 4 :(得分:1)
正如我在类似question and answer中提到的那样,最干净的方法就是这样做......
对于Rails 3,要从应用程序中删除test_unit,您需要删除(或注释掉)config/application.rb
中的test_unit Railtie:
# require "rails/test_unit/railtie"
如果您对这行代码的作用感到好奇,请查看目前看起来像这样的railties/lib/rails/test_unit/railtie.rb source:
module Rails
class TestUnitRailtie < Rails::Railtie
config.app_generators do |c|
c.test_framework :test_unit, :fixture => true,
:fixture_replacement => nil
c.integration_tool :test_unit
c.performance_tool :test_unit
end
rake_tasks do
load "rails/test_unit/testing.rake"
end
end
end
答案 5 :(得分:0)
在Rails 6
中的config/application.rb
上替换
require 'rails/all'
针对:
require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "active_storage/engine"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_mailbox/engine"
require "action_text/engine"
require "action_view/railtie"
require "action_cable/engine"
require "sprockets/railtie"
# require "rails/test_unit/railtie"