Read more

RSpec: Efficiently rerunning failed examples during development

Martin Schaflitzl
October 09, 2023Software engineer at makandra GmbH

Note

Don't use reruns as a mean to work around flaky tests. You should always try to fix those instead of rerunning them regularly.

Setup

Configure RSpec to persist the result of your test runs to a file. This is necessary to be able to rerun examples.
Add this to your spec/spec_helper.rb :

  config.example_status_persistence_file_path = 'spec/examples.txt'

Rerun all failed examples using --only-failures

Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

bundle exec rspec --only-failures (or g rs --only-failures with geordi) will rerun all examples which failed in the last run.

Rerun a single failed example using --next-failure

bundle exec rspec --next-failure (or g rs --next-failure with geordi) will rerun only the first previously failed example.
Once you fixed this spec and it´s green again the next run of g rs --next-failure will run the next failed example. This will continue until all specs are green and can be very useful if you just implemented your new feature and now need to fix all the specs it broke.

Posted by Martin Schaflitzl to makandra dev (2023-10-09 10:04)