Created
January 7, 2022 22:38
-
-
Save jvillarejo/54845731e8b8578c19fa5a5b7a9d1269 to your computer and use it in GitHub Desktop.
A timeout for failing specs when using turbo frames and hotwire
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
# This is how we use it | |
retry_until_timeout do | |
expect(page).to have_button('Add comment') | |
expect(page).to have_text('Cancell') | |
end | |
def retry_until_timeout(seconds = 10, message: 'Failed with timeout') | |
Timeout.timeout(seconds) do | |
loop do | |
yield | |
break | |
rescue Capybara::ElementNotFound | |
sleep_on_failure | |
rescue RSpec::Expectations::ExpectationNotMetError | |
sleep_on_failure | |
rescue Selenium::WebDriver::Error::StaleElementReferenceError | |
sleep_on_failure | |
end | |
end | |
rescue Timeout::Error | |
raise(message) | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment