class RSpec::Mocks::Matchers::HaveReceived

@private

Constants

ARGS_CONSTRAINTS
CONSTRAINTS
COUNT_CONSTRAINTS

Public Class Methods

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

Public Instance Methods

description() click to toggle source
# File lib/rspec/mocks/matchers/have_received.rb, line 46
def description
  (@expectation ||= expect).description_for("have received")
end
does_not_match?(subject) click to toggle source
# File lib/rspec/mocks/matchers/have_received.rb, line 30
def does_not_match?(subject)
  @subject = subject
  ensure_count_unconstrained
  @expectation = expect.never
  mock_proxy.ensure_implemented(@method_name)
  expected_messages_received_in_order?
end
failure_message() click to toggle source
# File lib/rspec/mocks/matchers/have_received.rb, line 38
def failure_message
  generate_failure_message
end
failure_message_when_negated() click to toggle source
# File lib/rspec/mocks/matchers/have_received.rb, line 42
def failure_message_when_negated
  generate_failure_message
end
matches?(subject, &block) click to toggle source
# File lib/rspec/mocks/matchers/have_received.rb, line 21
def matches?(subject, &block)
  @block ||= block
  @subject = subject
  @expectation = expect
  mock_proxy.ensure_implemented(@method_name)

  expected_messages_received_in_order?
end
name() click to toggle source
# File lib/rspec/mocks/matchers/have_received.rb, line 17
def name
  "have_received"
end
setup_allowance(_subject, &_block) click to toggle source
# File lib/rspec/mocks/matchers/have_received.rb, line 57
def setup_allowance(_subject, &_block)
  disallow("allow", " as it would have no effect")
end
setup_any_instance_allowance(_subject, &_block) click to toggle source
# File lib/rspec/mocks/matchers/have_received.rb, line 61
def setup_any_instance_allowance(_subject, &_block)
  disallow("allow_any_instance_of")
end
setup_any_instance_expectation(_subject, &_block) click to toggle source
# File lib/rspec/mocks/matchers/have_received.rb, line 65
def setup_any_instance_expectation(_subject, &_block)
  disallow("expect_any_instance_of")
end

Private Instance Methods

apply_constraints_to(expectation) click to toggle source
# File lib/rspec/mocks/matchers/have_received.rb, line 83
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 95
def count_constraint
  @constraints.map(&:first).find do |constraint|
    COUNT_CONSTRAINTS.include?(constraint)
  end
end
disallow(type, reason="") click to toggle source
# File lib/rspec/mocks/matchers/have_received.rb, line 71
def disallow(type, reason="")
  raise RSpec::Mocks::MockExpectationError,
        "Using #{type}(...) with the `have_received` "                  "matcher is not supported#{reason}."
end
ensure_count_unconstrained() click to toggle source
# File lib/rspec/mocks/matchers/have_received.rb, line 89
def ensure_count_unconstrained
  return unless count_constraint
  raise RSpec::Mocks::MockExpectationError,
        "can't use #{count_constraint} when negative"
end
expect() click to toggle source
# File lib/rspec/mocks/matchers/have_received.rb, line 77
def expect
  expectation = mock_proxy.build_expectation(@method_name)
  apply_constraints_to expectation
  expectation
end
expected_messages_received_in_order?() click to toggle source
# File lib/rspec/mocks/matchers/have_received.rb, line 108
def expected_messages_received_in_order?
  mock_proxy.replay_received_message_on @expectation, &@block
  @expectation.expected_messages_received? && @expectation.ensure_expected_ordering_received!
end
generate_failure_message() click to toggle source
# File lib/rspec/mocks/matchers/have_received.rb, line 101
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 113
def mock_proxy
  RSpec::Mocks.space.proxy_for(@subject)
end