class RSpec::Mocks::MessageExpectation

def advise(args, block)

def advise(args, block)
  similar_messages << args
end

def any_number_of_times(&block)

def any_number_of_times(&block)
  @method_block = block if block
  @expected_received_count = :any
  self
end

def at_least(n)

def at_least(n)
  set_expected_received_count :at_least, n
  self
end

def at_most(n)

def at_most(n)
  set_expected_received_count :at_most, n
  self
end

def clear_actual_received_count!

def clear_actual_received_count!
  @actual_received_count = 0
end

def exactly(n)

def exactly(n)
  set_expected_received_count :exactly, n
  self
end

def expected_messages_received?

def expected_messages_received?
  ignoring_args? || matches_exact_count? ||
     matches_at_least_count? || matches_at_most_count?
end

def generate_error

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

def ignoring_args?

def ignoring_args?
  @expected_received_count == :any
end

def matches_at_least_count?

def matches_at_least_count?
  @at_least && @actual_received_count >= @expected_received_count
end

def matches_at_most_count?

def matches_at_most_count?
  @at_most && @actual_received_count <= @expected_received_count
end

def matches_exact_count?

def matches_exact_count?
  @expected_received_count == @actual_received_count
end

def matches_name_but_not_args(sym, args)

def matches_name_but_not_args(sym, args)
  @sym == sym and not @args_expectation.args_match?(args)
end

def negative_expectation_for?(sym)

def negative_expectation_for?(sym)
  return false
end

def never

def never
  @expected_received_count = 0
  self
end

def once(&block)

def once(&block)
  @method_block = block if block
  @expected_received_count = 1
  self
end

def ordered(&block)

def ordered(&block)
  @method_block = block if block
  @order_group.register(self)
  @ordered = true
  self
end

def set_expected_received_count(relativity, n)

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

def similar_messages

def similar_messages
  @similar_messages ||= []
end

def times(&block)

def times(&block)
  @method_block = block if block
  self
end

def twice(&block)

def twice(&block)
  @method_block = block if block
  @expected_received_count = 2
  self
end

def verify_messages_received

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

def with(*args, &block)

def with(*args, &block)
  @return_block = block if block_given?
  @args_expectation = ArgumentExpectation.new(args, &block)
  self
end