class Capybara::UI::Checkpoint

A point in time where some condition, or some set of conditions, should be verified.

@see rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Base#synchronize-instance_method,

which inspired this class.

Attributes

rescuable_errors[RW]
timer[R]

Public Class Methods

new(wait_time = Capybara.default_max_wait_time) click to toggle source

Initializes a new Checkpoint.

@param wait_time how long this checkpoint will wait for its conditions to

be met, in seconds.
# File lib/capybara/ui/checkpoint.rb, line 70
def initialize(wait_time = Capybara.default_max_wait_time)
  @timer = Timer.new(wait_time)
end
wait_for(wait_time = Capybara.default_max_wait_time, &block) click to toggle source

Shortcut for instance level wait_for.

# File lib/capybara/ui/checkpoint.rb, line 62
def self.wait_for(wait_time = Capybara.default_max_wait_time, &block)
  new(wait_time).call(&block)
end

Public Instance Methods

call() { |or raise ConditionNotMet| ... } click to toggle source

Executes block repeatedly until it returns a “truthy” value or wait_time expires.

Swallows any StandardError or StandardError descendent until wait_time expires. If an exception is raised and the time has expired, that exception will be raised again.

If the block does not return a “truthy” value until wait_time expires, raises a Capybara::UI::Checkpoint::ConditionNotMet error.

Returns whatever value is returned by the block.

# File lib/capybara/ui/checkpoint.rb, line 85
def call(&condition)
  timer.start

  begin
    yield or raise ConditionNotMet
  rescue *rescuable_errors
    raise if timer.expired?

    timer.tick

    retry
  end
end

Protected Instance Methods

rescuable_errors() click to toggle source
# File lib/capybara/ui/checkpoint.rb, line 101
def rescuable_errors
  self.class.rescuable_errors
end