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
- #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.
59 60 61 62 |
# File 'lib/on/test_helper.rb', line 59 def initialize @block = false @callbacks = [] end |
Instance Method Details
#block_called? ⇒ Boolean
64 65 66 |
# File 'lib/on/test_helper.rb', line 64 def block_called? @block end |
#empty? ⇒ Boolean
68 69 70 |
# File 'lib/on/test_helper.rb', line 68 def empty? @callbacks.empty? end |
#last_record ⇒ Object
Pops the last recorded recorded.
73 74 75 |
# File 'lib/on/test_helper.rb', line 73 def last_record @callbacks.pop end |
#record_all ⇒ Object
Records block and all defined callbacks.
78 79 80 81 82 83 |
# File 'lib/on/test_helper.rb', line 78 def record_all proc do |on| record_block record_callback(on, *on.callbacks) end end |
#record_block ⇒ Object
96 97 98 |
# File 'lib/on/test_helper.rb', line 96 def record_block @block = true end |
#record_callback(on, *names) ⇒ Object
Records a single callback.
101 102 103 104 105 106 107 |
# File 'lib/on/test_helper.rb', line 101 def record_callback(on, *names) names.each do |name| on.on name do |*args| @callbacks << Callback.new(name, args) end end end |
#to_proc ⇒ Object
Short-hand for &recorder.record_all
.
110 111 112 |
# File 'lib/on/test_helper.rb', line 110 def to_proc record_all end |