Class: Mocha::ParameterMatchers::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/mocha/parameter_matchers/base.rb

Instance Method Summary collapse

Instance Method Details

#&(matcher) ⇒ Object

:call-seq: &(matcher) -> parameter_matcher

A short hand way of specifying multiple matchers that should all match.

Returns a new AllOf parameter matcher combining the given matcher and the receiver.

The following statements are equivalent:

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

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


27
28
29
# File 'lib/mocha/parameter_matchers/base.rb', line 27

def &(matcher)
  AllOf.new(self, matcher)
end

#to_matcherObject

:nodoc:



7
8
9
# File 'lib/mocha/parameter_matchers/base.rb', line 7

def to_matcher # :nodoc:
  self
end

#|(matcher) ⇒ Object

:call-seq: |(matcher) -> parameter_matcher

A short hand way of specifying multiple matchers, only at least one of which should pass.

Returns a new AnyOf parameter matcher combining the given matcher and the receiver.

The following statements are equivalent:

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

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

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

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


55
56
57
# File 'lib/mocha/parameter_matchers/base.rb', line 55

def |(matcher)
  AnyOf.new(self, matcher)
end