Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
module RSpec
module Core
class Example
def run_with_retry(example_group_instance, reporter)
@retrying_count = 0
succeeded = run_without_retry(example_group_instance, reporter)
unless succeeded
return finish_without_retry(reporter) unless retry_needed?
$stderr.puts "[RETRY] #{self.location}: #{self.full_description}"
@retrying_count += 1
# Initialize itself (originally this has done in ExampleGroup#run_example)
@exception = nil
example_group_instance = example_group_instance.class.new.tap do |group|
group.class.set_ivars(group, group.class.before_all_ivars)
end
succeeded = run_without_retry(example_group_instance, reporter)
end
succeeded
end
alias run_without_retry run
alias run run_with_retry
private
def finish_with_retry(reporter)
if (@retrying_count || 0) < 1 && @exception
false
else
finish_without_retry(reporter)
end
end
alias finish_without_retry finish
alias finish finish_with_retry
def retry_needed?
# Fix here for your usecase.
# For us, we calls internal-app's API for determining to retry or not.
true
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment