Class: Spec::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
#advise(args, block) ⇒ Object
233
234
235
|
# File 'lib/gems/rspec-1.1.11/lib/spec/mocks/message_expectation.rb', line 233
def advise(args, block)
similar_messages << args
end
|
#any_number_of_times(&block) ⇒ Object
270
271
272
273
274
|
# File 'lib/gems/rspec-1.1.11/lib/spec/mocks/message_expectation.rb', line 270
def any_number_of_times(&block)
@method_block = block if block
@expected_received_count = :any
self
end
|
#at_least(n) ⇒ Object
255
256
257
258
|
# File 'lib/gems/rspec-1.1.11/lib/spec/mocks/message_expectation.rb', line 255
def at_least(n)
set_expected_received_count :at_least, n
self
end
|
#at_most(n) ⇒ Object
260
261
262
263
|
# File 'lib/gems/rspec-1.1.11/lib/spec/mocks/message_expectation.rb', line 260
def at_most(n)
set_expected_received_count :at_most, n
self
end
|
#exactly(n) ⇒ Object
250
251
252
253
|
# File 'lib/gems/rspec-1.1.11/lib/spec/mocks/message_expectation.rb', line 250
def exactly(n)
set_expected_received_count :exactly, n
self
end
|
#expected_messages_received? ⇒ Boolean
208
209
210
211
|
# File 'lib/gems/rspec-1.1.11/lib/spec/mocks/message_expectation.rb', line 208
def expected_messages_received?
ignoring_args? || matches_exact_count? ||
matches_at_least_count? || matches_at_most_count?
end
|
#generate_error ⇒ Object
237
238
239
240
241
242
243
|
# File 'lib/gems/rspec-1.1.11/lib/spec/mocks/message_expectation.rb', line 237
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_unexpected_message_args_error(self, *@similar_messages.first)
end
end
|
#ignoring_args? ⇒ Boolean
213
214
215
|
# File 'lib/gems/rspec-1.1.11/lib/spec/mocks/message_expectation.rb', line 213
def ignoring_args?
@expected_received_count == :any
end
|
#matches_at_least_count? ⇒ Boolean
217
218
219
|
# File 'lib/gems/rspec-1.1.11/lib/spec/mocks/message_expectation.rb', line 217
def matches_at_least_count?
@at_least && @actual_received_count >= @expected_received_count
end
|
#matches_at_most_count? ⇒ Boolean
221
222
223
|
# File 'lib/gems/rspec-1.1.11/lib/spec/mocks/message_expectation.rb', line 221
def matches_at_most_count?
@at_most && @actual_received_count <= @expected_received_count
end
|
#matches_exact_count? ⇒ Boolean
225
226
227
|
# File 'lib/gems/rspec-1.1.11/lib/spec/mocks/message_expectation.rb', line 225
def matches_exact_count?
@expected_received_count == @actual_received_count
end
|
#matches_name_but_not_args(sym, args) ⇒ Object
195
196
197
|
# File 'lib/gems/rspec-1.1.11/lib/spec/mocks/message_expectation.rb', line 195
def matches_name_but_not_args(sym, args)
@sym == sym and not @args_expectation.args_match?(args)
end
|
#negative_expectation_for?(sym) ⇒ Boolean
300
301
302
|
# File 'lib/gems/rspec-1.1.11/lib/spec/mocks/message_expectation.rb', line 300
def negative_expectation_for?(sym)
return false
end
|
276
277
278
279
|
# File 'lib/gems/rspec-1.1.11/lib/spec/mocks/message_expectation.rb', line 276
def never
@expected_received_count = 0
self
end
|
#once(&block) ⇒ Object
281
282
283
284
285
|
# File 'lib/gems/rspec-1.1.11/lib/spec/mocks/message_expectation.rb', line 281
def once(&block)
@method_block = block if block
@expected_received_count = 1
self
end
|
#ordered(&block) ⇒ Object
293
294
295
296
297
298
|
# File 'lib/gems/rspec-1.1.11/lib/spec/mocks/message_expectation.rb', line 293
def ordered(&block)
@method_block = block if block
@order_group.register(self)
@ordered = true
self
end
|
#similar_messages ⇒ Object
229
230
231
|
# File 'lib/gems/rspec-1.1.11/lib/spec/mocks/message_expectation.rb', line 229
def similar_messages
@similar_messages ||= []
end
|
#times(&block) ⇒ Object
265
266
267
268
|
# File 'lib/gems/rspec-1.1.11/lib/spec/mocks/message_expectation.rb', line 265
def times(&block)
@method_block = block if block
self
end
|
#twice(&block) ⇒ Object
287
288
289
290
291
|
# File 'lib/gems/rspec-1.1.11/lib/spec/mocks/message_expectation.rb', line 287
def twice(&block)
@method_block = block if block
@expected_received_count = 2
self
end
|
#verify_messages_received ⇒ Object
199
200
201
202
203
204
205
206
|
# File 'lib/gems/rspec-1.1.11/lib/spec/mocks/message_expectation.rb', line 199
def verify_messages_received
return if expected_messages_received? || failed_fast?
generate_error
rescue Spec::Mocks::MockExpectationError => error
error.backtrace.insert(0, @expected_from)
Kernel::raise error
end
|
#with(*args, &block) ⇒ Object
245
246
247
248
|
# File 'lib/gems/rspec-1.1.11/lib/spec/mocks/message_expectation.rb', line 245
def with(*args, &block)
@args_expectation = ArgumentExpectation.new(args, &block)
self
end
|