Sha256: 9e0548838b2d446db9f0f2c1c1536529c6e90dcb31488564b6545d75d451d821

Contents?: true

Size: 487 Bytes

Versions: 4

Compression:

Stored size: 487 Bytes

Contents

require 'time'

class Wait
  ##
  # Execute a block until it returns true.
  # Optionally pass a timeout (by default 5 seconds).
  # 
  # wait = Wait.new
  # wait.until {
  #   (Random.rand(2) % 2)
  # }
  # 
  # wait.until(:timeout => 4) {
  #   (Random.rand(2) % 2)
  # }
  # 
  def Wait.until(options={:timeout => 5})
    timeout = Time.new + options[:timeout].to_f

    while (Time.new < timeout)
      return if (yield)
    end
    raise 'Timeout exceeded for wait until.'
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
frameworks-capybara-2.3.1 lib/frameworks/wait.rb
frameworks-capybara-2.3.0 lib/frameworks/wait.rb
frameworks-capybara-2.2.0 lib/frameworks/wait.rb
frameworks-capybara-2.1.0 lib/frameworks/wait.rb