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 Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(wait_time = Capybara.default_wait_time) ⇒ Checkpoint

Initializes a new Checkpoint.

Parameters:

  • wait_time (defaults to: Capybara.default_wait_time)

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



63
64
65
# File 'lib/dill/checkpoint.rb', line 63

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

Class Method Details

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

Shortcut for instance level wait_for.



55
56
57
# File 'lib/dill/checkpoint.rb', line 55

def self.wait_for(wait_time = Capybara.default_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.



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/dill/checkpoint.rb', line 78

def call(&condition)
  timer.start

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

    timer.tick

    retry
  end
end