Module: RR::DoubleDefinitions::DoubleDefinition::TimesDefinitionConstructionMethods
- Included in:
- RR::DoubleDefinitions::DoubleDefinition, SpyVerification
- Defined in:
- lib/rr/double_definitions/double_definition.rb
Instance Method Summary collapse
-
#any_number_of_times(&return_value_block) ⇒ Object
(also: #any_times)
Double#any_number_of_times sets an that the Double will be called any number of times.
-
#at_least(number, &return_value_block) ⇒ Object
Double#at_least sets the expectation that the Double will be called at least n times.
-
#at_most(number, &return_value_block) ⇒ Object
Double#at_most allows sets the expectation that the Double will be called at most n times.
-
#never ⇒ Object
Double#never sets the expectation that the Double will never be called.
-
#once(&return_value_block) ⇒ Object
Double#once sets the expectation that the Double will be called 1 time.
-
#times(matcher_value, &return_value_block) ⇒ Object
Double#times creates an TimesCalledExpectation of the passed in number.
-
#twice(&return_value_block) ⇒ Object
Double#twice sets the expectation that the Double will be called 2 times.
Instance Method Details
#any_number_of_times(&return_value_block) ⇒ Object Also known as: any_times
Double#any_number_of_times sets an that the Double will be called any number of times. This effectively removes the times called expectation from the Doublen
Passing in a block sets the return value.
mock(subject).method_name.any_number_of_times
158 159 160 161 162 |
# File 'lib/rr/double_definitions/double_definition.rb', line 158 def any_number_of_times(&return_value_block) @times_matcher = TimesCalledMatchers::AnyTimesMatcher.new install_method_callback return_value_block self end |
#at_least(number, &return_value_block) ⇒ Object
Double#at_least sets the expectation that the Double will be called at least n times. It works by creating a TimesCalledExpectation.
Passing in a block sets the return value.
mock(subject).method_name.at_least(4) {:return_value}
132 133 134 135 136 |
# File 'lib/rr/double_definitions/double_definition.rb', line 132 def at_least(number, &return_value_block) @times_matcher = TimesCalledMatchers::AtLeastMatcher.new(number) install_method_callback return_value_block self end |
#at_most(number, &return_value_block) ⇒ Object
Double#at_most allows sets the expectation that the Double will be called at most n times. It works by creating a TimesCalledExpectation.
Passing in a block sets the return value.
mock(subject).method_name.at_most(4) {:return_value}
145 146 147 148 149 |
# File 'lib/rr/double_definitions/double_definition.rb', line 145 def at_most(number, &return_value_block) @times_matcher = TimesCalledMatchers::AtMostMatcher.new(number) install_method_callback return_value_block self end |
#never ⇒ Object
Double#never sets the expectation that the Double will never be called.
This method does not accept a block because it will never be called.
mock(subject).method_name.never
96 97 98 99 |
# File 'lib/rr/double_definitions/double_definition.rb', line 96 def never @times_matcher = TimesCalledMatchers::IntegerMatcher.new(0) self end |
#once(&return_value_block) ⇒ Object
Double#once sets the expectation that the Double will be called 1 time.
Passing in a block sets the return value.
mock(subject).method_name.once {:return_value}
107 108 109 110 111 |
# File 'lib/rr/double_definitions/double_definition.rb', line 107 def once(&return_value_block) @times_matcher = TimesCalledMatchers::IntegerMatcher.new(1) install_method_callback return_value_block self end |
#times(matcher_value, &return_value_block) ⇒ Object
Double#times creates an TimesCalledExpectation of the passed in number.
Passing in a block sets the return value.
mock(subject).method_name.times(4) {:return_value}
171 172 173 174 175 |
# File 'lib/rr/double_definitions/double_definition.rb', line 171 def times(matcher_value, &return_value_block) @times_matcher = TimesCalledMatchers::TimesCalledMatcher.create(matcher_value) install_method_callback return_value_block self end |
#twice(&return_value_block) ⇒ Object
Double#twice sets the expectation that the Double will be called 2 times.
Passing in a block sets the return value.
mock(subject).method_name.twice {:return_value}
119 120 121 122 123 |
# File 'lib/rr/double_definitions/double_definition.rb', line 119 def twice(&return_value_block) @times_matcher = TimesCalledMatchers::IntegerMatcher.new(2) install_method_callback return_value_block self end |