Commit Graph

16 Commits

Author SHA1 Message Date
Rafael Mendonça França
97cc321280
Point to the right executable when warning about --profile 2024-05-23 16:19:53 +00:00
Rafael Mendonça França
7ee34d9efb
Enable Rails minitest plugin in our rake tasks 2024-05-23 16:16:37 +00:00
Aaron Patterson
aa7957e124
Don't mess with Minitest unless RAILS_ENV is set
Minitest will automatically scan all installed gems and load plugins
from those gems.  We should detect whether or not we're being run within
the context of a Rails app and only change MT behavior in that case.

To determine if we're being run via `bin/rails` we'll just check if
RAILS_ENV is set.

Ref: https://github.com/minitest/minitest/issues/996
Ref: https://github.com/minitest/minitest/issues/725
2024-05-02 16:28:09 -07:00
Alex Ghiculescu
957a3e5e55 Add BACKTRACE env variable to turn off backtrace for normal running, not just tests 2024-01-04 07:25:12 +10:00
fatkodima
14d9b3e07e Add ability to show slow tests to the test runner 2023-08-30 00:08:56 +03:00
Jonathan Hefner
e37adfed4e Add Oxford commas [ci-skip] 2022-02-21 11:11:11 -06:00
Jonathan Hefner
33fdae0584 Fix backtraces for generated plugin tests
`Minitest.plugin_rails_init` sets `Minitest.backtrace_filter` to
`Rails.backtrace_cleaner` right before tests are run, overwriting the
value set in test_helper.rb.

`Rails.backtrace_cleaner` silences backtrace lines that do not start
with `Rails.root` followed by e.g. "lib/" or "test/".  Thus when
`Rails.root` is a subdirectory of the project directory -- for example,
when testing a plugin that has a dummy app -- all lines of the backtrace
are silenced.

This commit adds a fallback such that when all backtrace lines are
silenced, the original `Minitest.backtrace_filter` is used instead.

Additionally, this commit refactors and expands existing test coverage.
2020-10-07 15:40:56 -05:00
Rafael Mendonça França
0c8df42b50
Decorate Rails' backtrace cleaner before passing to minitest
The minitest database cleaner never returns empty traces so we need to
make sure ours also have the same behavior before passing to minitest.
2020-10-07 00:28:02 +00:00
alkesh26
79c3cef444 Railities typo fixes. 2019-02-01 16:42:40 +05:30
yuuji.yaginuma
686f4f3a94 Allow use of minitest-rails gem with Rails test runner
Add explicit global namespace to `Rails::TestUnit::Runner` to resolve a
namespace conflict between `minitest-rails` and Rails test runner.

Fixes #31324
2018-04-11 07:20:53 +09:00
Kasper Timm Hansen
6cc000c34c
Clean up reporter replacement a bit.
* Don't use :: for class methods, we don't do that elsewhere.

* Don't install a needless method on minitest. Prefer assigning the
  reporter anyway as that's what minitest does internally.

* Don't bother opting out when the reporter ain't a Minitest::CompositeReporter.
  It's hardcoded: 005a3ba42c/lib/minitest.rb (L125)
  And overrides have to create delegate reporters:
  1018b1b42f/lib/minitest/minitest_reporter_plugin.rb (L72)
2018-02-18 21:35:30 +01:00
Kevin Robatel
40a5ba30fb Add SuppressedSummaryReporter and TestUnitReporter only if necessary 2018-02-15 10:02:26 +01:00
Rafael França
5ccdd0bb6d Merge pull request #29891 from pat/frozen-string-literals-railties
Railties updates for frozen string literals.
2017-08-14 15:00:37 -04:00
Pat Allan
acea68de02 Adding frozen_string_literal pragma to Railties. 2017-08-14 19:08:09 +02:00
yuuji.yaginuma
47308ff32a Show minitest options in test runner help
Since #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!
```
2017-07-31 07:12:33 +09:00
Kasper Timm Hansen
0d72489b2a * Don't eagerly require Rails' minitest plugin.
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.
2017-07-10 20:40:16 +02:00