The recorder that will collect method calls and provides an interface for finding those recordings
Initializes a new instance of a method call recorder every time a method gets called in an isolated object this gets stored in the method call recorder
# File lib/caricature/method_call_recorder.rb, line 166
166: def initialize
167: @method_calls = {:instance => {}, :class => {} }
168: end
# File lib/caricature/method_call_recorder.rb, line 193
193: def error
194: @error
195: end
# File lib/caricature/clr/method_call_recorder.rb, line 71
71: def event_error
72: @event_error
73: end
returns whether the event was actually raised with the specified constraints
# File lib/caricature/clr/method_call_recorder.rb, line 76
76: def event_raised?(event_name, mode = :instance, *args)
77: mc = event_raises[mode][event_name.to_s.to_sym]
78: if mc
79: vari = mc.find_argument_variations(args)
80: result = vari.any? { |agv| agv == args }
81: return result if result
82: if args.size == 1 and args.last.is_a?(Hash)
83: result = vari.any? do |agv|
84: agv.args.last.is_a?(Hash) and args.last.all? { |k, v| agv.args.last[k] == v }
85: end
86: end
87: @event_error = "Event Arguments don't match for #{event_name}.\n\nYou expected:\n#{args.join(", ")}.\n\nI did find the following variations:\n#{mc.args.collect {|ar| ar.args.join(', ') }.join(' and ')}" unless result
88: result
89: else
90: @event_error = "Couldn't find an event with name #{event_name}"
91: return !!mc
92: end
93: end
# File lib/caricature/clr/method_call_recorder.rb, line 59
59: def event_raises
60: @event_raises ||= {}
61: end
records a method call or increments the count of how many times this method was called.
# File lib/caricature/method_call_recorder.rb, line 171
171: def record_call(method_name, mode=:instance, expectation=nil, *args, &block)
172: mn_sym = method_name.to_s.underscore.to_sym
173: method_calls[mode][mn_sym] ||= MethodCallRecording.new mn_sym.to_s
174: mc = method_calls[mode][mn_sym]
175: mc.count += 1
176: agc = mc.add_argument_variation args, block
177: b = (expectation && expectation.block) ? (expectation.block||block) : block
178: expectation.block = lambda do |*ags|
179: res = nil
180: res = b.call *ags if b
181: agc.first.add_block_variation *ags
182: res
183: end if expectation
184: block.nil? ? nil : (lambda { |*ags|
185: res = nil
186: res = block.call *ags if block
187: agc.first.add_block_variation *ags
188: res
189: })
190: end
# File lib/caricature/clr/method_call_recorder.rb, line 63
63: def record_event_raise(event_name, mode, *args, &handler)
64: en_sym = event_name.to_sym
65: event_raises[mode] ||= {}
66: ev = (event_raises[mode][en_sym] ||= EventRaiseRecording.new(event_name))
67: ev.count += 1
68: ev.add_argument_variation args, handler
69: end
returns the number of different methods that has been recorderd
# File lib/caricature/method_call_recorder.rb, line 223
223: def size
224: @method_calls.size
225: end
returns whether the method was actually called with the specified constraints
# File lib/caricature/method_call_recorder.rb, line 198
198: def was_called?(method_name, block_args, mode=:instance, *args)
199: mc = method_calls[mode][method_name.to_s.underscore.to_sym]
200: if mc
201: vari = mc.find_argument_variations(args, block_args)
202: result = vari.any? { |agv| agv == args }
203: return result if result
204: if args.size == 1 and args.last.is_a?(Hash)
205: result = vari.any? do |agv|
206: agv.args.last.is_a?(Hash) and args.last.all? { |k, v| agv.args.last[k] == v }
207: end
208: end
209: @error = "Arguments don't match.\nYou expected:\n#{args.join(", ")}.\nI did find the following variations:\n#{mc.args.collect {|ar| ar.args.join(', ') }.join("\nand\n")}" unless result
210: result
211: else
212: @error = "Couldn't find a method with name #{method_name}"
213: return !!mc
214: end
215: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.