1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00
teamcapybara--capybara/lib/capybara/util/timeout.rb

28 lines
543 B
Ruby
Raw Normal View History

2010-07-09 14:30:50 -04:00
module Capybara
class << self
##
# Provides timeout similar to standard library Timeout, but avoids threads
#
def timeout(seconds = 1, driver = nil, error_message = nil, &block)
2010-07-09 14:30:50 -04:00
start_time = Time.now
result = nil
until result
return result if result = yield
delay = seconds - (Time.now - start_time)
if delay <= 0
raise TimeoutError, error_message || "timed out"
2010-07-09 14:30:50 -04:00
end
driver && driver.wait_until(delay)
sleep(0.05)
end
end
end
end