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

Conversation

domcleal
Copy link
Contributor

Fixes #27801

@rails-bot
Copy link

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.

@arthurnn
Copy link
Member

Thanks @domcleal for the bug fix.. Do you mind adding a changelog entry for this fix, and rebasing your PR against latest master?

@arthurnn arthurnn assigned arthurnn and unassigned chancancode Jan 31, 2017
@@ -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)
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 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.

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 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.

@domcleal
Copy link
Contributor Author

domcleal commented Feb 1, 2017

@arthurnn thanks, I've rebased the PR, added two commits in response to @kaspth's comment (improve test coverage, refactor away this instance variable) and added the CHANGELOG entry.

Edit: I think the actioncable test failure is unrelated, possibly a transient or intermittent issue.

@arthurnn
Copy link
Member

arthurnn commented Feb 1, 2017

@domcleal
Copy link
Contributor Author

domcleal commented Feb 2, 2017

@arthurnn thanks, you're right that it was called twice. options[:pattern] would be empty though for rake runs, but I've updated the last commit to skip the step when called via rake.


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.

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"
Copy link
Contributor

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.
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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)

@@ -1,3 +1,7 @@
* Fix running multiple test\* tasks specified in a single `rake` command
Copy link
Contributor

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'` }
Copy link
Contributor

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?

Copy link
Contributor Author

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"
Copy link
Contributor

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" :)

@kaspth
Copy link
Contributor

kaspth commented Feb 2, 2017

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
@domcleal
Copy link
Contributor Author

domcleal commented Feb 4, 2017

Thank you for the detailed review and comments @kaspth. I've fixed the style comments and squashed the commits.

@kaspth kaspth merged commit 2cb6c27 into rails:master Feb 5, 2017
@kaspth
Copy link
Contributor

kaspth commented Feb 5, 2017

Awesome, thanks!

@domcleal
Copy link
Contributor Author

domcleal commented Feb 8, 2017

Thanks @kaspth. Would you mind backporting it to 5-0-stable, since it's a regression vs 4.2?

kaspth added a commit that referenced this pull request Feb 20, 2017
Collect all file patterns when running multiple rake test tasks
@kaspth
Copy link
Contributor

kaspth commented Feb 20, 2017

Apologies for not keeping you in the loop, I needed #27941 to be merged first.

Backported to 5-0-stable at e79ffaf...88b335e

@domcleal
Copy link
Contributor Author

No worries, thanks @kaspth.

@kaspth
Copy link
Contributor

kaspth commented Feb 21, 2017

Sounds good 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants