class RSpec::Mocks::Matchers::HaveReceived

Constants

ARGS_CONSTRAINTS
CONSTRAINTS
COUNT_CONSTRAINTS

Public Class Methods

new(method_name) click to toggle source
# File lib/rspec/mocks/matchers/have_received.rb, line 9
def initialize(method_name)
  @method_name = method_name
  @constraints = []
  @subject = nil
end

Public Instance Methods

description() click to toggle source
# File lib/rspec/mocks/matchers/have_received.rb, line 36
def description
  expect.description
end
does_not_match?(subject) click to toggle source
# File lib/rspec/mocks/matchers/have_received.rb, line 21
def does_not_match?(subject)
  @subject = subject
  ensure_count_unconstrained
  @expectation = expect.never
  expected_messages_received?
end
failure_message() click to toggle source
# File lib/rspec/mocks/matchers/have_received.rb, line 28
def failure_message
  generate_failure_message
end
matches?(subject) click to toggle source
# File lib/rspec/mocks/matchers/have_received.rb, line 15
def matches?(subject)
  @subject = subject
  @expectation = expect
  expected_messages_received?
end
negative_failure_message() click to toggle source
# File lib/rspec/mocks/matchers/have_received.rb, line 32
def negative_failure_message
  generate_failure_message
end

Private Instance Methods

apply_constraints_to(expectation) click to toggle source
# File lib/rspec/mocks/matchers/have_received.rb, line 55
def apply_constraints_to(expectation)
  @constraints.each do |constraint|
    expectation.send(*constraint)
  end
end
count_constraint() click to toggle source
# File lib/rspec/mocks/matchers/have_received.rb, line 68
def count_constraint
  @constraints.map(&:first).detect do |constraint|
    COUNT_CONSTRAINTS.include?(constraint)
  end
end
ensure_count_unconstrained() click to toggle source
# File lib/rspec/mocks/matchers/have_received.rb, line 61
def ensure_count_unconstrained
  if count_constraint
    raise RSpec::Mocks::MockExpectationError,
      "can't use #{count_constraint} when negative"
  end
end
expect() click to toggle source
# File lib/rspec/mocks/matchers/have_received.rb, line 49
def expect
  expectation = mock_proxy.build_expectation(@method_name)
  apply_constraints_to expectation
  expectation
end
expected_messages_received?() click to toggle source
# File lib/rspec/mocks/matchers/have_received.rb, line 81
def expected_messages_received?
  mock_proxy.replay_received_message_on @expectation
  @expectation.expected_messages_received?
end
generate_failure_message() click to toggle source
# File lib/rspec/mocks/matchers/have_received.rb, line 74
def generate_failure_message
  mock_proxy.check_for_unexpected_arguments(@expectation)
  @expectation.generate_error
rescue RSpec::Mocks::MockExpectationError => error
  error.message
end
mock_proxy() click to toggle source
# File lib/rspec/mocks/matchers/have_received.rb, line 86
def mock_proxy
  RSpec::Mocks.proxy_for(@subject)
end