diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2017-02-05 17:02:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-05 17:02:58 +0100 |
commit | 2cb6c27310452da11b93d729c3b760ce988106e1 (patch) | |
tree | 85d9135baa1eab5e8e228164bb8e71c4f585ec13 | |
parent | 28934172042505156f7c60ac2534dd92f32170d9 (diff) | |
parent | 1c8a4cdf63134f34d638703a956c2706d8e3789f (diff) | |
download | rails-2cb6c27310452da11b93d729c3b760ce988106e1.tar.gz rails-2cb6c27310452da11b93d729c3b760ce988106e1.tar.bz2 rails-2cb6c27310452da11b93d729c3b760ce988106e1.zip |
Merge pull request #27802 from domcleal/27801-multiple-rake-tests
Collect all file patterns when running multiple rake test tasks
-rw-r--r-- | railties/CHANGELOG.md | 6 | ||||
-rw-r--r-- | railties/lib/rails/test_unit/minitest_plugin.rb | 14 | ||||
-rw-r--r-- | railties/test/application/test_runner_test.rb | 15 |
3 files changed, 28 insertions, 7 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 0b2fb3e9c8..7aee513a99 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,9 @@ +* Fix running multiple tests in one `rake` command + + e.g. `bin/rake test:models test:controllers` + + *Dominic Cleal* + * Add option to configure Ruby's warning behaviour to test runner. *Yuji Yaginuma* diff --git a/railties/lib/rails/test_unit/minitest_plugin.rb b/railties/lib/rails/test_unit/minitest_plugin.rb index e3c70b0b3d..4df3e7f0f2 100644 --- a/railties/lib/rails/test_unit/minitest_plugin.rb +++ b/railties/lib/rails/test_unit/minitest_plugin.rb @@ -59,19 +59,18 @@ module Minitest options[:color] = true options[:output_inline] = true - options[:patterns] = defined?(@rake_patterns) ? @rake_patterns : opts.order! + options[:patterns] = opts.order! unless run_via[:rake] end - # Running several Rake tasks in a single command would trip up the runner, - # as the patterns would also contain the other Rake tasks. def self.rake_run(patterns) # :nodoc: - @rake_patterns = patterns + run_via[:rake] = true + ::Rails::TestRequirer.require_files(patterns) autorun end module RunRespectingRakeTestopts def run(args = []) - if defined?(@rake_patterns) + if run_via[:rake] args = Shellwords.split(ENV["TESTOPTS"] || "") end @@ -86,8 +85,9 @@ module Minitest def self.plugin_rails_init(options) ENV["RAILS_ENV"] = options[:environment] || "test" - # If run via `ruby` we've been passed the files to run directly. - unless run_via[:ruby] + # If run via `ruby` we've been passed the files to run directly, or if run + # via `rake` then they have already been eagerly required. + unless run_via[:ruby] || run_via[:rake] ::Rails::TestRequirer.require_files(options[:patterns]) end diff --git a/railties/test/application/test_runner_test.rb b/railties/test/application/test_runner_test.rb index 4e36d126fc..d3d5b6d6dd 100644 --- a/railties/test/application/test_runner_test.rb +++ b/railties/test/application/test_runner_test.rb @@ -536,6 +536,21 @@ module ApplicationTests assert_match "seed=1234", output, "passing TEST= should run selected test" end + def test_rake_runs_multiple_test_tasks + create_test_file :models, "account" + create_test_file :controllers, "accounts_controller" + output = Dir.chdir(app_path) { `bin/rake test:models test:controllers TESTOPTS='-v'` } + assert_match "AccountTest#test_truth", output + assert_match "AccountsControllerTest#test_truth", output + end + + def test_rake_db_and_test_tasks_parses_args_correctly + create_test_file :models, "account" + output = Dir.chdir(app_path) { `bin/rake db:migrate test:models TESTOPTS='-v' && echo ".tables" | rails dbconsole` } + assert_match "AccountTest#test_truth", output + assert_match "ar_internal_metadata", output + end + def test_warnings_option app_file "test/models/warnings_test.rb", <<-RUBY require 'test_helper' |