Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save amree/e9309d5b4146f17f701a62116a36c049 to your computer and use it in GitHub Desktop.
Save amree/e9309d5b4146f17f701a62116a36c049 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