class RSpec::Mocks::Matchers::HaveReceived

def apply_constraints_to(expectation)

def apply_constraints_to(expectation)
  @constraints.each do |constraint|
    expectation.send(*constraint)
  end
end

def count_constraint

def count_constraint
  @constraints.map(&:first).detect do |constraint|
    COUNT_CONSTRAINTS.include?(constraint)
  end
end

def description

def description
  expect.description
end

def does_not_match?(subject)

def does_not_match?(subject)
  @subject = subject
  ensure_count_unconstrained
  @expectation = expect.never
  expected_messages_received_in_order?
end

def ensure_count_unconstrained

def ensure_count_unconstrained
  if count_constraint
    raise RSpec::Mocks::MockExpectationError,
      "can't use #{count_constraint} when negative"
  end
end

def expect

def expect
  expectation = mock_proxy.build_expectation(@method_name)
  apply_constraints_to expectation
  expectation
end

def expected_messages_received_in_order?

def expected_messages_received_in_order?
  mock_proxy.replay_received_message_on @expectation, &@block
  @expectation.expected_messages_received? && @expectation.ensure_expected_ordering_received!
end

def failure_message

def failure_message
  generate_failure_message
end

def generate_failure_message

def generate_failure_message
  mock_proxy.check_for_unexpected_arguments(@expectation)
  @expectation.generate_error
rescue RSpec::Mocks::MockExpectationError => error
  error.message
end

def initialize(method_name, &block)

def initialize(method_name, &block)
  @method_name = method_name
  @block = block
  @constraints = []
  @subject = nil
end

def matches?(subject, &block)

def matches?(subject, &block)
  @block ||= block
  @subject = subject
  @expectation = expect
  expected_messages_received_in_order?
end

def mock_proxy

def mock_proxy
  RSpec::Mocks.proxy_for(@subject)
end

def name

def name
  "have_received"
end

def negative_failure_message

def negative_failure_message
  generate_failure_message
end