Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collect all file patterns when running multiple rake test tasks #27802

Merged
merged 1 commit into from
Feb 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions railties/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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*
Expand Down
14 changes: 7 additions & 7 deletions railties/lib/rails/test_unit/minitest_plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,18 @@ def self.plugin_rails_options(opts, options)

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

Expand All @@ -86,8 +85,9 @@ def run(args = [])
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

Expand Down
15 changes: 15 additions & 0 deletions railties/test/application/test_runner_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,21 @@ def test_rake_passes_multiple_TESTOPTS_to_minitest
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` }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't the piping into dbconsole make the test stall?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test doesn't hang if that's what you mean, but it may take a bit longer to run. I wanted to check that the db:migrate task ran too, and this is the method used by previous tests.

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'
Expand Down