In RSpec 3.3, the --only-failures
option was added. This means you can have RSpec dump the failures to a file, and rerun them.
Add this line to your application's Gemfile:
gem 'rspec-redo'
And then execute:
$ bundle
Or install it yourself as:
$ gem install rspec-redo
First, you'll need to tell RSpec where to persist a list of failed examples. To do this, you'll have to add a line to your spec_helper.rb
. You'll want to add this file to your .gitignore
.
RSpec.configure do |c|
c.example_status_persistence_file_path = 'tmp/rspec-failures.txt'
end
Okay, now you're ready. Simply execute:
$ rspec-redo
You can also pass options you'd typically pass to RSpec. For example:
$ rspec-redo spec/models/person_spec.rb --format doc
By default, the program will retry failed specs only once. You can retry multiple times like so:
$ rspec-redo --retry-count 5
RSpec Redo includes a build in Rake task generator. To create a new Rake task, add the following to your Rakefile:
require 'rspec-redo/rake_task'
RSpecRedo::RakeTask.new 'spec:redo'
Cool, now you can run:
$ rake spec:redo
You can customize the command by providing a block:
RSpecRedo::RakeTask.new 'spec:redo:models' do |t|
t.pattern = 'spec/models/*_spec.rb'
end
Read RSpec's documentation for available options.
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rspec_redo.
Inspired by rspec-rerun
.
The gem is available as open source under the terms of the MIT License.