class RR::Double
RR::Double
is the use case for a method call. It has the ArgumentEqualityExpectation, TimesCalledExpectation, and the implementation.
Attributes
Public Class Methods
Source
# File lib/rr/double.rb, line 23 def initialize(double_injection, definition) @double_injection = double_injection @definition = definition @times_called = 0 @times_called_expectation = Expectations::TimesCalledExpectation.new(self) definition.double = self verify_method_signature if definition.verify_method_signature? double_injection.register_double self end
Public Instance Methods
Source
# File lib/rr/double.rb, line 47 def attempt? verify_times_matcher_is_set times_called_expectation.attempt? end
Double#attempt?
returns true when the TimesCalledExpectation is satisfied.
Source
# File lib/rr/double.rb, line 35 def exact_match?(*arguments) definition.exact_match?(*arguments) end
Double#exact_match?
returns true when the passed in arguments exactly match the ArgumentEqualityExpectation arguments.
Source
# File lib/rr/double.rb, line 72 def expected_arguments verify_argument_expectation_is_set argument_expectation.expected_arguments end
The Arguments that this Double
expects
Source
# File lib/rr/double.rb, line 82 def formatted_name self.class.formatted_name(method_name, expected_arguments) end
Source
# File lib/rr/double.rb, line 94 def implementation_is_original_method? definition.implementation_is_original_method? end
Source
# File lib/rr/double.rb, line 86 def method_call(args) if verbose? puts Double.formatted_name(method_name, args) end times_called_expectation.attempt if definition.times_matcher space.verify_ordered_double(self) if ordered? end
Source
# File lib/rr/double.rb, line 67 def method_name double_injection.method_name end
The method name that this Double
is attatched to
Source
# File lib/rr/double.rb, line 61 def terminal? verify_times_matcher_is_set times_called_expectation.terminal? end
Source
# File lib/rr/double.rb, line 78 def times_matcher definition.times_matcher end
The TimesCalledMatcher for the TimesCalledExpectation
Source
# File lib/rr/double.rb, line 55 def verify verify_times_matcher_is_set times_called_expectation.verify! true end
Double#verify
verifies the the TimesCalledExpectation is satisfied for this double. A TimesCalledError is raised if the TimesCalledExpectation is not met.
Source
# File lib/rr/double.rb, line 41 def wildcard_match?(*arguments) definition.wildcard_match?(*arguments) end
Double#wildcard_match?
returns true when the passed in arguments wildcard match the ArgumentEqualityExpectation arguments.
Protected Instance Methods
Source
# File lib/rr/double.rb, line 147 def args definition.argument_expectation.expected_arguments end
Source
# File lib/rr/double.rb, line 151 def argument_expectation definition.argument_expectation end
Source
# File lib/rr/double.rb, line 138 def arity_matches? return true if subject_accepts_only_varargs? if subject_accepts_varargs? return ((subject_arity * -1) - 1) <= args.size else return subject_arity == args.size end end
Source
# File lib/rr/double.rb, line 130 def subject_accepts_only_varargs? subject_arity == -1 end
Source
# File lib/rr/double.rb, line 134 def subject_accepts_varargs? subject_arity < 0 end
Source
# File lib/rr/double.rb, line 126 def subject_arity double_injection.original_method.arity end
Source
# File lib/rr/double.rb, line 113 def verify_argument_expectation_is_set unless definition.argument_expectation raise RR::Errors.build_error(:DoubleDefinitionError, "#definition.argument_expectation is not set") end end
Source
# File lib/rr/double.rb, line 119 def verify_method_signature unless double_injection.subject_has_original_method? raise RR::Errors.build_error(:SubjectDoesNotImplementMethodError) end raise RR::Errors.build_error(:SubjectHasDifferentArityError) unless arity_matches? end
Source
# File lib/rr/double.rb, line 107 def verify_times_matcher_is_set unless definition.times_matcher raise RR::Errors.build_error(:DoubleDefinitionError, "#definition.times_matcher is not set") end end