Module: RSpec::Mocks::MessageExpectation::ImplementationDetails

### Home Classes Methods

### In Files

- lib/rspec/mocks/message_expectation.rb

### Methods

- ::new
- #actual_received_count_matters?
- #additional_expected_calls
- #advise
- #and_yield_receiver_to_implementation
- #called_max_times?
- #description_for
- #ensure_expected_ordering_received!
- #expectation_count_type
- #expected_args
- #expected_messages_received?
- #generate_error
- #ignoring_args?
- #increase_actual_received_count!
- #invoke
- #invoke_without_incrementing_received_count
- #matches?
- #matches_at_least_count?
- #matches_at_most_count?
- #matches_exact_count?
- #matches_name_but_not_args
- #negative?
- #negative_expectation_for?
- #ordered?
- #raise_out_of_order_error
- #raise_unexpected_message_args_error
- #safe_invoke
- #similar_messages
- #unadvise
- #verify_messages_received
- #yield_receiver_to_implementation_block?

### Class/Module Index

Quicksearch

- RSpec
- RSpec::Mocks
- RSpec::Mocks::AllowanceTarget
- RSpec::Mocks::AndReturnImplementation
- RSpec::Mocks::AndWrapOriginalImplementation
- RSpec::Mocks::AndYieldImplementation
- RSpec::Mocks::AnyInstance
- RSpec::Mocks::AnyInstance::Chain
- RSpec::Mocks::AnyInstance::Chain::Customizations
- RSpec::Mocks::AnyInstance::ErrorGenerator
- RSpec::Mocks::AnyInstance::ExpectChainChain
- RSpec::Mocks::AnyInstance::ExpectationChain
- RSpec::Mocks::AnyInstance::FluentInterfaceProxy
- RSpec::Mocks::AnyInstance::MessageChains
- RSpec::Mocks::AnyInstance::PositiveExpectationChain
- RSpec::Mocks::AnyInstance::Proxy
- RSpec::Mocks::AnyInstance::Recorder
- RSpec::Mocks::AnyInstance::StubChain
- RSpec::Mocks::AnyInstance::StubChainChain
- RSpec::Mocks::AnyInstanceAllowanceTarget
- RSpec::Mocks::AnyInstanceExpectationTarget
- RSpec::Mocks::ArgumentListMatcher
- RSpec::Mocks::ArgumentMatchers
- RSpec::Mocks::ArgumentMatchers::AnyArgMatcher
- RSpec::Mocks::ArgumentMatchers::AnyArgsMatcher
- RSpec::Mocks::ArgumentMatchers::ArrayIncludingMatcher
- RSpec::Mocks::ArgumentMatchers::BaseHashMatcher
- RSpec::Mocks::ArgumentMatchers::BooleanMatcher
- RSpec::Mocks::ArgumentMatchers::DuckTypeMatcher
- RSpec::Mocks::ArgumentMatchers::HashExcludingMatcher
- RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher
- RSpec::Mocks::ArgumentMatchers::InstanceOf
- RSpec::Mocks::ArgumentMatchers::KindOf
- RSpec::Mocks::ArgumentMatchers::NoArgsMatcher
- RSpec::Mocks::ArgumentMatchers::SingletonMatcher
- RSpec::Mocks::CallbackInvocationStrategy
- RSpec::Mocks::ClassNewMethodReference
- RSpec::Mocks::ClassVerifyingDouble
- RSpec::Mocks::Configuration
- RSpec::Mocks::Constant
- RSpec::Mocks::ConstantMutator
- RSpec::Mocks::ConstantMutator::BaseMutator
- RSpec::Mocks::ConstantMutator::ConstantHider
- RSpec::Mocks::ConstantMutator::DefinedConstantReplacer
- RSpec::Mocks::ConstantMutator::UndefinedConstantSetter
- RSpec::Mocks::DirectObjectReference
- RSpec::Mocks::Double
- RSpec::Mocks::ErrorGenerator
- RSpec::Mocks::ExampleMethods
- RSpec::Mocks::ExampleMethods::ExpectHost
- RSpec::Mocks::ExpectChain
- RSpec::Mocks::ExpectationTarget
- RSpec::Mocks::Implementation
- RSpec::Mocks::InstanceMethodReference
- RSpec::Mocks::InstanceMethodStasher
- RSpec::Mocks::InstanceVerifyingDouble
- RSpec::Mocks::MarshalExtension
- RSpec::Mocks::Matchers
- RSpec::Mocks::Matchers::ExpectationCustomization
- RSpec::Mocks::Matchers::HaveReceived
- RSpec::Mocks::Matchers::Receive
- RSpec::Mocks::Matchers::Receive::DefaultDescribable
- RSpec::Mocks::Matchers::ReceiveMessageChain
- RSpec::Mocks::Matchers::ReceiveMessages
- RSpec::Mocks::MessageChain
- RSpec::Mocks::MessageExpectation
- RSpec::Mocks::MessageExpectation::ImplementationDetails
- RSpec::Mocks::MethodDouble
- RSpec::Mocks::MethodReference
- RSpec::Mocks::Mutex
- RSpec::Mocks::NamedObjectReference
- RSpec::Mocks::NestedSpace
- RSpec::Mocks::NoCallbackInvocationStrategy
- RSpec::Mocks::ObjectMethodReference
- RSpec::Mocks::ObjectReference
- RSpec::Mocks::ObjectVerifyingDouble
- RSpec::Mocks::ObjectVerifyingDoubleMethods
- RSpec::Mocks::OrderGroup
- RSpec::Mocks::PartialClassDoubleProxy
- RSpec::Mocks::PartialClassDoubleProxyMethods
- RSpec::Mocks::PartialDoubleProxy
- RSpec::Mocks::Proxy
- RSpec::Mocks::ProxyForNil
- RSpec::Mocks::ReentrantMutex
- RSpec::Mocks::RootSpace
- RSpec::Mocks::SimpleMessageExpectation
- RSpec::Mocks::Space
- RSpec::Mocks::StubChain
- RSpec::Mocks::Syntax
- RSpec::Mocks::TargetBase
- RSpec::Mocks::TestDouble
- RSpec::Mocks::TestDoubleFormatter
- RSpec::Mocks::TestDoubleProxy
- RSpec::Mocks::VerifyingDouble
- RSpec::Mocks::VerifyingDouble::SilentIO
- RSpec::Mocks::VerifyingExistingClassNewMethodDouble
- RSpec::Mocks::VerifyingExistingMethodDouble
- RSpec::Mocks::VerifyingMessageExpectation
- RSpec::Mocks::VerifyingMethodDouble
- RSpec::Mocks::VerifyingPartialClassDoubleProxy
- RSpec::Mocks::VerifyingPartialDoubleProxy
- RSpec::Mocks::VerifyingProxy
- RSpec::Mocks::VerifyingProxyMethods
- RSpec::Mocks::Version
- BasicObject
- Class

