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, &block) ⇒ Object



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

def timeout(seconds = 1, &block)
  start_time = Time.now

  result = nil

  until result
    return result if result = yield

    if (Time.now - start_time) > seconds
       raise TimeoutError
    end
  end
end