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.
Defined Under Namespace
Classes: ConditionNotMet, TimeFrozen
Instance Attribute Summary collapse
-
#wait_time ⇒ Object
readonly
The configured wait time, in seconds.
Class Method Summary collapse
-
.driver ⇒ Object
The Capybara driver in use.
-
.wait_for(wait_time = Capybara.default_wait_time, raise_errors = true, &block) ⇒ Object
Executes
blockrepeatedly until it returns a “truthy” value ortimeoutexpires.
Instance Method Summary collapse
-
#initialize(wait_time = Capybara.default_wait_time) ⇒ Checkpoint
constructor
Initializes a new Checkpoint.
-
#wait_for(raise_errors = true) { ... } ⇒ Object
Waits until the condition encapsulated by the block is met.
Constructor Details
#initialize(wait_time = Capybara.default_wait_time) ⇒ Checkpoint
Initializes a new Checkpoint.
33 34 35 |
# File 'lib/dill/checkpoint.rb', line 33 def initialize(wait_time = .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
.driver ⇒ Object
Returns the Capybara driver in use.
15 16 17 |
# File 'lib/dill/checkpoint.rb', line 15 def self.driver .current_session.driver end |
.wait_for(wait_time = Capybara.default_wait_time, raise_errors = true, &block) ⇒ Object
Executes block repeatedly until it returns a “truthy” value or timeout expires.
TODO: Expand documentation.
23 24 25 26 27 |
# File 'lib/dill/checkpoint.rb', line 23 def self.wait_for(wait_time = .default_wait_time, raise_errors = true, &block) new(wait_time).wait_for(raise_errors, &block) end |
Instance Method Details
#wait_for(raise_errors = true) { ... } ⇒ Object
Waits until the condition encapsulated by the block is met.
Automatically rescues some exceptions (Capybara::ElementNotFound, and driver specific exceptions) until #wait_time is exceeded. At that point it raises whatever exception was raised in the condition block, or ConditionNotMet, if no exception was raised inside the block. However, if raise_errors is set to false, returns false instead of propagating any of the automatically rescued exceptions.
If an “unknown” exception is raised, it is propagated immediately, without waiting for #wait_time to expire.
If a driver that doesn’t support waiting is used, any exception raised is immediately propagated.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/dill/checkpoint.rb', line 61 def wait_for(raise_errors = true, &condition) start begin yield or raise ConditionNotMet rescue *rescuable_errors => e if immediate? raise e if raise_errors return false end if expired? raise e if raise_errors return false end wait raise TimeFrozen, 'time appears to be frozen' if time_frozen? retry end end |