Actions
Refactor #16557
closedMove tests into test/models, controllers, helpers dirs.
Difficulty:
Triaged:
Description
Rails 4 recommends using test/models/, test/controllers/, test/mailers/ and test/helpers/ to match the app/ layout for tests rather than having test/unit/ contain model and general unit/service object tests.
This is also important under Rails 5 which fails to run rake test
when these directories don't exist:
$ rake test:units rake aborted! LoadError: cannot load such file -- /home/dcleal/code/foreman/foreman/test/models /home/dcleal/.rvm/gems/ruby-2.3.0@foreman/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `require' /home/dcleal/.rvm/gems/ruby-2.3.0@foreman/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `block in require' /home/dcleal/.rvm/gems/ruby-2.3.0@foreman/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:259:in `load_dependency' /home/dcleal/.rvm/gems/ruby-2.3.0@foreman/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `require' /home/dcleal/.rvm/gems/ruby-2.3.0@foreman/gems/railties-5.0.0/lib/rails/test_unit/test_requirer.rb:11:in `block in require_files' /home/dcleal/.rvm/gems/ruby-2.3.0@foreman/gems/railties-5.0.0/lib/rails/test_unit/test_requirer.rb:10:in `each' /home/dcleal/.rvm/gems/ruby-2.3.0@foreman/gems/railties-5.0.0/lib/rails/test_unit/test_requirer.rb:10:in `require_files' /home/dcleal/.rvm/gems/ruby-2.3.0@foreman/gems/railties-5.0.0/lib/rails/test_unit/minitest_plugin.rb:76:in `plugin_rails_init' /home/dcleal/.rvm/gems/ruby-2.3.0@foreman/gems/minitest-5.1.0/lib/minitest.rb:73:in `block in init_plugins' /home/dcleal/.rvm/gems/ruby-2.3.0@foreman/gems/minitest-5.1.0/lib/minitest.rb:71:in `each' /home/dcleal/.rvm/gems/ruby-2.3.0@foreman/gems/minitest-5.1.0/lib/minitest.rb:71:in `init_plugins' /home/dcleal/.rvm/gems/ruby-2.3.0@foreman/gems/minitest-5.1.0/lib/minitest.rb:122:in `run' /home/dcleal/.rvm/gems/ruby-2.3.0@foreman/gems/railties-5.0.0/lib/rails/test_unit/minitest_plugin.rb:64:in `rake_run' /home/dcleal/.rvm/gems/ruby-2.3.0@foreman/gems/railties-5.0.0/lib/rails/test_unit/testing.rake:43:in `block (2 levels) in <top (required)>'
Moving models into test/models/ and using test/unit/ for other objects would also allow test/lib/ to be rolled into test/unit/ in a more logical way, which allows us to remove the custom test:lib
rake task.
(http://guides.rubyonrails.org/testing.html#rails-sets-up-for-testing-from-the-word-go and https://github.com/rails/rails/blob/4-2-stable/railties/lib/rails/test_unit/testing.rake show possible directories)
Actions