Skip to content

Instantly share code, notes, and snippets.

@arathunku
Created May 14, 2014 15:06
Show Gist options
  • Save arathunku/49bd7db2e458bd8de6fb to your computer and use it in GitHub Desktop.
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.
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