Created
June 4, 2013 08:45
-
-
Save sorah/5704562 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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