第一次失败时最小的出口?

时间:2015-05-07 05:26:10

标签: ruby-on-rails ruby minitest

我使用Minitest和Rails。

如果我正在运行一系列测试,如何让它在第一次失败时退出?我希望在我编写测试时发生这种情况,因为以后的测试在失败之后运行会浪费时间。

2 个答案:

答案 0 :(得分:0)

你可以使用minitest-fail-fast宝石。报告失败后,您还可以将Minitest记者引擎修改为exit

答案 1 :(得分:0)

我在搜索解决方案时发现了这个答案,但至少在Rails 5.1中你有一个选择:

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

所以你只需要运行rails test -f