123456789_123456789_123456789_123456789_123456789_

Class: RSpec::Mocks::VerifyingMessageExpectation Private

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: RSpec::Mocks::MessageExpectation
Defined in: rspec-mocks/lib/rspec/mocks/verifying_message_expectation.rb

Overview

A message expectation that knows about the real implementation of the message being expected, so that it can verify that any expectations have the valid arguments.

Class Method Summary

Instance Attribute Summary

Instance Method Summary

MessageExpectation - Inherited

#and_call_original

Tells the object to delegate to the original unmodified method when it receives the message.

#and_invoke

Tells the object to invoke a Proc when it receives the message.

#and_raise

Tells the object to raise an exception when the message is received.

#and_return

Tells the object to return a value when it receives the message.

#and_throw

Tells the object to throw a symbol (with the object if that form is used) when the message is received.

#and_wrap_original

Decorates the stubbed method with the supplied block.

#and_yield

Tells the object to yield one or more args to a block when the message is received.

#at_least

Constrain a message expectation to be received at least a specific number of times.

#at_most

Constrain a message expectation to be received at most a specific number of times.

#exactly

Constrain a message expectation to be received a specific number of times.

#inspect
#never

Expect a message not to be received at all.

#once

Expect a message to be received exactly one time.

#ordered

Expect messages to be received in a specific order.

#thrice

Expect a message to be received exactly three times.

#time
#times

Syntactic sugar for exactly, at_least and at_most

#to_s,
#twice

Expect a message to be received exactly two times.

#with

Constrains a stub or message expectation to invocations with specific arguments.

MessageExpectation::ImplementationDetails - Included

Instance Attribute Details

#method_reference (rw)

A level of indirection is used here rather than just passing in the method itself, since method look up is expensive and we only want to do it if actually needed.

Conceptually the method reference makes more sense as a constructor argument since it should be immutable, but it is significantly more straight forward to build the object in pieces so for now it stays as an accessor.

[ GitHub ]

  
# File 'rspec-mocks/lib/rspec/mocks/verifying_message_expectation.rb', line 18

attr_accessor :method_reference

Instance Method Details

#validate_expected_arguments! (private)

[ GitHub ]

  
# File 'rspec-mocks/lib/rspec/mocks/verifying_message_expectation.rb', line 38

def validate_expected_arguments!
  return if method_reference.nil?

  method_reference.with_signature do |signature|
    args     = yield signature
    verifier = Support::LooseSignatureVerifier.new(signature, args)

    unless verifier.valid?
      # Fail fast is required, otherwise the message expectation will fail
      # as well ("expected method not called") and clobber this one.
      @failed_fast = true
      @error_generator.raise_invalid_arguments_error(verifier)
    end
  end
end

#with(*args, &block)

[ GitHub ]

  
# File 'rspec-mocks/lib/rspec/mocks/verifying_message_expectation.rb', line 25

def with(*args, &block)
  super(*args, &block).tap do
    validate_expected_arguments! do |signature|
      example_call_site_args = [:an_arg] * signature.min_non_kw_args
      example_call_site_args << :kw_args_hash if signature.required_kw_args.any?
      @argument_list_matcher.resolve_expected_args_based_on(example_call_site_args)
    end
  end
end