ill_always_be_a_warriors
ill_always_be_a_warriors

Reputation: 1566

Minitest Exit on first failure?

I'm using Minitest with Rails.

How do I get it to exit on the first failure if I'm running a bunch of tests? I want this to happen when I'm writing the tests because it's a waste of time for later tests to run after the failed one.

Upvotes: 3

Views: 1494

Answers (2)

Paulo Fidalgo
Paulo Fidalgo

Reputation: 22311

I've just found this answer while searching for the solution, but at least in Rails 5.1 you have one option:

rails test -h Usage: bin/rails test [options] [files or directories]

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

So you just just need to run rails test -f

Upvotes: 5

vgoff
vgoff

Reputation: 11323

You can probably use the minitest-fail-fast gem. You may also modify the Minitest reporters engine to exit after reporting a failure.

Upvotes: 0

Related Questions