Module: Mocha::ParameterMatchers
- Included in:
- API
- Defined in:
- lib/mocha/parameter_matchers.rb,
lib/mocha/parameter_matchers/not.rb,
lib/mocha/parameter_matchers/base.rb,
lib/mocha/parameter_matchers/is_a.rb,
lib/mocha/parameter_matchers/all_of.rb,
lib/mocha/parameter_matchers/any_of.rb,
lib/mocha/parameter_matchers/equals.rb,
lib/mocha/parameter_matchers/has_key.rb,
lib/mocha/parameter_matchers/kind_of.rb,
lib/mocha/parameter_matchers/anything.rb,
lib/mocha/parameter_matchers/includes.rb,
lib/mocha/parameter_matchers/has_value.rb,
lib/mocha/parameter_matchers/has_entry.rb,
lib/mocha/parameter_matchers/optionally.rb,
lib/mocha/parameter_matchers/has_entries.rb,
lib/mocha/parameter_matchers/instance_of.rb,
lib/mocha/parameter_matchers/query_string.rb,
lib/mocha/parameter_matchers/responds_with.rb,
lib/mocha/parameter_matchers/regexp_matches.rb,
lib/mocha/parameter_matchers/any_parameters.rb,
lib/mocha/parameter_matchers/yaml_equivalent.rb
Overview
Used as parameters for Expectation#with to restrict the parameter values which will match the expectation. Can be nested.
Defined Under Namespace
Classes: AllOf, AnyOf, AnyParameters, Anything, Base, Equals, HasEntries, HasEntry, HasKey, HasValue, Includes, InstanceOf, IsA, KindOf, Not, Optionally, QueryStringMatches, RegexpMatches, RespondsWith, YamlEquivalent
Instance Method Summary (collapse)
-
- (AllOf) all_of(*matchers)
Matches if all
matchers
match. -
- (AnyOf) any_of(*matchers)
Matches if any
matchers
match. -
- (AnyParameters) any_parameters
Matches any parameters.
-
- (Anything) anything
Matches any object.
-
- (Equals) equals(value)
Matches any
Object
equallingvalue
. -
- (HasEntries) has_entries(entries)
Matches
Hash
containing allentries
. -
- (HasEntry) has_entry(*options)
Matches
Hash
containing entry withkey
andvalue
. -
- (QueryStringMatches) has_equivalent_query_string(uri)
Matches a URI without regard to the ordering of parameters in the query string.
-
- (HasKey) has_key(key)
Matches
Hash
containingkey
. -
- (HasValue) has_value(value)
Matches
Hash
containingvalue
. -
- (Includes) includes(*items)
Matches any object that responds with
true
to include?(item) for all items. -
- (InstanceOf) instance_of(klass)
Matches any object that is an instance of
klass
. -
- (IsA) is_a(klass)
Matches any object that is a
klass
. -
- (KindOf) kind_of(klass)
Matches any
Object
that is a kind ofklass
. -
- (Not) Not(matcher)
Matches if
matcher
does not match. -
- (Optionally) optionally(*matchers)
Matches optional parameters if available.
-
- (RegexpMatches) regexp_matches(regexp)
Matches any object that matches
regexp
. -
- (RespondsWith) responds_with(message, result)
Matches any object that responds to
message
withresult
. -
- (YamlEquivalent) yaml_equivalent(object)
Matches any YAML that represents the specified
object
.
Instance Method Details
- (AllOf) all_of(*matchers)
Matches if all matchers
match.
25 26 27 |
# File 'lib/mocha/parameter_matchers/all_of.rb', line 25 def all_of(*matchers) AllOf.new(*matchers) end |
- (AnyOf) any_of(*matchers)
Matches if any matchers
match.
31 32 33 |
# File 'lib/mocha/parameter_matchers/any_of.rb', line 31 def any_of(*matchers) AnyOf.new(*matchers) end |
- (AnyParameters) any_parameters
Matches any parameters. This is used as the default for a newly built expectation.
23 24 25 |
# File 'lib/mocha/parameter_matchers/any_parameters.rb', line 23 def any_parameters AnyParameters.new end |
- (Anything) anything
Matches any object.
20 21 22 |
# File 'lib/mocha/parameter_matchers/anything.rb', line 20 def anything Anything.new end |
- (Equals) equals(value)
Matches any Object
equalling value
.
26 27 28 |
# File 'lib/mocha/parameter_matchers/equals.rb', line 26 def equals(value) Equals.new(value) end |
- (HasEntries) has_entries(entries)
Matches Hash
containing all entries
.
27 28 29 |
# File 'lib/mocha/parameter_matchers/has_entries.rb', line 27 def has_entries(entries) HasEntries.new(entries) end |
- (HasEntry) has_entry(key, value) - (HasEntry) has_entry(single_entry_hash)
Matches Hash
containing entry with key
and
value
.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/mocha/parameter_matchers/has_entry.rb', line 44 def has_entry(*) case .length when 1 case [0] when Hash case [0].length when 0 raise ArgumentError.new("Argument has no entries.") when 1 key, value = [0].first else raise ArgumentError.new("Argument has multiple entries. Use Mocha::ParameterMatchers#has_entries instead.") end else raise ArgumentError.new("Argument is not a Hash.") end when 2 key, value = else raise ArgumentError.new("Too many arguments; use either a single argument (must be a Hash) or two arguments (a key and a value).") end HasEntry.new(key, value) end |
- (QueryStringMatches) has_equivalent_query_string(uri)
Matches a URI without regard to the ordering of parameters in the query string.
25 26 27 |
# File 'lib/mocha/parameter_matchers/query_string.rb', line 25 def has_equivalent_query_string(uri) QueryStringMatches.new(uri) end |
- (HasKey) has_key(key)
Matches Hash
containing key
.
25 26 27 |
# File 'lib/mocha/parameter_matchers/has_key.rb', line 25 def has_key(key) HasKey.new(key) end |
- (HasValue) has_value(value)
Matches Hash
containing value
.
25 26 27 |
# File 'lib/mocha/parameter_matchers/has_value.rb', line 25 def has_value(value) HasValue.new(value) end |
- (Includes) includes(*items)
Matches any object that responds with true
to include?(item)
for all items.
25 26 27 |
# File 'lib/mocha/parameter_matchers/includes.rb', line 25 def includes(*items) Includes.new(*items) end |
- (InstanceOf) instance_of(klass)
Matches any object that is an instance of klass
26 27 28 |
# File 'lib/mocha/parameter_matchers/instance_of.rb', line 26 def instance_of(klass) InstanceOf.new(klass) end |
- (IsA) is_a(klass)
Matches any object that is a klass
.
26 27 28 |
# File 'lib/mocha/parameter_matchers/is_a.rb', line 26 def is_a(klass) IsA.new(klass) end |
- (KindOf) kind_of(klass)
Matches any Object
that is a kind of klass
.
26 27 28 |
# File 'lib/mocha/parameter_matchers/kind_of.rb', line 26 def kind_of(klass) KindOf.new(klass) end |
- (Not) Not(matcher)
Matches if matcher
does not match.
25 26 27 |
# File 'lib/mocha/parameter_matchers/not.rb', line 25 def Not(matcher) Not.new(matcher) end |
- (Optionally) optionally(*matchers)
Matches optional parameters if available.
35 36 37 |
# File 'lib/mocha/parameter_matchers/optionally.rb', line 35 def optionally(*matchers) Optionally.new(*matchers) end |
- (RegexpMatches) regexp_matches(regexp)
Matches any object that matches regexp
.
26 27 28 |
# File 'lib/mocha/parameter_matchers/regexp_matches.rb', line 26 def regexp_matches(regexp) RegexpMatches.new(regexp) end |
- (RespondsWith) responds_with(message, result)
Matches any object that responds to message
with
result
. To put it another way, it tests the quack, not the
duck.
27 28 29 |
# File 'lib/mocha/parameter_matchers/responds_with.rb', line 27 def responds_with(, result) RespondsWith.new(, result) end |
- (YamlEquivalent) yaml_equivalent(object)
Matches any YAML that represents the specified object
26 27 28 |
# File 'lib/mocha/parameter_matchers/yaml_equivalent.rb', line 26 def yaml_equivalent(object) YamlEquivalent.new(object) end |