How to re-enable Test::Unit in Rails 4 after 'rails new app --skip-test-unit'

我是研究僧i 提交于 2019-12-23 12:32:36

问题


I used

rails new app --skip-test-unit

because initially, I thought I could add testing later.

I developed a significant portion of my app.

Now, I would like to add Test::Unit but I couldn't find any documentation on how to do it. Googling only lead me to the Rails Guides and tutorials that assume you didn't ask rails to skip the testing framework when you first created the app.

I know I might be able to figure out what _test.rb files to add manually and how to modify the Rakefile (by looking at an app that was created without skipping tests) but I prefer to find an easier approach if it exists.

I think the --skip-test-unit writes something somewhere to tell the Rails generators not to generate tests, and as well, it removes the rake tasks related to tests.

It would be good to find out if there is a command (or a config file modification) to restore Test::Unit to my Rails app.

I don't necessarily mind if the existing controllers/models do not have tests and I don't necessarily want to add tests to them, but going forward, I would like tests to be generated by the generators, and I would like to be able to run

rake test

回答1:


config/application.rb:

uncomment the line that says:

require "rails/test_unit/railtie"



回答2:


TestUnit:
  test_unit:controller
  test_unit:generator
  test_unit:helper
  test_unit:integration
  test_unit:job
  test_unit:mailer
  test_unit:model
  test_unit:plugin
  test_unit:scaffold

this used in conjunction with the rails generate command will generate you the corresponding test case template.

eg:

rails g test_unit:model School

will generate

test/models/school_test.rb



来源:https://stackoverflow.com/questions/29325977/how-to-re-enable-testunit-in-rails-4-after-rails-new-app-skip-test-unit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!