Class: Impersonator::BlockSpy
- Inherits:
-
Struct
- Object
- Struct
- Impersonator::BlockSpy
- Defined in:
- lib/impersonator/block_spy.rb
Overview
An spy object that can collect block invocations
Instance Attribute Summary collapse
-
#actual_block ⇒ Object
Returns the value of attribute actual_block.
-
#block_invocations ⇒ Object
Returns the value of attribute block_invocations.
Instance Method Summary collapse
-
#block ⇒ Proc
A proc that will collect block invocations.
- #encode_with(coder) ⇒ Object
- #init_with(coder) ⇒ Object
Instance Attribute Details
#actual_block ⇒ Object
Returns the value of attribute actual_block
3 4 5 |
# File 'lib/impersonator/block_spy.rb', line 3 def actual_block @actual_block end |
#block_invocations ⇒ Object
Returns the value of attribute block_invocations
3 4 5 |
# File 'lib/impersonator/block_spy.rb', line 3 def block_invocations @block_invocations end |
Instance Method Details
#block ⇒ Proc
Returns a proc that will collect block invocations.
5 6 7 8 9 10 11 12 |
# File 'lib/impersonator/block_spy.rb', line 5 def block @block ||= proc do |*arguments| self.block_invocations ||= [] self.block_invocations << BlockInvocation.new(arguments: arguments) return_value = actual_block.call(*arguments) return_value end end |
#encode_with(coder) ⇒ Object
18 19 20 |
# File 'lib/impersonator/block_spy.rb', line 18 def encode_with(coder) coder['block_invocations'] = block_invocations end |
#init_with(coder) ⇒ Object
14 15 16 |
# File 'lib/impersonator/block_spy.rb', line 14 def init_with(coder) self.block_invocations = coder['block_invocations'] end |