Skip to content

Instantly share code, notes, and snippets.

@jvillarejo
Created January 7, 2022 22:38
Show Gist options
  • Save jvillarejo/54845731e8b8578c19fa5a5b7a9d1269 to your computer and use it in GitHub Desktop.
Save jvillarejo/54845731e8b8578c19fa5a5b7a9d1269 to your computer and use it in GitHub Desktop.
A timeout for failing specs when using turbo frames and hotwire
# 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