Created
May 14, 2014 15:06
-
-
Save arathunku/49bd7db2e458bd8de6fb to your computer and use it in GitHub Desktop.
Method which will try to validate a block for a given number of seconds. I'm using it when javascript is responsible for loading another page.
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 timeout_expect(seconds=1, &block) | |
end_at = Time.now + seconds | |
error = nil | |
while Time.now < end_at | |
begin | |
error = nil | |
block.call | |
end_at = Time.now | |
rescue RSpec::Expectations::ExpectationNotMetError => e | |
error = e | |
end | |
end | |
raise(RSpec::Expectations::ExpectationNotMetError.new(error.message)) if error | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment