Module: Testable::Ready
- Includes:
- Situation
- Defined in:
- lib/testable/ready.rb
Defined Under Namespace
Modules: ReadyAttributes
Instance Attribute Summary collapse
-
#ready ⇒ Object
If a ready validation fails, the message reported by that failure will be captured in the ‘ready_error` accessor.
-
#ready_error ⇒ Object
If a ready validation fails, the message reported by that failure will be captured in the ‘ready_error` accessor.
Class Method Summary collapse
Instance Method Summary collapse
- #check_if_ready ⇒ Object
-
#ready? ⇒ Boolean
The ‘ready?` method is used to check if the page has been loaded successfully, which means that none of the ready validations have indicated failure.
-
#when_ready(simple_check = false, &_block) ⇒ Object
The ‘when_ready` method is called on an instance of an interface.
Instance Attribute Details
#ready ⇒ Object
If a ready validation fails, the message reported by that failure will be captured in the ‘ready_error` accessor.
45 46 47 |
# File 'lib/testable/ready.rb', line 45 def ready @ready end |
#ready_error ⇒ Object
If a ready validation fails, the message reported by that failure will be captured in the ‘ready_error` accessor.
45 46 47 |
# File 'lib/testable/ready.rb', line 45 def ready_error @ready_error end |
Class Method Details
.included(caller) ⇒ Object
39 40 41 |
# File 'lib/testable/ready.rb', line 39 def self.included(caller) caller.extend(ReadyAttributes) end |
Instance Method Details
#check_if_ready ⇒ Object
70 71 72 |
# File 'lib/testable/ready.rb', line 70 def check_if_ready when_ready(true) end |
#ready? ⇒ Boolean
The ‘ready?` method is used to check if the page has been loaded successfully, which means that none of the ready validations have indicated failure.
When ‘ready?` is called, the blocks that were stored in the above `ready_validations` array are instance evaluated against the current page instance.
81 82 83 84 85 86 |
# File 'lib/testable/ready.rb', line 81 def ready? self.ready_error = nil return true if ready ready_validations_pass? end |
#when_ready(simple_check = false, &_block) ⇒ Object
The ‘when_ready` method is called on an instance of an interface. This executes the provided validation block after the page has been loaded. The Ready object instance is yielded into the block.
Calls to the ‘ready?` method use a poor-man’s cache approach. The idea here being that when a page has confirmed that it is ready, meaning that no ready validations have failed, that information is stored so that any subsequent calls to ‘ready?` do not query the ready validations again.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/testable/ready.rb', line 55 def when_ready(simple_check = false, &_block) already_marked_ready = ready unless simple_check no_ready_check_possible unless block_given? end self.ready = ready? not_ready_validation(ready_error || 'NO REASON PROVIDED') unless ready yield self if block_given? ensure self.ready = already_marked_ready end |