No matching classes.

# RSpec::Mocks::MessageExpectation::ImplementationDetails

@private Contains the parts of `MessageExpecation` that aren't part of rspec-mocks' public API. The class is very big and could really use some collaborators it delegates to for this stuff but for now this was the simplest way to split the public from private stuff to make it easier to publish the docs for the APIs we want published.

### Attributes

argument_list_matcher[W]
error_generator[RW]
expected_from[W]
expected_received_count[W]
implementation[RW]
message[R]
orig_object[R]

### Public Class Methods

new(error_generator, expectation_ordering, expected_from, method_double, type=:expectation, opts={}, &implementation_block) click to toggle source

rubocop:disable Style/ParameterLists

    # File lib/rspec/mocks/message_expectation.rb, line 361
    def initialize(error_generator, expectation_ordering, expected_from, method_double,
                   type=:expectation, opts={}, &implementation_block)
      @error_generator = error_generator
      @error_generator.opts = opts
      @expected_from = expected_from
      @method_double = method_double
      @orig_object = @method_double.object
      @message = @method_double.method_name
      @actual_received_count = 0
      @expected_received_count = type == :expectation ? 1 : :any
      @argument_list_matcher = ArgumentListMatcher::MATCH_ALL
      @order_group = expectation_ordering
      @order_group.register(self) unless type == :stub
      @expectation_type = type
      @ordered = false
      @at_least = @at_most = @exactly = nil

      # Initialized to nil so that we don't allocate an array for every
      # mock or stub. See also comment in `and_yield`.
      @args_to_yield = nil
      @eval_context = nil
      @yield_receiver_to_implementation_block = false

      @implementation = Implementation.new
      self.inner_implementation_action = implementation_block
    end

### Public Instance Methods

actual_received_count_matters?() click to toggle source

    # File lib/rspec/mocks/message_expectation.rb, line 523
    def actual_received_count_matters?
      @at_least || @at_most || @exactly
    end

additional_expected_calls() click to toggle source

    # File lib/rspec/mocks/message_expectation.rb, line 510
    def additional_expected_calls
      return 0 if @expectation_type == :stub || !@exactly
      @expected_received_count - 1
    end

advise(*args) click to toggle source

    # File lib/rspec/mocks/message_expectation.rb, line 467
    def advise(*args)
      similar_messages << args
    end

and_yield_receiver_to_implementation() click to toggle source

    # File lib/rspec/mocks/message_expectation.rb, line 393
    def and_yield_receiver_to_implementation
      @yield_receiver_to_implementation_block = true
      self
    end

called_max_times?() click to toggle source

    # File lib/rspec/mocks/message_expectation.rb, line 422
    def called_max_times?
      @expected_received_count != :any &&
        !@at_least &&
        @expected_received_count > 0 &&
        @actual_received_count >= @expected_received_count
    end

description_for(verb) click to toggle source

    # File lib/rspec/mocks/message_expectation.rb, line 499
    def description_for(verb)
      @error_generator.describe_expectation(
        verb, @message, @expected_received_count,
        @actual_received_count, expected_args
      )
    end

ensure_expected_ordering_received!() click to toggle source

    # File lib/rspec/mocks/message_expectation.rb, line 442
    def ensure_expected_ordering_received!
      @order_group.verify_invocation_order(self) if @ordered
      true
    end

expectation_count_type() click to toggle source

    # File lib/rspec/mocks/message_expectation.rb, line 493
    def expectation_count_type
      return :at_least if @at_least
      return :at_most if @at_most
      nil
    end

expected_args() click to toggle source

rubocop:enable Style/ParameterLists

    # File lib/rspec/mocks/message_expectation.rb, line 389
    def expected_args
      @argument_list_matcher.expected_args
    end

expected_messages_received?() click to toggle source

    # File lib/rspec/mocks/message_expectation.rb, line 438
    def expected_messages_received?
      ignoring_args? || matches_exact_count? || matches_at_least_count? || matches_at_most_count?
    end

generate_error() click to toggle source

    # File lib/rspec/mocks/message_expectation.rb, line 475
    def generate_error
      if similar_messages.empty?
        @error_generator.raise_expectation_error(
          @message, @expected_received_count, @argument_list_matcher,
          @actual_received_count, expectation_count_type, expected_args,
          @expected_from, exception_source_id
        )
      else
        @error_generator.raise_similar_message_args_error(
          self, @similar_messages, @expected_from
        )
      end
    end

ignoring_args?() click to toggle source

    # File lib/rspec/mocks/message_expectation.rb, line 447
    def ignoring_args?
      @expected_received_count == :any
    end

increase_actual_received_count!() click to toggle source

    # File lib/rspec/mocks/message_expectation.rb, line 527
    def increase_actual_received_count!
      @actual_received_count += 1
    end

invoke(parent_stub, *args, &block) click to toggle source

    # File lib/rspec/mocks/message_expectation.rb, line 410
    def invoke(parent_stub, *args, &block)
      invoke_incrementing_actual_calls_by(1, true, parent_stub, *args, &block)
    end

invoke_without_incrementing_received_count(parent_stub, *args, &block) click to toggle source

    # File lib/rspec/mocks/message_expectation.rb, line 414
    def invoke_without_incrementing_received_count(parent_stub, *args, &block)
      invoke_incrementing_actual_calls_by(0, true, parent_stub, *args, &block)
    end

matches?(message, *args) click to toggle source

    # File lib/rspec/mocks/message_expectation.rb, line 402
    def matches?(message, *args)
      @message == message && @argument_list_matcher.args_match?(*args)
    end

matches_at_least_count?() click to toggle source

    # File lib/rspec/mocks/message_expectation.rb, line 451
    def matches_at_least_count?
      @at_least && @actual_received_count >= @expected_received_count
    end

matches_at_most_count?() click to toggle source

    # File lib/rspec/mocks/message_expectation.rb, line 455
    def matches_at_most_count?
      @at_most && @actual_received_count <= @expected_received_count
    end

matches_exact_count?() click to toggle source

    # File lib/rspec/mocks/message_expectation.rb, line 459
    def matches_exact_count?
      @expected_received_count == @actual_received_count
    end

matches_name_but_not_args(message, *args) click to toggle source

    # File lib/rspec/mocks/message_expectation.rb, line 429
    def matches_name_but_not_args(message, *args)
      @message == message && !@argument_list_matcher.args_match?(*args)
    end

negative?() click to toggle source

    # File lib/rspec/mocks/message_expectation.rb, line 418
    def negative?
      @expected_received_count == 0 && !@at_least
    end

negative_expectation_for?(message) click to toggle source

    # File lib/rspec/mocks/message_expectation.rb, line 519
    def negative_expectation_for?(message)
      @message == message && negative?
    end

ordered?() click to toggle source

    # File lib/rspec/mocks/message_expectation.rb, line 515
    def ordered?
      @ordered
    end

raise_out_of_order_error() click to toggle source

    # File lib/rspec/mocks/message_expectation.rb, line 506
    def raise_out_of_order_error
      @error_generator.raise_out_of_order_error @message
    end

raise_unexpected_message_args_error(args_for_multiple_calls) click to toggle source

    # File lib/rspec/mocks/message_expectation.rb, line 489
    def raise_unexpected_message_args_error(args_for_multiple_calls)
      @error_generator.raise_unexpected_message_args_error(self, args_for_multiple_calls, exception_source_id)
    end

safe_invoke(parent_stub, *args, &block) click to toggle source

    # File lib/rspec/mocks/message_expectation.rb, line 406
    def safe_invoke(parent_stub, *args, &block)
      invoke_incrementing_actual_calls_by(1, false, parent_stub, *args, &block)
    end

similar_messages() click to toggle source

    # File lib/rspec/mocks/message_expectation.rb, line 463
    def similar_messages
      @similar_messages ||= []
    end

unadvise(args) click to toggle source

    # File lib/rspec/mocks/message_expectation.rb, line 471
    def unadvise(args)
      similar_messages.delete_if { |message| args.include?(message) }
    end

verify_messages_received() click to toggle source

    # File lib/rspec/mocks/message_expectation.rb, line 433
    def verify_messages_received
      return if expected_messages_received?
      generate_error
    end

yield_receiver_to_implementation_block?() click to toggle source

    # File lib/rspec/mocks/message_expectation.rb, line 398
    def yield_receiver_to_implementation_block?
      @yield_receiver_to_implementation_block
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.