Methods
public instance
- advise
- any_number_of_times
- at_least
- at_most
- exactly
- expected_messages_received?
- 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
- similar_messages
- times
- twice
- verify_messages_received
- with
protected instance
Public instance methods
advise
(args, block)
[show source]
# File lib/spec/mocks/message_expectation.rb, line 221 def advise(args, block) similar_messages << args end
any_number_of_times
(&block)
[show source]
# File lib/spec/mocks/message_expectation.rb, line 258 def any_number_of_times(&block) @method_block = block if block @expected_received_count = :any self end
at_least
(n)
[show source]
# File lib/spec/mocks/message_expectation.rb, line 243 def at_least(n) set_expected_received_count :at_least, n self end
at_most
(n)
[show source]
# File lib/spec/mocks/message_expectation.rb, line 248 def at_most(n) set_expected_received_count :at_most, n self end
exactly
(n)
[show source]
# File lib/spec/mocks/message_expectation.rb, line 238 def exactly(n) set_expected_received_count :exactly, n self end
expected_messages_received?
()
[show source]
# File lib/spec/mocks/message_expectation.rb, line 196 def expected_messages_received? ignoring_args? || matches_exact_count? || matches_at_least_count? || matches_at_most_count? end
generate_error
()
[show source]
# File lib/spec/mocks/message_expectation.rb, line 225 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) end end
ignoring_args?
()
[show source]
# File lib/spec/mocks/message_expectation.rb, line 201 def ignoring_args? @expected_received_count == :any end
matches_at_least_count?
()
[show source]
# File lib/spec/mocks/message_expectation.rb, line 205 def matches_at_least_count? @at_least && @actual_received_count >= @expected_received_count end
matches_at_most_count?
()
[show source]
# File lib/spec/mocks/message_expectation.rb, line 209 def matches_at_most_count? @at_most && @actual_received_count <= @expected_received_count end
matches_exact_count?
()
[show source]
# File lib/spec/mocks/message_expectation.rb, line 213 def matches_exact_count? @expected_received_count == @actual_received_count end
matches_name_but_not_args
(sym, args)
[show source]
# File lib/spec/mocks/message_expectation.rb, line 183 def matches_name_but_not_args(sym, args) @sym == sym and not @args_expectation.args_match?(args) end
negative_expectation_for?
(sym)
[show source]
# File lib/spec/mocks/message_expectation.rb, line 288 def negative_expectation_for?(sym) return false end
never
()
[show source]
# File lib/spec/mocks/message_expectation.rb, line 264 def never @expected_received_count = 0 self end
once
(&block)
[show source]
# File lib/spec/mocks/message_expectation.rb, line 269 def once(&block) @method_block = block if block @expected_received_count = 1 self end
ordered
(&block)
[show source]
# File lib/spec/mocks/message_expectation.rb, line 281 def ordered(&block) @method_block = block if block @order_group.register(self) @ordered = true self end
similar_messages
()
[show source]
# File lib/spec/mocks/message_expectation.rb, line 217 def similar_messages @similar_messages ||= [] end
times
(&block)
[show source]
# File lib/spec/mocks/message_expectation.rb, line 253 def times(&block) @method_block = block if block self end
twice
(&block)
[show source]
# File lib/spec/mocks/message_expectation.rb, line 275 def twice(&block) @method_block = block if block @expected_received_count = 2 self end
verify_messages_received
()
[show source]
# File lib/spec/mocks/message_expectation.rb, line 187 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)
[show source]
# File lib/spec/mocks/message_expectation.rb, line 233 def with(*args, &block) @args_expectation = ArgumentExpectation.new(args, &block) self end
Protected instance methods
clear_actual_received_count!
()
[show source]
# File lib/spec/mocks/message_expectation.rb, line 306 def clear_actual_received_count! @actual_received_count = 0 end
set_expected_received_count
(relativity, n)
[show source]
# File lib/spec/mocks/message_expectation.rb, line 293 def set_expected_received_count(relativity, n) @at_least = (relativity == :at_least) @at_most = (relativity == :at_most) @expected_received_count = case n when Numeric n when :once 1 when :twice 2 end end