Class: Mocha::ParameterMatchers::Base

### Home Classes Methods

### In Files

- lib/mocha/parameter_matchers/base.rb

### Parent

Object

### Methods

- #&
- #to_matcher
- #|

### Class/Module Index

Quicksearch

- Mocha
- Mocha::API
- Mocha::AnyInstanceMethod
- Mocha::AnyInstanceReceiver
- Mocha::ArgumentIterator
- Mocha::ArrayMethods
- Mocha::BacktraceFilter
- Mocha::Cardinality
- Mocha::Central
- Mocha::ChangeStateSideEffect
- Mocha::ClassMethod
- Mocha::ClassMethods
- Mocha::ClassMethods::AnyInstance
- Mocha::Configuration
- Mocha::DateMethods
- Mocha::Debug
- Mocha::DefaultName
- Mocha::DefaultReceiver
- Mocha::Deprecation
- Mocha::Detection
- Mocha::Detection::MiniTest
- Mocha::Detection::TestUnit
- Mocha::ExceptionRaiser
- Mocha::Expectation
- Mocha::ExpectationError
- Mocha::ExpectationErrorFactory
- Mocha::ExpectationList
- Mocha::HashMethods
- Mocha::Hooks
- Mocha::ImpersonatingAnyInstanceName
- Mocha::ImpersonatingName
- Mocha::InStateOrderingConstraint
- Mocha::InstanceMethod
- Mocha::Integration
- Mocha::Integration::AssertionCounter
- Mocha::Integration::MiniTest
- Mocha::Integration::MiniTest::Adapter
- Mocha::Integration::MiniTest::Nothing
- Mocha::Integration::MiniTest::Version13
- Mocha::Integration::MiniTest::Version13::RunMethodPatch
- Mocha::Integration::MiniTest::Version140
- Mocha::Integration::MiniTest::Version140::RunMethodPatch
- Mocha::Integration::MiniTest::Version141
- Mocha::Integration::MiniTest::Version141::RunMethodPatch
- Mocha::Integration::MiniTest::Version142To172
- Mocha::Integration::MiniTest::Version142To172::RunMethodPatch
- Mocha::Integration::MiniTest::Version200
- Mocha::Integration::MiniTest::Version200::RunMethodPatch
- Mocha::Integration::MiniTest::Version201To222
- Mocha::Integration::MiniTest::Version201To222::RunMethodPatch
- Mocha::Integration::MiniTest::Version2110To2111
- Mocha::Integration::MiniTest::Version2110To2111::RunMethodPatch
- Mocha::Integration::MiniTest::Version2112To320
- Mocha::Integration::MiniTest::Version2112To320::RunMethodPatch
- Mocha::Integration::MiniTest::Version230To2101
- Mocha::Integration::MiniTest::Version230To2101::RunMethodPatch
- Mocha::Integration::MonkeyPatcher
- Mocha::Integration::TestUnit
- Mocha::Integration::TestUnit::Adapter
- Mocha::Integration::TestUnit::GemVersion200
- Mocha::Integration::TestUnit::GemVersion200::RunMethodPatch
- Mocha::Integration::TestUnit::GemVersion201To202
- Mocha::Integration::TestUnit::GemVersion201To202::RunMethodPatch
- Mocha::Integration::TestUnit::GemVersion203To220
- Mocha::Integration::TestUnit::GemVersion203To220::RunMethodPatch
- Mocha::Integration::TestUnit::GemVersion230To250
- Mocha::Integration::TestUnit::GemVersion230To250::RunMethodPatch
- Mocha::Integration::TestUnit::Nothing
- Mocha::Integration::TestUnit::RubyVersion185AndBelow
- Mocha::Integration::TestUnit::RubyVersion185AndBelow::RunMethodPatch
- Mocha::Integration::TestUnit::RubyVersion186AndAbove
- Mocha::Integration::TestUnit::RubyVersion186AndAbove::RunMethodPatch
- Mocha::Logger
- Mocha::MethodMatcher
- Mocha::Mock
- Mocha::Mockery
- Mocha::ModuleMethod
- Mocha::ModuleMethods
- Mocha::MultipleYields
- Mocha::Name
- Mocha::NoYields
- Mocha::ObjectMethods
- Mocha::ObjectReceiver
- Mocha::ParameterMatchers
- Mocha::ParameterMatchers::AllOf
- Mocha::ParameterMatchers::AnyOf
- Mocha::ParameterMatchers::AnyParameters
- Mocha::ParameterMatchers::Anything
- Mocha::ParameterMatchers::Base
- Mocha::ParameterMatchers::Equals
- Mocha::ParameterMatchers::HasEntries
- Mocha::ParameterMatchers::HasEntry
- Mocha::ParameterMatchers::HasKey
- Mocha::ParameterMatchers::HasValue
- Mocha::ParameterMatchers::Includes
- Mocha::ParameterMatchers::InstanceOf
- Mocha::ParameterMatchers::IsA
- Mocha::ParameterMatchers::KindOf
- Mocha::ParameterMatchers::Not
- Mocha::ParameterMatchers::Optionally
- Mocha::ParameterMatchers::QueryStringMatches
- Mocha::ParameterMatchers::RegexpMatches
- Mocha::ParameterMatchers::RespondsWith
- Mocha::ParameterMatchers::YamlEquivalent
- Mocha::ParametersMatcher
- Mocha::PrettyParameters
- Mocha::ReturnValues
- Mocha::Sequence
- Mocha::Sequence::InSequenceOrderingConstraint
- Mocha::SingleReturnValue
- Mocha::SingleYield
- Mocha::StateMachine
- Mocha::StateMachine::State
- Mocha::StateMachine::StatePredicate
- Mocha::StringMethods
- Mocha::StubbingError
- Mocha::Thrower
- Mocha::TimeMethods
- Mocha::UnexpectedInvocation
- Mocha::YieldParameters
- Array
- Date
- Hash
- Object
- String
- Time

