Parent

Files

Caricature::MethodCallRecording

A recording that represents a method call it contains argument variations that can be matched too

Attributes

method_name[RW]

gets or sets the method name

count[RW]

gets or sets the amount of times the method was called

args[RW]

gets or sets the arguments for this method call

block[RW]

gets or sets the block for this method call

Public Class Methods

new(method_name, count=0) click to toggle source

Initializes a new instance of a method call recording every time a method gets called in an isolated object this gets stored in the method call recorder It expects a method_name at the very least.

     # File lib/caricature/method_call_recorder.rb, line 98
 98:     def initialize(method_name, count=0)
 99:       @method_name = method_name
100:       @count = count
101:       @variations = []
102:     end

Public Instance Methods

add_argument_variation(args, block) click to toggle source

add an argument variation

     # File lib/caricature/method_call_recorder.rb, line 115
115:     def add_argument_variation(args, block)
116:       variation = find_argument_variations args, nil
117:       if variation.empty?
118:         @variations << ArgumentRecording.new(args, @variations.size+1, block) if variation == []
119:       else
120:         variation.first.call_number += 1
121:       end
122:     end
args() click to toggle source

add args

     # File lib/caricature/method_call_recorder.rb, line 105
105:     def args
106:       @variations
107:     end
find_argument_variations(args, block_args) click to toggle source

finds an argument variation that matches the provided args

     # File lib/caricature/method_call_recorder.rb, line 125
125:     def find_argument_variations(args, block_args)
126:       return @variations if args.first.is_a?(Symbol) and args.last == :any
127:       return match_hash(args, block_args) if args.size == 1 and args.last.is_a?(Hash)
128:       return @variations.select { |ar| ar.args == args } if block_args.nil? 
129:       return @variations.select { |ar| ar.args == args and ar.block } if block_args.last == :any
130:       return @variations.select do |ar|
131:         av = ar.args == args
132:         # idx = 0
133:         #         ags = ar.args
134:         #         av = args.all? do |ag| 
135:         #           rag = ags[idx]
136:         #           res = if ag.is_a?(Hash) and rag.is_a?(Hash)
137:         #             ag.all? { |k, v| ar.args[idx][k] == v  }
138:         #           else
139:         #             ag == rag
140:         #           end
141:         #           idx += 1
142:         #           res
143:         #         end
144:         av and not ar.find_block_variation(*block_args).empty?
145:       end
146:     end
has_argument_variations?() click to toggle source

indicates if it has an argument variation

     # File lib/caricature/method_call_recorder.rb, line 110
110:     def has_argument_variations?
111:       @variations.size > 1
112:     end
match_hash(args, block_args) click to toggle source
     # File lib/caricature/method_call_recorder.rb, line 148
148:     def match_hash(args, block_args)
149:       @variations.select do |ar| 
150:         ags = ar.args.last
151:         args.last.all? { |k, v| ags[k] == v }  
152:       end
153:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.