Methods
- any_number_of_times
- at_least
- at_most
- exactly
- generate_error
- ignoring_args?
- matches_at_least_count?
- matches_at_most_count?
- matches_exact_count?
- matches_name_but_not_args
- negative_expectation_for?
- never
- once
- ordered
- set_expected_received_count
- times
- twice
- verify_messages_received
- with
Public Instance methods
[ show source ]
# File lib/spec/mocks/message_expectation.rb, line 208
208: def any_number_of_times(&block)
209: @method_block = block if block
210: @expected_received_count = :any
211: self
212: end
[ show source ]
# File lib/spec/mocks/message_expectation.rb, line 193
193: def at_least(n)
194: set_expected_received_count :at_least, n
195: self
196: end
[ show source ]
# File lib/spec/mocks/message_expectation.rb, line 198
198: def at_most(n)
199: set_expected_received_count :at_most, n
200: self
201: end
[ show source ]
# File lib/spec/mocks/message_expectation.rb, line 188
188: def exactly(n)
189: set_expected_received_count :exactly, n
190: self
191: end
[ show source ]
# File lib/spec/mocks/message_expectation.rb, line 178
178: def generate_error
179: @error_generator.raise_expectation_error(@sym, @expected_received_count, @actual_received_count, *@args_expectation.args)
180: end
[ show source ]
# File lib/spec/mocks/message_expectation.rb, line 162
162: def ignoring_args?
163: @expected_received_count == :any
164: end
[ show source ]
# File lib/spec/mocks/message_expectation.rb, line 166
166: def matches_at_least_count?
167: @at_least && @actual_received_count >= @expected_received_count
168: end
[ show source ]
# File lib/spec/mocks/message_expectation.rb, line 170
170: def matches_at_most_count?
171: @at_most && @actual_received_count <= @expected_received_count
172: end
[ show source ]
# File lib/spec/mocks/message_expectation.rb, line 174
174: def matches_exact_count?
175: @expected_received_count == @actual_received_count
176: end
[ show source ]
# File lib/spec/mocks/message_expectation.rb, line 148
148: def matches_name_but_not_args(sym, args)
149: @sym == sym and not @args_expectation.check_args(args)
150: end
[ show source ]
# File lib/spec/mocks/message_expectation.rb, line 238
238: def negative_expectation_for?(sym)
239: return false
240: end
[ show source ]
# File lib/spec/mocks/message_expectation.rb, line 214
214: def never
215: @expected_received_count = 0
216: self
217: end
[ show source ]
# File lib/spec/mocks/message_expectation.rb, line 219
219: def once(&block)
220: @method_block = block if block
221: @expected_received_count = 1
222: self
223: end
[ show source ]
# File lib/spec/mocks/message_expectation.rb, line 231
231: def ordered(&block)
232: @method_block = block if block
233: @order_group.register(self)
234: @ordered = true
235: self
236: end
[ show source ]
# File lib/spec/mocks/message_expectation.rb, line 203
203: def times(&block)
204: @method_block = block if block
205: self
206: end
[ show source ]
# File lib/spec/mocks/message_expectation.rb, line 225
225: def twice(&block)
226: @method_block = block if block
227: @expected_received_count = 2
228: self
229: end
[ show source ]
# File lib/spec/mocks/message_expectation.rb, line 152
152: def verify_messages_received
153: return if ignoring_args? || matches_exact_count? ||
154: matches_at_least_count? || matches_at_most_count?
155:
156: generate_error
157: rescue Spec::Mocks::MockExpectationError => error
158: error.backtrace.insert(0, @expected_from)
159: Kernel::raise error
160: end
[ show source ]
# File lib/spec/mocks/message_expectation.rb, line 182
182: def with(*args, &block)
183: @method_block = block if block
184: @args_expectation = ArgumentExpectation.new(args)
185: self
186: end
Protected Instance methods
[ show source ]
# File lib/spec/mocks/message_expectation.rb, line 243
243: def set_expected_received_count(relativity, n)
244: @at_least = (relativity == :at_least)
245: @at_most = (relativity == :at_most)
246: @expected_received_count = case n
247: when Numeric
248: n
249: when :once
250: 1
251: when :twice
252: 2
253: end
254: end