-
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 6135ef5
Showing
2 changed files
with
41 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,31 @@ | ||
# Include in `test_helper.rb` like this: | ||
# | ||
# class ActiveSupport::TestCase | ||
# prepend RetryOnFlakyTests[FlakyError, AnotherFlakyError, max_tries: 3] | ||
# end | ||
|
||
class RetryOnFlakyTests < Module | ||
def self.[](*error_classes, max_tries: 3) | ||
Module.new do | ||
define_method :run do | ||
tries ||= 1 | ||
super() | ||
rescue *error_classes => err | ||
raise unless (tries +=1) <= max_tries | ||
|
||
puts "Got #{err.class.name} Error, trying again #{tries}. time" | ||
retry | ||
end | ||
|
||
define_method :capture_exceptions do |&block| | ||
block.call | ||
rescue => err | ||
if error_classes.include?(err.class) | ||
raise | ||
else | ||
super(&->{ raise err }) | ||
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