-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Conversation
Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @chancancode (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review. Please see the contribution instructions for more information. |
f42effb
to
065b5ca
Compare
Thanks @domcleal for the bug fix.. Do you mind adding a changelog entry for this fix, and rebasing your PR against latest master? |
@@ -60,7 +60,7 @@ def self.plugin_rails_options(opts, options) | |||
# 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 | |||
(@rake_patterns ||= []).push(*patterns) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this negate what the comment says above? In other words, do we need rake_run
anymore? It might have become obsolete after moving to autorun
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment is still valid with @rake_patterns
- it's targeted at fixing rake db:migrate test
rather than two test tasks. Without it, the plugin would run tests listed in the argument list, which is ['db:migrate' ,'test']
- instead rake_run
stores the paths from test:* tasks so running test + non-test tasks works.
This was originally added in df744b5, but missing a test to cover it and the conditional above, so I added one in b5a9428.
I think you're right that rake_run
(or rather @rake_patterns
) is a bit obsolete now that autorun
is used. The test files can be required immediately and autorun
will handle it. I've removed @rake_patterns
in a12803d, but kept rake_run
as it makes the tasks in railties/lib/rails/test_unit/testing.rake a little less repetitive.
065b5ca
to
a12803d
Compare
Aren't we going to require_files twice now? https://github.com/domcleal/rails/blob/a12803dc17417437ddbbe93bc798d6b779363331/railties/lib/rails/test_unit/minitest_plugin.rb#L90 |
a12803d
to
d936d9f
Compare
@arthurnn thanks, you're right that it was called twice. |
|
||
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` } |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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, "passing test:models should run test/models/" | ||
assert_match "ar_internal_metadata", output, "tables should be dumped" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's kill the custom messages on assert_match
here and above. Think the intention is sufficiently clear in the test code itself.
# 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 included. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
included
is a new term, let's say eagerly required
to stick with the established terminology.
def self.rake_run(patterns) # :nodoc: | ||
@rake_patterns = patterns | ||
::Rails::TestRequirer.require_files patterns | ||
run_via[:rake] = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think it makes more sense to assign run_via
as the first step and then require the files.
def self.rake_run(patterns) # :nodoc: | ||
@rake_patterns = patterns | ||
::Rails::TestRequirer.require_files patterns |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add parens around here: ::Rails::TestRequirer.require_files(patterns)
railties/CHANGELOG.md
Outdated
@@ -1,3 +1,7 @@ | |||
* Fix running multiple test\* tasks specified in a single `rake` command |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't understand what test\*
is supposed to mean.
I'd write:
* Fix running multiple tests in one `rake` command.
E.g. `bin/rake test:models test:controllers`
# …
def test_rake_runs_multiple_test_tasks | ||
create_test_file :models, "account" | ||
create_test_file :controllers, "accountcontroller" | ||
output = Dir.chdir(app_path) { `bin/rake test:models test:controllers TESTOPTS='-v'` } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we pass in TESTOPTS
here and below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It prints the names of the tests, so it can assert the expected tests ran using output
.
@@ -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, "accountcontroller" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's follow Rails' naming conventions for good measure: "accounts_controller"
:)
Squash your commits down to 1 once the latest review has been addressed. Thanks for fixing this, digging it! 🤘 |
Replaces the rake_patterns instance variable with simple require, as `autorun` will run tests from all eagerly required test files. Fixes rails#27801
d936d9f
to
1c8a4cd
Compare
Thank you for the detailed review and comments @kaspth. I've fixed the style comments and squashed the commits. |
Awesome, thanks! |
Thanks @kaspth. Would you mind backporting it to 5-0-stable, since it's a regression vs 4.2? |
Collect all file patterns when running multiple rake test tasks
Apologies for not keeping you in the loop, I needed #27941 to be merged first. Backported to 5-0-stable at e79ffaf...88b335e |
No worries, thanks @kaspth. |
Sounds good 👍 |
Fixes #27801