Class: Dill::Checkpoint
- Inherits:
-
Object
- Object
- Dill::Checkpoint
- Defined in:
- lib/dill/checkpoint.rb
Overview
A point in time where some condition, or some set of conditions, should be verified.
Direct Known Subclasses
Defined Under Namespace
Classes: ConditionNotMet, TimeFrozen
Instance Attribute Summary collapse
-
#wait_time ⇒ Object
readonly
The configured wait time, in seconds.
Class Method Summary collapse
-
.wait_for(wait_time = Capybara.default_wait_time, &block) ⇒ Object
Shortcut for instance level wait_for.
Instance Method Summary collapse
-
#initialize(wait_time = Capybara.default_wait_time) ⇒ Checkpoint
constructor
Initializes a new Checkpoint.
- #rescuable_errors ⇒ Object
-
#wait_for(&condition) ⇒ Object
Executes
blockrepeatedly until it returns a “truthy” value orwait_timeexpires.
Constructor Details
#initialize(wait_time = Capybara.default_wait_time) ⇒ Checkpoint
Initializes a new Checkpoint.
23 24 25 |
# File 'lib/dill/checkpoint.rb', line 23 def initialize(wait_time = Capybara.default_wait_time) @wait_time = wait_time end |
Instance Attribute Details
#wait_time ⇒ Object (readonly)
Returns the configured wait time, in seconds.
12 13 14 |
# File 'lib/dill/checkpoint.rb', line 12 def wait_time @wait_time end |
Class Method Details
.wait_for(wait_time = Capybara.default_wait_time, &block) ⇒ Object
Shortcut for instance level wait_for.
15 16 17 |
# File 'lib/dill/checkpoint.rb', line 15 def self.wait_for(wait_time = Capybara.default_wait_time, &block) new(wait_time).wait_for(&block) end |
Instance Method Details
#rescuable_errors ⇒ Object
54 55 56 |
# File 'lib/dill/checkpoint.rb', line 54 def rescuable_errors StandardError end |
#wait_for(&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.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/dill/checkpoint.rb', line 38 def wait_for(&condition) start begin yield or raise ConditionNotMet rescue *rescuable_errors raise if expired? wait raise TimeFrozen, 'time appears to be frozen' if time_frozen? retry end end |