Class: RSpec::Mocks::ArgumentListMatcher

### Home Classes Methods

### In Files

- lib/rspec/mocks/argument_list_matcher.rb

### Parent

Object

### Methods

- ::new
- #args_match?
- #resolve_expected_args_based_on

### 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::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::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::InsertOntoBacktrace
- 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::NamedObjectReference
- RSpec::Mocks::NestedSpace
- 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::RootSpace
- RSpec::Mocks::SimpleMessageExpectation
- RSpec::Mocks::Space
- RSpec::Mocks::Space::FakeMutex
- RSpec::Mocks::StubChain
- RSpec::Mocks::Syntax
- RSpec::Mocks::TargetBase
- RSpec::Mocks::TestDouble
- RSpec::Mocks::TestDoubleProxy
- RSpec::Mocks::VerifyingDouble
- 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::ArgumentListMatcher

Wrapper for matching arguments against a list of expected values. Used by the `with` method on a `MessageExpectation`:

    expect(object).to receive(:message).with(:a, 'b', 3)
    object.message(:a, 'b', 3)

Values passed to `with` can be literal values or argument matchers that match against the real objects .e.g.

    expect(object).to receive(:message).with(hash_including(:a => 'b'))

Can also be used directly to match the contents of any `Array`. This enables 3rd party mocking libs to take advantage of rspec's argument matching without using the rest of rspec-mocks.

    require 'rspec/mocks/argument_list_matcher'
    include RSpec::Mocks::ArgumentMatchers

    arg_list_matcher = RSpec::Mocks::ArgumentListMatcher.new(123, hash_including(:a => 'b'))
    arg_list_matcher.args_match?(123, :a => 'b')

This class is immutable.

@see ArgumentMatchers

### Constants

MATCH_ALL

  Value that will match all argument lists.

  @private

### Attributes

expected_args[R]

@private

### Public Class Methods

new(*expected_args) click to toggle source

@api public @param [Array] expected_args a list of expected literals and/or argument matchers

Initializes an `ArgumentListMatcher` with a collection of literal values and/or argument matchers.

@see ArgumentMatchers @see args_match?

    # File lib/rspec/mocks/argument_list_matcher.rb, line 45
    def initialize(*expected_args)
      @expected_args = expected_args
      ensure_expected_args_valid!
    end

### Public Instance Methods

args_match?(*args) click to toggle source

@api public @param [Array] args

Matches each element in the `expected_args` against the element in the same position of the arguments passed to `new`.

@see initialize

    # File lib/rspec/mocks/argument_list_matcher.rb, line 57
    def args_match?(*args)
      Support::FuzzyMatcher.values_match?(resolve_expected_args_based_on(args), args)
    end

resolve_expected_args_based_on(actual_args) click to toggle source

@private Resolves abstract arg placeholders like `no_args` and `any_args` into a more concrete arg list based on the provided `actual_args`.

    # File lib/rspec/mocks/argument_list_matcher.rb, line 64
    def resolve_expected_args_based_on(actual_args)
      return [] if [ArgumentMatchers::NoArgsMatcher::INSTANCE] == expected_args

      any_args_index = expected_args.index(ArgumentMatchers::AnyArgsMatcher::INSTANCE)
      return expected_args unless any_args_index

      replace_any_args_with_splat_of_anything(any_args_index, actual_args.count)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.