Class: Mocha::ParameterMatchers::Base
- Defined in:
- lib/mocha/parameter_matchers/base.rb
Direct Known Subclasses
AllOf, AnyOf, AnyParameters, Anything, Equals, HasEntries, HasEntry, HasKey, HasValue, Includes, InstanceOf, IsA, KindOf, Not, Optionally, RegexpMatches, RespondsWith, YamlEquivalent
Instance Method Summary collapse
-
#&(matcher) ⇒ Object
:call-seq: &(matcher) -> parameter_matcher.
-
#to_matcher ⇒ Object
:nodoc:.
-
#|(matcher) ⇒ Object
:call-seq: |(matcher) -> parameter_matcher.
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_matcher ⇒ Object
: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 |