In some projects we have issues with flaky tests. The best default is to fix them all. But in some cases it might be a pragmatic way to retry them for a limit number of times.
Notes:
- This setup was tested with a CI Pipeline that uses knapsack Show archive.org snapshot for parallel test balacing
- The official docs Show archive.org snapshot recommend to use rspec-retry Show archive.org snapshot , but we preferred the maintained fork rspec-rebound Show archive.org snapshot
Gemfile.lock
group :test do
gem 'rspec'
gem 'rspec-rebound'
end
spec/spec_helper.rb
require 'rspec/rebound'
RSpec.configure do |config|
# https://github.com/windmotion-io/rspec-rebound/blob/master/README.md
if ENV['CI']
config.default_retry_count = 3
config.verbose_retry = true
config.display_try_failure_messages = true
end
end
Example Screenshots
Here is an example output for a flaky test that passed the second time:
Here is an example output for a flaky test that retries to often (the example set default_retry_count to 1):
Posted by Emanuel to makandra dev (2026-02-13 16:18)