Class: Capybara::WaitUntil

Inherits:
Object
  • Object
show all
Defined in:
lib/capybara/wait_until.rb

Overview

Provides timeout similar to standard library Timeout, but avoids threads

Class Method Summary collapse

Class Method Details

.timeout(seconds = 1, driver = nil, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/capybara/wait_until.rb', line 7

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