Repository navigation
Don't eagerly require Rails' minitest plugin. - #29572
Conversation
There was a problem hiding this comment.
Renaming this file to be "minitest/*_plugin.rb" makes minitest autoload us.
There was a problem hiding this comment.
I should try removing this altogether now.
There was a problem hiding this comment.
In a later PR, I'd like to follow minitest-focus'es lead to make the filters regexps. I.e. move the filter definitions into plugin_rails_init by resolving line numbers to a specific method name.
Needs to handle a file creating multiple Runnables though and running with multiple line numbers (test/models/post_test.rb:4:8). Tried to do it for this, but faced way too much head-desking.
There was a problem hiding this comment.
I really despise this code. At first I had defined these as Thor options in the test command, but I couldn't figure out a way to make Thor remove the options from ARGV after parsing them (that also broke the test/generators/plugin_test_runner_test.rb tests).
|
I've been running a locally |
There was a problem hiding this comment.
The test runner of the rails plugin does not use TestCommand.
Therefore, TestCommand#help will not be called and rails' help will not be displayed.
$ rails plugin new yaffle
$ cd yaffle
$ <edit some files>
$ ./bin/test --help
minitest options:
-h, --help Display this help.
-s, --seed SEED Sets random seed. Also via env. Eg: SEED=n rake
-v, --verbose Verbose. Show progress processing files.
-n, --name PATTERN Filter run on /regexp/ or string.
-e, --exclude PATTERN Exclude /regexp/ or string from run.
Known extensions: rails, pride
-b, --backtrace Show the complete backtrace
-d, --defer-output Output test failures and errors after the test run
-f, --fail-fast Abort test run on first failure or error
-c, --[no-]color Enable color in the output
-p, --pride Pride. Show your testing pride!
I think that it is better to keep help displayed on plugin_rails_options, what about it?
There was a problem hiding this comment.
I noticed that but opted to separate them out. If we're running with ruby -Itest test/models --help we aren't running directly through the Rails test command, so I liked that we're slightly indicating that in the different help output. For instance when tests are run with ruby we can't support the -e option (iirc the app is booted once rails/test_help is run, so invoking the test command from there won't work either).
There was a problem hiding this comment.
Oh, I see. Thanks for you explanation!
There was a problem hiding this comment.
Would Display Ruby warning be more clear option name than Enable?
|
I cloned the branch and tried it on a dummy app with minitest-focus and minitest/pride enabled. Works just fine 👌 Great work! |
|
@kirs sweet! I'll try to prepare a version of this that works on 5-0-stable, so you can try it out there 😊 |
|
@kirs got a branch for 5-0-stable set up: 5-0-stable...test-runner-no-eager-require-5-0-stable The branches are slightly out of sync as I haven't pushed the master test fixes there (I wanna see what the failures will be on 5-0-stable first). |
There was a problem hiding this comment.
Should we need Rails::TestUnit::Runner.parse_options(ARGV) here?
There was a problem hiding this comment.
Can we use Rails::TestUnit::Runner.run?
By making the Rails minitest behave like a standard minitest plugin we're much more likely to not break when people use other minitest plugins. Like minitest-focus and pride. To do this, we need to behave like minitest: require files up front and then perform the plugin behavior via the at_exit hook. This also saves us a fair bit of wrangling with test file loading. Finally, since the environment and warnings options have to be applied as early as possible, and since minitest loads plugins at_exit, they have to be moved to the test command. * Don't expect the root method. It's likely this worked because we eagerly loaded the Rails minitest plugin and that somehow defined a root method on `Rails`. * Assign a backtrace to failed exceptions. Otherwise Minitest pukes when attempting to filter the backtrace (which Rails' backtrace cleaner then removes). Means the exception message test has to be revised too. This is likely caused by the rails minitest plugin now being loaded for these tests and assigning a default backtrace cleaner.
86da9ab to
0d72489
Compare
|
Failed on the new secrets test again: https://travis-ci.org/rails/rails/jobs/252119183#L1973 — I'm going to merge this since it's unrelated. |
Don't eagerly require Rails' minitest plugin.
|
5-1-stable: de0d960...5b07011 Looked at the wrong build when I pushed to 5-0-stable then tried to fix it live. I then reverted it on 5-0-stable as I couldn't reproduce the test failures locally, then I figured it the issue was with rerun snippets on Travis since the plugin is now loaded there as well. 631c596 Think these should do it! Phew 😅 |
|
Since this PR was merged, any failing test in ActiveRecord/ActiveJob/ActiveSupport suite would fail in the reporter step: I fixed the issue in #29818 |
Since rails#29572, minitest options are available but are no longer showed in help. This fixed to show minitest option in help as with Rails 5.1.2. **before** ``` ./bin/rails t --help You can run a single test by appending a line number to a filename: bin/rails test test/models/user_test.rb:27 You can run multiple files and directories at the same time: bin/rails test test/controllers test/integration/login_test.rb By default test failures and errors are reported inline during a run. Rails options: -w, --warnings Run with Ruby warnings enabled -e, --environment Run tests in the ENV environment -b, --backtrace Show the complete backtrace -d, --defer-output Output test failures and errors after the test run -f, --fail-fast Abort test run on first failure or error -c, --[no-]color Enable color in the output ``` **after** ``` ./bin/rails t --help You can run a single test by appending a line number to a filename: bin/rails test test/models/user_test.rb:27 You can run multiple files and directories at the same time: bin/rails test test/controllers test/integration/login_test.rb By default test failures and errors are reported inline during a run. minitest options: -h, --help Display this help. -s, --seed SEED Sets random seed. Also via env. Eg: SEED=n rake -v, --verbose Verbose. Show progress processing files. -n, --name PATTERN Filter run on /regexp/ or string. --exclude PATTERN Exclude /regexp/ or string from run. Known extensions: rails, pride -w, --warnings Run with Ruby warnings enabled -e, --environment Run tests in the ENV environment -b, --backtrace Show the complete backtrace -d, --defer-output Output test failures and errors after the test run -f, --fail-fast Abort test run on first failure or error -c, --[no-]color Enable color in the output -p, --pride Pride. Show your testing pride! ```
Since rails#29572, test runner will be loaded as minitest's plugin. Therefore, if specify a value in `Minitest.extensions` before the Minitest initialization process, the extension will not load and the test runner will not work. https://github.com/seattlerb/minitest/blob/44eee51ed9716c789c7cea8a90c131cf736b8915/lib/minitest.rb#L86 Also, load processing of adapter is done before minitest option processing, so set the adapter in the file so that the `-a` option works.
Since #29572, test runner will be loaded as minitest's plugin. Therefore, if specify a value in `Minitest.extensions` before the Minitest initialization process, the extension will not load and the test runner will not work. https://github.com/seattlerb/minitest/blob/44eee51ed9716c789c7cea8a90c131cf736b8915/lib/minitest.rb#L86 Also, load processing of adapter is done before minitest option processing, so set the adapter in the file so that the `-a` option works.
- Add a description of major features in Rails 5.2.
- Add a reference to Pull Request/Commit to every entry in CHANGELOGs,
note that some of them combined.
- Add section "Ruby on Rails Guides" with notable changes.
- Note that
- Skipped this since encrypted secrets are already on the way out.
```
* Add `rails secrets:show` command.
([Pull Request](rails#29695))
```
- Skipped this since it was backported all the way to 5-0-stable.
```
* Make Rails' test runner work better with minitest plugins.
([Pull Request](rails#29572))
```
Thanks to everyone who has been working on Rails 5.2! <3
The command bin/test stop running single tests once Devise started to support Rails 5.2. The problem is because we used `rails/test_unit/minitest_plugin` and this file was moved to another place. See: rails/rails#29572 I'm not sure if we should require the `minitest-plugin` directly from Rails like we were doing, I tried it and it didn't work. So I'm changing this `bin/test` completely following based on how Rails does that [here](https://github.com/rails/rails/blob/master/tools/test.rb)
The command bin/test stop running single tests once Devise started to support Rails 5.2. The problem is because we used `rails/test_unit/minitest_plugin` and this file was moved to another place. See: rails/rails#29572 I'm not sure if we should require the `minitest-plugin` directly from Rails like we were doing, I tried it and it didn't work. So I'm changing this `bin/test` completely following based on how Rails does that [here](https://github.com/rails/rails/blob/master/tools/test.rb)
The command bin/test stop running single tests once Devise started to support Rails 5.2. The problem is because we used `rails/test_unit/minitest_plugin` and this file was moved to another place. See: rails/rails#29572 I'm not sure if we should require the `minitest-plugin` directly from Rails like we were doing, I tried it and it didn't work. So I'm changing this `bin/test` completely following based on how Rails does that [here](https://github.com/rails/rails/blob/master/tools/test.rb)
The command bin/test stop running single tests once Devise started to support Rails 5.2. The problem is because we used `rails/test_unit/minitest_plugin` and this file was moved to another place. See: rails/rails#29572 I'm not sure if we should require the `minitest-plugin` directly from Rails like we were doing, I tried it and it didn't work. So I'm changing this `bin/test` completely following based on how Rails does that [here](https://github.com/rails/rails/blob/master/tools/test.rb)
The command bin/test stop running single tests once Devise started to support Rails 5.2. The problem is because we used `rails/test_unit/minitest_plugin` and this file was moved to another place. See: rails/rails#29572 I'm not sure if we should require the `minitest-plugin` directly from Rails like we were doing, I tried it and it didn't work. So I'm changing this `bin/test` completely based on how Rails does that [here](https://github.com/rails/rails/blob/master/tools/test.rb)
Fixes #29469. Fixes #25046.
By making the Rails minitest behave like a standard minitest plugin
we're much more likely to not break when people use other minitest
plugins. Like minitest-focus and pride.
To do this, we need to behave like minitest: require files up front
and then perform the plugin behavior via the at_exit hook.
This also saves us a fair bit of wrangling with test file loading.
Finally, since the environment and warnings options have to be applied
as early as possible, and since minitest loads plugins at_exit, they
have to be moved to the test command.
Ideally, I'd like to backport this to both 5-1-stable and 5-0-stable. It's an extensive fix for sure though.