Module: Waiter

Defined in:
lib/waiter.rb,
lib/version.rb,
lib/timeout_error.rb

Defined Under Namespace

Classes: ChainableWait, TimeoutError, WaitExpectationTarget

Constant Summary collapse

VERSION =
'1.0.4'

Instance Method Summary collapse

Instance Method Details

#wait(opts = {}, &block) ⇒ Object

Wrapper for RSpec expectations that allows waiting/polling.

The default timeout is 15 seconds, polling every 1 second.

To adjust the timeout/polling, simple chain methods are supported.

The up_to method accepts an Integer and adjusts the timeout. Use the every method with an Integer to adjust the polling time.

You do not have to use both methods, you can adjust one or the other. They can also be used in any order.

You can also pass a block to be evaluated, using until, until it is true.

Examples:


wait.for('foo').to eq 'foo' # Will pass.
wait.for('foo').to eq 'bar' # Will throw exception.
wait.for('foo').to_not eq 'bar' # Will pass.
wait.for('foo').to_not eq 'foo' # Will fail.

# Wait for 30 seconds, polling every 2 second.
wait.every(2).up_to(30).for('foo').to eq 'foo'

# Wait for 30 seconds, using the default 1 second poll.
wait.for('foo').up_to(30).to eq 'foo'

# Wait for the default 15 seconds, polling every 5 seconds.
wait.for('foo').every(5).to eq 'foo'

wait.until { true == true }

wait.every(5).up_to(30).until {
  true == true
}

Author:



49
50
51
# File 'lib/waiter.rb', line 49

def wait(opts = {}, &block)
  ChainableWait.new(opts)
end