No matching classes.

# Mocha::ParameterMatchers::Base

@abstract Subclass and implement `#matches?` and `#mocha_inspect` to define a custom matcher. Also add a suitably named instance method to {ParameterMatchers} to build an instance of the new matcher c.f. {equals}.

### Public Instance Methods

&(matcher) click to toggle source

A shorthand way of combining two matchers when both must match.

Returns a new {AllOf} parameter matcher combining two matchers using a logical AND.

This shorthand will not work with an implicit equals match. Instead, an explicit {Equals} matcher should be used.

@param [Base] matcher parameter matcher. @return [AllOf] parameter matcher.

@see Expectation#with

@example Alternative ways to combine matchers with a logical AND.

    object = mock()
    object.expects(:run).with(all_of(has_key(:foo), has_key(:bar)))
    object.run(:foo => 'foovalue', :bar => 'barvalue')

    # is exactly equivalent to

    object.expects(:run).with(has_key(:foo) & has_key(:bar))
    object.run(:foo => 'foovalue', :bar => 'barvalue)

    # File lib/mocha/parameter_matchers/base.rb, line 33
    def &(matcher)
      AllOf.new(self, matcher)
    end

to_matcher() click to toggle source

@private

    # File lib/mocha/parameter_matchers/base.rb, line 9
    def to_matcher
      self
    end

|(matcher) click to toggle source

A shorthand way of combining two matchers when at least one must match.

Returns a new `AnyOf` parameter matcher combining two matchers using a logical OR.

This shorthand will not work with an implicit equals match. Instead, an explicit {Equals} matcher should be used.

@param [Base] matcher parameter matcher. @return [AnyOf] parameter matcher.

@see Expectation#with

@example Alternative ways to combine matchers with a logical OR.

    object = mock()
    object.expects(:run).with(any_of(has_key(:foo), has_key(:bar)))
    object.run(:foo => 'foovalue')

    # is exactly equivalent to

    object.expects(:run).with(has_key(:foo) | has_key(:bar))
    object.run(:foo => 'foovalue')

@example Using an explicit {Equals} matcher in combination with {#|}.

    object.expects(:run).with(equals(1) | equals(2))
    object.run(1) # passes
    object.run(2) # passes
    object.run(3) # fails

    # File lib/mocha/parameter_matchers/base.rb, line 63
    def |(matcher)
      AnyOf.new(self, matcher)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.