Class: Capybara::UI::Checkpoint

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

Overview

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

Defined Under Namespace

Classes: ConditionNotMet, Timer

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(wait_time = Capybara.default_max_wait_time) ⇒ Checkpoint

Initializes a new Checkpoint.

Parameters:

  • wait_time (defaults to: Capybara.default_max_wait_time)

    how long this checkpoint will wait for its conditions to be met, in seconds.


70
71
72
# File 'lib/capybara/ui/checkpoint.rb', line 70

def initialize(wait_time = Capybara.default_max_wait_time)
  @timer = Timer.new(wait_time)
end

Class Attribute Details

.rescuable_errorsObject

Returns the value of attribute rescuable_errors


12
13
14
# File 'lib/capybara/ui/checkpoint.rb', line 12

def rescuable_errors
  @rescuable_errors
end

Class Method Details

.wait_for(wait_time = Capybara.default_max_wait_time, &block) ⇒ Object

Shortcut for instance level wait_for.


62
63
64
# 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

Instance Method Details

#call(&condition) ⇒ Object

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.


85
86
87
88
89
90
91
92
93
94
95
96
97
# 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