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_entry.rb,
lib/mocha/parameter_matchers/has_value.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/responds_with.rb,
lib/mocha/parameter_matchers/any_parameters.rb,
lib/mocha/parameter_matchers/equivalent_uri.rb,
lib/mocha/parameter_matchers/regexp_matches.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, EquivalentUri, HasEntries, HasEntry, HasKey, HasValue, Includes, InstanceOf, IsA, KindOf, Not, Optionally, RegexpMatches, RespondsWith, YamlEquivalent
Instance Method Summary collapse
-
#all_of(*matchers) ⇒ AllOf
Matches if all
matchersmatch. -
#any_of(*matchers) ⇒ AnyOf
Matches if any
matchersmatch. -
#any_parameters ⇒ AnyParameters
Matches any parameters.
-
#anything ⇒ Anything
Matches any object.
-
#equals(value) ⇒ Equals
Matches any
Objectequallingvalue. -
#equivalent_uri(uri) ⇒ EquivalentUri
Matches a URI without regard to the ordering of parameters in the query string.
-
#has_entries(entries) ⇒ HasEntries
Matches
Hashcontaining allentries. -
#has_entry(*options) ⇒ HasEntry
Matches
Hashcontaining entry withkeyandvalue. -
#has_equivalent_query_string(uri) ⇒ Object
deprecated
Deprecated.
Use #equivalent_uri instead.
-
#has_key(key) ⇒ HasKey
Matches
Hashcontainingkey. -
#has_value(value) ⇒ HasValue
Matches
Hashcontainingvalue. -
#includes(*items) ⇒ Includes
Matches any object that responds with
trueto include?(item) for all items. -
#instance_of(klass) ⇒ InstanceOf
Matches any object that is an instance of
klass. -
#is_a(klass) ⇒ IsA
Matches any object that is a
klass. -
#kind_of(klass) ⇒ KindOf
Matches any
Objectthat is a kind ofklass. -
#Not(matcher) ⇒ Not
Matches if
matcherdoes not match. -
#optionally(*matchers) ⇒ Optionally
Matches optional parameters if available.
-
#regexp_matches(regexp) ⇒ RegexpMatches
Matches any object that matches
regexp. -
#responds_with(message, result) ⇒ RespondsWith
Matches any object that responds to
messagewithresult. -
#yaml_equivalent(object) ⇒ YamlEquivalent
Matches any YAML that represents the specified
object.
Instance Method Details
#all_of(*matchers) ⇒ AllOf
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 |
#any_of(*matchers) ⇒ AnyOf
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 |
#any_parameters ⇒ AnyParameters
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(value) ⇒ Equals
Matches any Object equalling value.
26 27 28 |
# File 'lib/mocha/parameter_matchers/equals.rb', line 26 def equals(value) Equals.new(value) end |
#equivalent_uri(uri) ⇒ EquivalentUri
Matches a URI without regard to the ordering of parameters in the query string.
27 28 29 |
# File 'lib/mocha/parameter_matchers/equivalent_uri.rb', line 27 def equivalent_uri(uri) EquivalentUri.new(uri) end |
#has_entries(entries) ⇒ HasEntries
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 |
#has_entry(key, value) ⇒ HasEntry #has_entry(single_entry_hash) ⇒ HasEntry
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 |
#has_equivalent_query_string(uri) ⇒ Object
Use #equivalent_uri instead.
32 33 34 35 36 |
# File 'lib/mocha/parameter_matchers/equivalent_uri.rb', line 32 def has_equivalent_query_string(uri) Mocha::Deprecation.warning("`has_equivalent_query_string` is deprecated. Please use `equivalent_uri` instead.") equivalent_uri(uri) end |
#has_key(key) ⇒ HasKey
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 |
#has_value(value) ⇒ HasValue
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(*items) ⇒ Includes
Matches any object that responds with true to include?(item)
for all items.
65 66 67 |
# File 'lib/mocha/parameter_matchers/includes.rb', line 65 def includes(*items) Includes.new(*items) end |
#instance_of(klass) ⇒ InstanceOf
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 |
#is_a(klass) ⇒ IsA
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 |
#kind_of(klass) ⇒ KindOf
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(matcher) ⇒ Not
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(*matchers) ⇒ Optionally
Matches optional parameters if available.
35 36 37 |
# File 'lib/mocha/parameter_matchers/optionally.rb', line 35 def optionally(*matchers) Optionally.new(*matchers) end |
#regexp_matches(regexp) ⇒ RegexpMatches
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 |
#responds_with(message, result) ⇒ RespondsWith
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 |
#yaml_equivalent(object) ⇒ YamlEquivalent
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 |