-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Retry capybara tests on specific errors
- Loading branch information
1 parent
8a7e69b
commit 823714d
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Include in `test_helper.rb` like this: | ||
# | ||
# class ActiveSupport::TestCase | ||
# prepend RetryOnFlakyTests[FlakyError, AnotherFlakyError, max_tries: 3] | ||
# end | ||
|
||
module RetryOnFlakyTests | ||
def self.[](*error_classes, max_tries: 3) | ||
Module.new do | ||
define_method :max_tries do | ||
max_tries | ||
end | ||
|
||
define_method :error_classes do | ||
error_classes | ||
end | ||
|
||
def run_one_method(klass, method_name, reporter) | ||
report_result = nil | ||
max_tries.times do | ||
result = Minitest.run_one_method(klass, method_name) | ||
report_result ||= result | ||
(report_result = result) and break if result.passed? | ||
|
||
break unless retryable_failure?(result) | ||
end | ||
reporter.record(report_result) | ||
end | ||
|
||
def retryable_failure?(result) | ||
result.failures.map do |failure| | ||
failure.error.to_s | ||
end.any? do |failure_msg| | ||
error_classes.first {|error_class| failure_msg =~ error_class.name } | ||
end | ||
end | ||
end | ||
end | ||
end |
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