Created
October 7, 2016 14:49
-
-
Save matthieuprat/092022af6df09d0f68cada10a5687f09 to your computer and use it in GitHub Desktop.
Capybara eventually helper
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
def eventually(timeout: Capybara.default_max_wait_time, interval: 0.2) | |
Timeout.timeout(timeout) do | |
begin | |
next yield | |
rescue Minitest::Assertion, Capybara::ExpectationNotMet | |
sleep interval | |
retry | |
end | |
end | |
rescue Timeout::Error | |
yield | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you're using RSpec you'll want to add
RSpec::Expectations::ExpectationNotMetError
to the exception list.Also, in case it helps others, I've placed this method inside of a file located at
spec/support/helpers/capybara.rb
and wrapped it inmodule Helpers
:If your
rails_helper.rb
orspec_helper.rb
is already set to autoload everything inspec/support
theneventually
is ready to be used in your specs.