I recently discovered RSpec’s
--only-failures feature after seeing Increase Your Quality of Life: An RSpec Primer. I thought I was being clever to combine it with
--fail-fast – allowing me to methodically step through failures one at a time – only to discover that the RSpec team already has this covered with the
--next-failure option and that they’ve both been available since 2015.
To enable these features example status persistence must be configured in
spec/spec_helper.rb (remember to add the path to your
RSpec.configure do |config|
config.example_status_persistence_file_path = "spec/examples.txt"
rspec --only-failures and
rspec --next-failure will work as advertised. They can also be combined with an additional path filter and so will work with an entire directory, a single file, or any other RSpec path filter:
rspec --next-failure spec/system
rspec --next-failure spec/models/foo_spec.rb
rspec --next-failure spec/models/foo_spec.rb[1:2]
These RSpec nuggets have made me much more efficient when encountering a large swathes of failing tests, it makes me wonder of what else I’m unaware.
Originally published at www.benpickles.com