Class: Dill::Checkpoint

Inherits:
Object
  • Object
show all
Defined in:
lib/dill/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.



74
75
76
# File 'lib/dill/checkpoint.rb', line 74

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.



11
12
13
# File 'lib/dill/checkpoint.rb', line 11

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.



66
67
68
# File 'lib/dill/checkpoint.rb', line 66

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 Dill::Checkpoint::ConditionNotMet error.

Returns whatever value is returned by the block.



89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/dill/checkpoint.rb', line 89

def call(&condition)
  timer.start

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

    timer.tick

    retry
  end
end