Class: On::TestHelper::Recorder
- Inherits:
-
Object
- Object
- On::TestHelper::Recorder
- Defined in:
- lib/on/test_helper.rb
Overview
Record callbacks.
Defined Under Namespace
Classes: Callback
Instance Method Summary collapse
- #block_called? ⇒ Boolean
- #callback_recorded(name, args = []) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize ⇒ Recorder
constructor
A new instance of Recorder.
-
#last_record ⇒ Object
Pops the last recorded recorded.
-
#record_all ⇒ Object
Records block and all defined callbacks.
-
#record_block ⇒ Object
Records a block.
-
#record_callback(on, *names) ⇒ Object
Records a single callback.
-
#to_proc ⇒ Object
Short-hand for &
recorder.record_all
.
Constructor Details
#initialize ⇒ Recorder
Returns a new instance of Recorder.
78 79 80 81 |
# File 'lib/on/test_helper.rb', line 78 def initialize @block = false @callbacks = [] end |
Instance Method Details
#block_called? ⇒ Boolean
83 84 85 |
# File 'lib/on/test_helper.rb', line 83 def block_called? @block end |
#callback_recorded(name, args = []) ⇒ Object
128 129 130 131 |
# File 'lib/on/test_helper.rb', line 128 def callback_recorded(name, args=[]) callback = Callback === name ? name : Callback.new(name, args) @callbacks << callback end |
#empty? ⇒ Boolean
87 88 89 |
# File 'lib/on/test_helper.rb', line 87 def empty? @callbacks.empty? end |
#last_record ⇒ Object
Pops the last recorded recorded.
92 93 94 |
# File 'lib/on/test_helper.rb', line 92 def last_record @callbacks.pop end |
#record_all ⇒ Object
Records block and all defined callbacks.
97 98 99 100 101 102 |
# File 'lib/on/test_helper.rb', line 97 def record_all proc do |on| record_block record_callback(on, *on.callbacks) end end |
#record_block ⇒ Object
Records a block.
recorder = Recorder.new
On.new(:success) do |callback|
recorder.record_block
callback.on :success do
# assert...
end
end
assert recorder.block_called?
115 116 117 |
# File 'lib/on/test_helper.rb', line 115 def record_block @block = true end |
#record_callback(on, *names) ⇒ Object
Records a single callback.
120 121 122 123 124 125 126 |
# File 'lib/on/test_helper.rb', line 120 def record_callback(on, *names) names.each do |name| on.on name do |*args| callback_recorded(name, args) end end end |
#to_proc ⇒ Object
Short-hand for &recorder.record_all
.
134 135 136 |
# File 'lib/on/test_helper.rb', line 134 def to_proc record_all end |