Class: Impersonator::BlockSpy

Inherits:
Struct
  • Object
show all
Defined in:
lib/impersonator/block_spy.rb

Overview

An spy object that can collect block invocations

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#actual_blockObject

Returns the value of attribute actual_block

Returns:

  • (Object)

    the current value of actual_block



3
4
5
# File 'lib/impersonator/block_spy.rb', line 3

def actual_block
  @actual_block
end

#block_invocationsObject

Returns the value of attribute block_invocations

Returns:

  • (Object)

    the current value of block_invocations



3
4
5
# File 'lib/impersonator/block_spy.rb', line 3

def block_invocations
  @block_invocations
end

Instance Method Details

#blockProc

Returns a proc that will collect block invocations.

Returns:



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