Class | RR::RecordedCalls |
In: |
lib/rr/recorded_calls.rb
|
Parent: | Object |
ordered_index | [RW] | |
recorded_calls | [R] |
# File lib/rr/recorded_calls.rb, line 5 5: def initialize(recorded_calls=[]) 6: @recorded_calls = recorded_calls 7: @ordered_index = 0 8: end
# File lib/rr/recorded_calls.rb, line 17 17: def <<(recorded_call) 18: recorded_calls << recorded_call 19: end
# File lib/rr/recorded_calls.rb, line 25 25: def ==(other) 26: recorded_calls == other.recorded_calls 27: end
# File lib/rr/recorded_calls.rb, line 21 21: def any?(&block) 22: recorded_calls.any?(&block) 23: end
# File lib/rr/recorded_calls.rb, line 12 12: def clear 13: self.ordered_index = 0 14: recorded_calls.clear 15: end
# File lib/rr/recorded_calls.rb, line 29 29: def match_error(spy_verification) 30: double_injection_exists_error(spy_verification) || begin 31: if spy_verification.ordered? 32: ordered_match_error(spy_verification) 33: else 34: unordered_match_error(spy_verification) 35: end 36: end 37: end
# File lib/rr/recorded_calls.rb, line 42 42: def double_injection_exists_error(spy_verification) 43: unless Injections::DoubleInjection.exists_by_subject?(spy_verification.subject, spy_verification.method_name) 44: RR::Errors::SpyVerificationErrors::DoubleInjectionNotFoundError.new( 45: "A Double Injection for the subject and method call:\n" << 46: "#{spy_verification.subject.inspect}\n" << 47: "#{spy_verification.method_name}\ndoes not exist in:\n" << 48: "\t#{recorded_calls.map {|call| call.inspect}.join("\n\t")}" 49: ) 50: end 51: end
# File lib/rr/recorded_calls.rb, line 92 92: def invocation_count_error(spy_verification, matching_recorded_calls) 93: RR::Errors::SpyVerificationErrors::InvocationCountError.new( 94: "On subject #{spy_verification.subject.inspect}\n" << 95: "Expected #{Double.formatted_name(spy_verification.method_name, spy_verification.argument_expectation.expected_arguments)}\n" << 96: "to be called #{spy_verification.times_matcher.expected_times_message},\n" << 97: "but was called #{matching_recorded_calls.size} times.\n" << 98: "All of the method calls related to Doubles are:\n" << 99: "\t#{recorded_calls.map {|call| call.inspect}.join("\n\t")}" 100: ) 101: end
# File lib/rr/recorded_calls.rb, line 85 85: def match_argument_expectation(spy_verification) 86: lambda do |recorded_call| 87: spy_verification.argument_expectation.exact_match?(*recorded_call[2]) || 88: spy_verification.argument_expectation.wildcard_match?(*recorded_call[2]) 89: end 90: end
# File lib/rr/recorded_calls.rb, line 78 78: def match_double_injection(spy_verification) 79: lambda do |recorded_call| 80: recorded_call[0] == spy_verification.subject && 81: recorded_call[1] == spy_verification.method_name 82: end 83: end
# File lib/rr/recorded_calls.rb, line 72 72: def matching_recorded_calls(spy_verification) 73: recorded_calls[ordered_index..-1]. 74: select(&match_double_injection(spy_verification)). 75: select(&match_argument_expectation(spy_verification)) 76: end
# File lib/rr/recorded_calls.rb, line 53 53: def ordered_match_error(spy_verification) 54: memoized_matching_recorded_calls = matching_recorded_calls(spy_verification) 55: 56: if memoized_matching_recorded_calls.last 57: self.ordered_index = recorded_calls.index(memoized_matching_recorded_calls.last) 58: end 59: (0..memoized_matching_recorded_calls.size).to_a.any? do |i| 60: spy_verification.times_matcher.matches?(i) 61: end ? nil : invocation_count_error(spy_verification, memoized_matching_recorded_calls) 62: end
# File lib/rr/recorded_calls.rb, line 64 64: def unordered_match_error(spy_verification) 65: memoized_matching_recorded_calls = matching_recorded_calls(spy_verification) 66: 67: spy_verification.times_matcher.matches?( 68: memoized_matching_recorded_calls.size 69: ) ? nil : invocation_count_error(spy_verification, memoized_matching_recorded_calls) 70: end