When running a project’s RSpec test suite locally, have RSpec automatically stop on the first test failure with the --fail-fast command-line option1.
bundle exec rspec --fail-fast
...............................F
Failures:
1) Example divides the dividend by the divisor
Failure/Error: expect(dividend / divisor).to eq(21)
TypeError:
nil can't be coerced into Integer
# ./example_spec.rb:12:in `/'
# ./example_spec.rb:12:in `block (3 levels) in <top (required)>'
Finished in 0.00507 seconds (files took 0.09149 seconds to load)
32 examples, 1 failure
Failed examples:
rspec './example_spec.rb[1:32]' # Example divides the dividend by the divisor
Aborting on the first failure saves time and reduces the amount of output printed to the screen when there are multiple failures in the run.
For projects with slower test suites, turn use the --fail-fast option any time the suite runs locally, and save the full runs for CI.
Although the project-wide
↩︎fail_fastconfiguration option2 existed in earlier versions, the--fail-fastcommand line option was released as part of RSpec 2.1.To turn on
--fail-fastfor every tun, turn on the project-wide configuration option:↩︎RSpec.configure { |config| config.fail_fast = true }