Module: RSpec::Mocks::ArgumentMatchers

### Home Classes Methods

### In Files

- lib/rspec/mocks/argument_matchers.rb

### Namespace

- CLASS RSpec::Mocks::ArgumentMatchers::AnyArgMatcher
- CLASS RSpec::Mocks::ArgumentMatchers::AnyArgsMatcher
- CLASS RSpec::Mocks::ArgumentMatchers::ArrayIncludingMatcher
- CLASS RSpec::Mocks::ArgumentMatchers::BaseHashMatcher
- CLASS RSpec::Mocks::ArgumentMatchers::BooleanMatcher
- CLASS RSpec::Mocks::ArgumentMatchers::DuckTypeMatcher
- CLASS RSpec::Mocks::ArgumentMatchers::HashExcludingMatcher
- CLASS RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher
- CLASS RSpec::Mocks::ArgumentMatchers::InstanceOf
- CLASS RSpec::Mocks::ArgumentMatchers::KindOf
- CLASS RSpec::Mocks::ArgumentMatchers::NoArgsMatcher
- CLASS RSpec::Mocks::ArgumentMatchers::SingletonMatcher

### Methods

- ::anythingize_lonely_keys
- #a_kind_of
- #an_instance_of
- #any_args
- #anything
- #array_including
- #boolean
- #duck_type
- #hash_excluding
- #hash_including
- #hash_not_including
- #instance_of
- #kind_of
- #no_args

### 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::ArgumentMatchers

ArgumentMatchers are placeholders that you can include in message expectations to match arguments against a broader check than simple equality.

With the exception of `any_args` and `no_args`, they all match against the arg in same position in the argument list.

@see ArgumentListMatcher

### Public Class Methods

anythingize_lonely_keys(*args) click to toggle source

@private

    # File lib/rspec/mocks/argument_matchers.rb, line 118
    def self.anythingize_lonely_keys(*args)
      hash = args.last.class == Hash ? args.delete_at(-1) : {}
      args.each { | arg | hash[arg] = AnyArgMatcher::INSTANCE }
      hash
    end

### Public Instance Methods

a_kind_of(klass) click to toggle source
Alias for: kind_of
an_instance_of(klass) click to toggle source
Alias for: instance_of
any_args() click to toggle source

Acts like an arg splat, matching any number of args at any point in an arg list.

@example

    expect(object).to receive(:message).with(1, 2, any_args)

    # matches any of these:
    object.message(1, 2)
    object.message(1, 2, 3)
    object.message(1, 2, 3, 4)

    # File lib/rspec/mocks/argument_matchers.rb, line 26
    def any_args
      AnyArgsMatcher::INSTANCE
    end

anything() click to toggle source

Matches any argument at all.

@example

    expect(object).to receive(:message).with(anything)

    # File lib/rspec/mocks/argument_matchers.rb, line 34
    def anything
      AnyArgMatcher::INSTANCE
    end

array_including(*args) click to toggle source

Matches an array that includes the specified items at least once. Ignores duplicates and additional values

@example

    expect(object).to receive(:message).with(array_including(1,2,3))
    expect(object).to receive(:message).with(array_including([1,2,3]))

    # File lib/rspec/mocks/argument_matchers.rb, line 80
    def array_including(*args)
      actually_an_array = Array === args.first && args.count == 1 ? args.first : args
      ArrayIncludingMatcher.new(actually_an_array)
    end

boolean() click to toggle source

Matches a boolean value.

@example

    expect(object).to receive(:message).with(boolean())

    # File lib/rspec/mocks/argument_matchers.rb, line 59
    def boolean
      BooleanMatcher::INSTANCE
    end

duck_type(*args) click to toggle source

Matches if the actual argument responds to the specified messages.

@example

    expect(object).to receive(:message).with(duck_type(:hello))
    expect(object).to receive(:message).with(duck_type(:hello, :goodbye))

    # File lib/rspec/mocks/argument_matchers.rb, line 51
    def duck_type(*args)
      DuckTypeMatcher.new(*args)
    end

hash_excluding(*args) click to toggle source

Matches a hash that doesn't include the specified key(s) or key/value.

@example

    expect(object).to receive(:message).with(hash_excluding(:key => val))
    expect(object).to receive(:message).with(hash_excluding(:key))
    expect(object).to receive(:message).with(hash_excluding(:key, :key2 => :val2))

    # File lib/rspec/mocks/argument_matchers.rb, line 91
    def hash_excluding(*args)
      HashExcludingMatcher.new(ArgumentMatchers.anythingize_lonely_keys(*args))
    end

Also aliased as: hash_not_including
hash_including(*args) click to toggle source

Matches a hash that includes the specified key(s) or key/value pairs. Ignores any additional keys.

@example

    expect(object).to receive(:message).with(hash_including(:key => val))
    expect(object).to receive(:message).with(hash_including(:key))
    expect(object).to receive(:message).with(hash_including(:key, :key2 => val2))

    # File lib/rspec/mocks/argument_matchers.rb, line 70
    def hash_including(*args)
      HashIncludingMatcher.new(ArgumentMatchers.anythingize_lonely_keys(*args))
    end

hash_not_including(*args) click to toggle source
Alias for: hash_excluding
instance_of(klass) click to toggle source

Matches if `arg.instance_of?(klass)`

@example

    expect(object).to receive(:message).with(instance_of(Thing))

    # File lib/rspec/mocks/argument_matchers.rb, line 101
    def instance_of(klass)
      InstanceOf.new(klass)
    end

Also aliased as: an_instance_of
kind_of(klass) click to toggle source

Matches if `arg.kind_of?(klass)`

@example

    expect(object).to receive(:message).with(kind_of(Thing))

    # File lib/rspec/mocks/argument_matchers.rb, line 111
    def kind_of(klass)
      KindOf.new(klass)
    end

Also aliased as: a_kind_of
no_args() click to toggle source

Matches no arguments.

@example

    expect(object).to receive(:message).with(no_args)

    # File lib/rspec/mocks/argument_matchers.rb, line 42
    def no_args
      NoArgsMatcher::INSTANCE
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.