Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add callback for intermittent tests #122

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/rspec/retry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ def self.setup
# Callback between retries
config.add_setting :retry_callback, :default => nil

# Callback for intermittent tests
config.add_setting :intermittent_callback, :default => nil

config.around(:each) do |ex|
ex.run_with_retry
end
Expand Down Expand Up @@ -123,9 +126,16 @@ def run
example.clear_exception
ex.run

self.attempts += 1
if example.exception.nil?
# If it's an intermittent test, call the callback
if attempts > 0 && RSpec.configuration.intermittent_callback
example.example_group_instance.instance_exec(example, &RSpec.configuration.intermittent_callback)
end

break if example.exception.nil?
break
end

self.attempts += 1

example.metadata[:retry_exceptions] << example.exception

Expand Down