Class: Caricature::ArgumentRecording

Inherits:
Object
  • Object
show all
Defined in:
lib/caricature/method_call_recorder.rb

Overview

A recording of an argument variation. Every time a method is called with different arguments the method call recorder will create an ArgumentVariation these variations are used later in the assertion to verify against specific argument values

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = [], call_number = 1, block = nil) ⇒ ArgumentRecording

initializes a new instance of an argument recording. configures it with 1 call count and the args as an Array



43
44
45
46
47
48
# File 'lib/caricature/method_call_recorder.rb', line 43

def initialize(args=[], call_number=1, block=nil)
  @args = args
  @block = block
  @blocks = []
  @call_number = call_number
end

Instance Attribute Details

#argsObject

contains the arguments of the recorded parameters



30
31
32
# File 'lib/caricature/method_call_recorder.rb', line 30

def args
  @args
end

#blockObject

contains the block for the recorded parameters



33
34
35
# File 'lib/caricature/method_call_recorder.rb', line 33

def block
  @block
end

#blocksObject (readonly)

the collection of block calls variations on this argument variation



39
40
41
# File 'lib/caricature/method_call_recorder.rb', line 39

def blocks
  @blocks
end

#call_numberObject

the number of the call that has the following parameters



36
37
38
# File 'lib/caricature/method_call_recorder.rb', line 36

def call_number
  @call_number
end

Instance Method Details

#==(other) ⇒ Object

compares one argument variation to another. Also takes an array as an argument



66
67
68
69
70
# File 'lib/caricature/method_call_recorder.rb', line 66

def ==(other)
  other = self.class.new(other) if other.respond_to?(:each)
  return true if other.args.first.is_a?(Symbol) and other.args.first == :any 
  other.args == args
end

#add_block_variation(*args) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/caricature/method_call_recorder.rb', line 50

def add_block_variation(*args)
  bv = find_block_variation(*args)
  if bv.empty?
    blocks << BlockCallRecording.new(*args)
  else
    bv.first.call_number += 1
  end
end

#find_block_variation(*args) ⇒ Object



59
60
61
62
# File 'lib/caricature/method_call_recorder.rb', line 59

def find_block_variation(*args)
  return @blocks if args.last.is_a?(Symbol) and args.last == :any
  @blocks.select { |bv| bv.args == args }
end

#to_sObject Also known as: inspect



72
73
74
# File 'lib/caricature/method_call_recorder.rb', line 72

def to_s
  "<ArgumentRecording @args=#{args}, @block= #{block}, @call_number=#{call_number}"
end