Class: RR::Double
Overview
RR::Double is the use case for a method call. It has the ArgumentEqualityExpectation, TimesCalledExpectation, and the implementation.
Instance Attribute Summary collapse
-
#definition ⇒ Object
readonly
Returns the value of attribute definition.
-
#double_injection ⇒ Object
readonly
Returns the value of attribute double_injection.
-
#times_called ⇒ Object
readonly
Returns the value of attribute times_called.
-
#times_called_expectation ⇒ Object
readonly
Returns the value of attribute times_called_expectation.
Instance Method Summary collapse
-
#attempt? ⇒ Boolean
Double#attempt? returns true when the TimesCalledExpectation is satisfied.
-
#exact_match?(arguments, keyword_arguments) ⇒ Boolean
Double#exact_match? returns true when the passed in arguments exactly match the ArgumentEqualityExpectation arguments.
-
#expected_arguments ⇒ Object
The Arguments that this Double expects.
-
#expected_keyword_arguments ⇒ Object
The keyword arguments that this Double expects.
- #formatted_name ⇒ Object
- #implementation_is_original_method? ⇒ Boolean
-
#initialize(double_injection, definition) ⇒ Double
constructor
A new instance of Double.
- #method_call(args, kwargs) ⇒ Object
-
#method_name ⇒ Object
The method name that this Double is attatched to.
- #terminal? ⇒ Boolean
-
#times_matcher ⇒ Object
The TimesCalledMatcher for the TimesCalledExpectation.
-
#verify ⇒ Object
Double#verify verifies the the TimesCalledExpectation is satisfied for this double.
-
#wildcard_match?(arguments, keyword_arguments) ⇒ Boolean
Double#wildcard_match? returns true when the passed in arguments wildcard match the ArgumentEqualityExpectation arguments.
Methods included from Space::Reader
Constructor Details
#initialize(double_injection, definition) ⇒ Double
Returns a new instance of Double.
29 30 31 32 33 34 35 36 37 |
# File 'lib/rr/double.rb', line 29 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 |
Instance Attribute Details
#definition ⇒ Object (readonly)
Returns the value of attribute definition.
25 26 27 |
# File 'lib/rr/double.rb', line 25 def definition @definition end |
#double_injection ⇒ Object (readonly)
Returns the value of attribute double_injection.
25 26 27 |
# File 'lib/rr/double.rb', line 25 def double_injection @double_injection end |
#times_called ⇒ Object (readonly)
Returns the value of attribute times_called.
25 26 27 |
# File 'lib/rr/double.rb', line 25 def times_called @times_called end |
#times_called_expectation ⇒ Object (readonly)
Returns the value of attribute times_called_expectation.
25 26 27 |
# File 'lib/rr/double.rb', line 25 def times_called_expectation @times_called_expectation end |
Instance Method Details
#attempt? ⇒ Boolean
Double#attempt? returns true when the TimesCalledExpectation is satisfied.
53 54 55 56 |
# File 'lib/rr/double.rb', line 53 def attempt? verify_times_matcher_is_set times_called_expectation.attempt? end |
#exact_match?(arguments, keyword_arguments) ⇒ Boolean
Double#exact_match? returns true when the passed in arguments exactly match the ArgumentEqualityExpectation arguments.
41 42 43 |
# File 'lib/rr/double.rb', line 41 def exact_match?(arguments, keyword_arguments) definition.exact_match?(arguments, keyword_arguments) end |
#expected_arguments ⇒ Object
The Arguments that this Double expects
78 79 80 81 |
# File 'lib/rr/double.rb', line 78 def expected_arguments verify_argument_expectation_is_set argument_expectation.expected_arguments end |
#expected_keyword_arguments ⇒ Object
The keyword arguments that this Double expects
84 85 86 87 |
# File 'lib/rr/double.rb', line 84 def expected_keyword_arguments verify_argument_expectation_is_set argument_expectation.expected_keyword_arguments end |
#formatted_name ⇒ Object
94 95 96 97 98 |
# File 'lib/rr/double.rb', line 94 def formatted_name self.class.formatted_name(method_name, expected_arguments, expected_keyword_arguments) end |
#implementation_is_original_method? ⇒ Boolean
108 109 110 |
# File 'lib/rr/double.rb', line 108 def implementation_is_original_method? definition.implementation_is_original_method? end |
#method_call(args, kwargs) ⇒ Object
100 101 102 103 104 105 106 |
# File 'lib/rr/double.rb', line 100 def method_call(args, kwargs) if verbose? puts Double.formatted_name(method_name, args, kwargs) end times_called_expectation.attempt if definition.times_matcher space.verify_ordered_double(self) if ordered? end |
#method_name ⇒ Object
The method name that this Double is attatched to
73 74 75 |
# File 'lib/rr/double.rb', line 73 def method_name double_injection.method_name end |
#terminal? ⇒ Boolean
67 68 69 70 |
# File 'lib/rr/double.rb', line 67 def terminal? verify_times_matcher_is_set times_called_expectation.terminal? end |
#times_matcher ⇒ Object
The TimesCalledMatcher for the TimesCalledExpectation
90 91 92 |
# File 'lib/rr/double.rb', line 90 def times_matcher definition.times_matcher end |
#verify ⇒ Object
Double#verify verifies the the TimesCalledExpectation is satisfied for this double. A TimesCalledError is raised if the TimesCalledExpectation is not met.
61 62 63 64 65 |
# File 'lib/rr/double.rb', line 61 def verify verify_times_matcher_is_set times_called_expectation.verify! true end |
#wildcard_match?(arguments, keyword_arguments) ⇒ Boolean
Double#wildcard_match? returns true when the passed in arguments wildcard match the ArgumentEqualityExpectation arguments.
47 48 49 |
# File 'lib/rr/double.rb', line 47 def wildcard_match?(arguments, keyword_arguments) definition.wildcard_match?(arguments, keyword_arguments) end |