diff --git a/lib/rspec/retry.rb b/lib/rspec/retry.rb index 19ef16e..580673c 100644 --- a/lib/rspec/retry.rb +++ b/lib/rspec/retry.rb @@ -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 @@ -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