Object
TODO I can’t work out how to disentangle the 2 responsibilities of this class:
Inspecting and acting on spy invocations
Presenting the results of those inspections.
One to revisit later when my head is less befuddled.
# File lib/matahari/invocation_matcher.rb, line 10 def initialize(iterator = nil) @expected_call_count = iterator ? iterator.count : nil end
# File lib/matahari/invocation_matcher.rb, line 26 def failure_message_for_should if @args_to_verify.size > 0 "Spy(:#{@subject.name}) expected to receive :#{@call_to_verify}(#{@args_to_verify.map(&:inspect).join(", ")}) #{prettify_times(@expected_call_count)}, received #{prettify_times(@matching_calls)}" else "Spy(:#{@subject.name}) expected to receive :#{@call_to_verify} #{prettify_times(@expected_call_count)}, received #{prettify_times(@matching_calls)}" end end
# File lib/matahari/invocation_matcher.rb, line 22 def failure_message_for_should_not "Spy(:#{@subject.name}) expected not to receive :#{@call_to_verify} but received it #{prettify_times(@matching_calls)}" end
# File lib/matahari/invocation_matcher.rb, line 14 def matches?(subject) @subject = subject @invocations_of_method = subject.invocations.select {|i| i.method == @call_to_verify} verifying_args = @args_to_verify.size != 0 match_passes?(verifying_args) end
Allows chaining of method calls following has_received?/should have_received, e.g. spy.should_have received.some_method, where some_method is handled by method_missing, its arguments and name being stored until matches? is called.
# File lib/matahari/invocation_matcher.rb, line 37 def method_missing(sym, *args, &block) @call_to_verify = sym @args_to_verify = args self end
Generated with the Darkfish Rdoc Generator 2.