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.
Instance Method Summary collapse
-
#initialize(wait_time = Capybara.default_wait_time) ⇒ Checkpoint
constructor
Initializes a new Checkpoint.
-
#wait_until(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.
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
.driver ⇒ Object
Returns the Capybara driver in use.
15 16 17 |
# File 'lib/dill/checkpoint.rb', line 15 def self.driver Capybara.current_session.driver end |
Instance Method Details
#wait_until(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.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/dill/checkpoint.rb', line 51 def wait_until(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 |