mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
28 lines
492 B
Ruby
28 lines
492 B
Ruby
|
module Capybara
|
||
|
class << self
|
||
|
|
||
|
##
|
||
|
# Provides timeout similar to standard library Timeout, but avoids threads
|
||
|
#
|
||
|
def timeout(seconds = 1, driver = nil, &block)
|
||
|
start_time = Time.now
|
||
|
|
||
|
result = nil
|
||
|
|
||
|
until result
|
||
|
return result if result = yield
|
||
|
|
||
|
delay = seconds - (Time.now - start_time)
|
||
|
if delay <= 0
|
||
|
raise TimeoutError
|
||
|
end
|
||
|
|
||
|
driver && driver.wait_until(delay)
|
||
|
|
||
|
sleep(0.05)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
end
|
||
|
end
|