Class: RSpec::Mocks::MessageExpectation
Instance Attribute Summary
#sym
Instance Method Summary
collapse
#and_raise, #and_return, #and_throw, #and_yield, #build_child, #called_max_times?, #expected_args, #initialize, #invoke, #matches?
Instance Method Details
#actual_received_count_matters? ⇒ Boolean
314
315
316
|
# File 'lib/rspec/mocks/message_expectation.rb', line 314
def actual_received_count_matters?
@at_least || @at_most || @exactly
end
|
#advise(*args) ⇒ Object
239
240
241
|
# File 'lib/rspec/mocks/message_expectation.rb', line 239
def advise(*args)
similar_messages << args
end
|
#any_number_of_times(&block) ⇒ Object
280
281
282
283
284
|
# File 'lib/rspec/mocks/message_expectation.rb', line 280
def any_number_of_times(&block)
@method_block = block if block
@expected_received_count = :any
self
end
|
#at_least(n, &block) ⇒ Object
263
264
265
266
267
|
# File 'lib/rspec/mocks/message_expectation.rb', line 263
def at_least(n, &block)
@method_block = block if block
set_expected_received_count :at_least, n
self
end
|
#at_most(n, &block) ⇒ Object
269
270
271
272
273
|
# File 'lib/rspec/mocks/message_expectation.rb', line 269
def at_most(n, &block)
@method_block = block if block
set_expected_received_count :at_most, n
self
end
|
#exactly(n, &block) ⇒ Object
257
258
259
260
261
|
# File 'lib/rspec/mocks/message_expectation.rb', line 257
def exactly(n, &block)
@method_block = block if block
set_expected_received_count :exactly, n
self
end
|
#expected_messages_received? ⇒ Boolean
214
215
216
217
|
# File 'lib/rspec/mocks/message_expectation.rb', line 214
def expected_messages_received?
ignoring_args? || matches_exact_count? ||
matches_at_least_count? || matches_at_most_count?
end
|
#generate_error ⇒ Object
243
244
245
246
247
248
249
|
# File 'lib/rspec/mocks/message_expectation.rb', line 243
def generate_error
if similar_messages.empty?
@error_generator.raise_expectation_error(@sym, @expected_received_count, @actual_received_count, *@args_expectation.args)
else
@error_generator.raise_similar_message_args_error(self, *@similar_messages)
end
end
|
#ignoring_args? ⇒ Boolean
219
220
221
|
# File 'lib/rspec/mocks/message_expectation.rb', line 219
def ignoring_args?
@expected_received_count == :any
end
|
#increase_actual_received_count! ⇒ Object
318
319
320
|
# File 'lib/rspec/mocks/message_expectation.rb', line 318
def increase_actual_received_count!
@actual_received_count += 1
end
|
#matches_at_least_count? ⇒ Boolean
223
224
225
|
# File 'lib/rspec/mocks/message_expectation.rb', line 223
def matches_at_least_count?
@at_least && @actual_received_count >= @expected_received_count
end
|
#matches_at_most_count? ⇒ Boolean
227
228
229
|
# File 'lib/rspec/mocks/message_expectation.rb', line 227
def matches_at_most_count?
@at_most && @actual_received_count <= @expected_received_count
end
|
#matches_exact_count? ⇒ Boolean
231
232
233
|
# File 'lib/rspec/mocks/message_expectation.rb', line 231
def matches_exact_count?
@expected_received_count == @actual_received_count
end
|
#matches_name_but_not_args(sym, *args) ⇒ Object
201
202
203
|
# File 'lib/rspec/mocks/message_expectation.rb', line 201
def matches_name_but_not_args(sym, *args)
@sym == sym and not @args_expectation.args_match?(*args)
end
|
#negative_expectation_for?(sym) ⇒ Boolean
310
311
312
|
# File 'lib/rspec/mocks/message_expectation.rb', line 310
def negative_expectation_for?(sym)
return false
end
|
#never ⇒ Object
286
287
288
289
|
# File 'lib/rspec/mocks/message_expectation.rb', line 286
def never
@expected_received_count = 0
self
end
|
#once(&block) ⇒ Object
291
292
293
294
295
|
# File 'lib/rspec/mocks/message_expectation.rb', line 291
def once(&block)
@method_block = block if block
set_expected_received_count :exactly, 1
self
end
|
#ordered(&block) ⇒ Object
303
304
305
306
307
308
|
# File 'lib/rspec/mocks/message_expectation.rb', line 303
def ordered(&block)
@method_block = block if block
@order_group.register(self)
@ordered = true
self
end
|
#similar_messages ⇒ Object
235
236
237
|
# File 'lib/rspec/mocks/message_expectation.rb', line 235
def similar_messages
@similar_messages ||= []
end
|
#times(&block) ⇒ Object
275
276
277
278
|
# File 'lib/rspec/mocks/message_expectation.rb', line 275
def times(&block)
@method_block = block if block
self
end
|
#twice(&block) ⇒ Object
297
298
299
300
301
|
# File 'lib/rspec/mocks/message_expectation.rb', line 297
def twice(&block)
@method_block = block if block
set_expected_received_count :exactly, 2
self
end
|
#verify_messages_received ⇒ Object
205
206
207
208
209
210
211
212
|
# File 'lib/rspec/mocks/message_expectation.rb', line 205
def verify_messages_received
return if expected_messages_received? || failed_fast?
generate_error
rescue RSpec::Mocks::MockExpectationError => error
error.backtrace.insert(0, @expected_from)
Kernel::raise error
end
|
#with(*args, &block) ⇒ Object
251
252
253
254
255
|
# File 'lib/rspec/mocks/message_expectation.rb', line 251
def with(*args, &block)
@return_block = block if block_given? unless args.empty?
@args_expectation = ArgumentExpectation.new(*args, &block)
self
end
|