module Mocha::ParameterMatchers
def Not(matcher) # rubocop:disable Naming/MethodName
- Example: Actual parameter does include the value +1+. -
Example: Actual parameter does not include the value +1+. -
Other tags:
- See: Expectation#with -
Returns:
-
(Not)
- parameter matcher.
Parameters:
-
matcher
(Base
) -- matcher whose logic to invert.
def Not(matcher) # rubocop:disable Naming/MethodName Not.new(matcher) end
def all_of(*matchers)
- Example: One of the parameter matchers does not match. -
Example: All parameter matchers match. -
Other tags:
- See: Expectation#with -
Returns:
-
(AllOf)
- parameter matcher.
Parameters:
-
matchers
(*Array
) -- parameter matchers.
def all_of(*matchers) AllOf.new(*matchers) end
def any_of(*matchers)
- Example: Neither parameter matcher matches. -
Example: The other parameter matcher matches. -
Example: One parameter matcher matches. -
Other tags:
- See: Expectation#with -
Returns:
-
(AnyOf)
- parameter matcher.
Parameters:
-
matchers
(*Array
) -- parameter matchers.
def any_of(*matchers) AnyOf.new(*matchers) end
def any_parameters
- Example: Any parameters will match. -
Other tags:
- See: Expectation#with -
Returns:
-
(AnyParameters)
- parameter matcher.
def any_parameters AnyParameters.new end
def anything
- Example: Any object will match. -
Other tags:
- See: Expectation#with -
Returns:
-
(Anything)
- parameter matcher.
def anything Anything.new end
def equals(value)
- Example: Actual parameter does not equal expected parameter. -
Example: Actual parameter equals expected parameter. -
Other tags:
- See: Object#== -
See: Expectation#with -
Returns:
-
(Equals)
- parameter matcher.
Parameters:
-
value
(Object
) -- expected value.
def equals(value) Equals.new(value) end
def equivalent_uri(uri)
- Example: Actual URI is not equivalent. -
Example: Actual URI is equivalent. -
Other tags:
- See: Expectation#with -
Returns:
-
(EquivalentUri)
- parameter matcher.
Parameters:
-
uri
(String
) -- URI to match.
def equivalent_uri(uri) EquivalentUri.new(uri) end
def has_entries(entries) # rubocop:disable Naming/PredicateName
- Example: Actual parameter does not contain all expected entries. -
Example: Actual parameter contains all expected entries. -
Other tags:
- See: Expectation#with -
Returns:
-
(HasEntries)
- parameter matcher.
Parameters:
-
entries
(Hash
) -- expected +Hash+ entries.
def has_entries(entries) # rubocop:disable Naming/PredicateName HasEntries.new(entries) end
def has_entry(*options) # rubocop:disable Naming/PredicateName
- Example: Actual parameter does not contain expected entry supplied as +Hash+ entry. -
Example: Actual parameter does not contain expected entry supplied as key and value. -
Example: Actual parameter contains expected entry supplied as +Hash+ entry. -
Example: Actual parameter contains expected entry supplied as key and value. -
Other tags:
- See: Expectation#with -
Returns:
-
(HasEntry)
- parameter matcher.
Raises:
-
(ArgumentError)
- if +single_entry_hash+ does not contain exactly one entry.
Parameters:
-
single_entry_hash
(Hash
) -- +Hash+ with single entry. -
value
(Object
) -- value for entry. -
key
(Object
) -- key for entry.
Overloads:
-
def has_entry(single_entry_hash)
-
def has_entry(key, value)
def has_entry(*options) # rubocop:disable Naming/PredicateName case options.length when 0 raise ArgumentError, 'No arguments. Expecting at least one.' when 1 key, value = parse_option(options[0]) when 2 key, value = options else raise ArgumentError, '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
def has_key(key) # rubocop:disable Naming/PredicateName
- Example: Actual parameter does not contain entry with expected key. -
Example: Actual parameter contains entry with expected key. -
Other tags:
- See: Expectation#with -
Returns:
-
(HasKey)
- parameter matcher.
Parameters:
-
key
(Object
) -- expected key.
def has_key(key) # rubocop:disable Naming/PredicateName HasKey.new(key) end
def has_keys(*keys) # rubocop:disable Naming/PredicateName
- Example: Actual parameter does not contain all expected keys. -
Example: Actual parameter contains entry with expected keys. -
Other tags:
- See: Expectation#with -
Returns:
-
(HasKeys)
- parameter matcher.
Parameters:
-
keys
(*Array
) -- expected keys.
def has_keys(*keys) # rubocop:disable Naming/PredicateName HasKeys.new(*keys) end
def has_value(value) # rubocop:disable Naming/PredicateName
- Example: Actual parameter does not contain entry with expected value. -
Example: Actual parameter contains entry with expected value. -
Other tags:
- See: Expectation#with -
Returns:
-
(HasValue)
- parameter matcher.
Parameters:
-
value
(Object
) -- expected value.
def has_value(value) # rubocop:disable Naming/PredicateName HasValue.new(value) end
def includes(*items)
- Example: Actual parameter is a Hash no key matching the given matcher. -
Example: Actual parameter is a Hash with a key matching the given matcher. -
Example: Actual parameter is a Hash without the given key. -
Example: Actual parameter is a Hash including the given key. -
Example: Actual parameter is a String not including substring. -
Example: Actual parameter is a String including substring. -
Example: Actual parameter does not include item matching nested matcher. -
Example: Actual parameter includes item which matches nested matcher. -
Example: Actual parameter does not include all items. -
Example: Actual parameter includes all items. -
Other tags:
- See: Expectation#with -
Returns:
-
(Includes)
- parameter matcher.
Parameters:
-
items
(*Array
) -- expected items.
def includes(*items) Includes.new(*items) end
def instance_of(klass)
- Example: Actual parameter is not an instance of +String+. -
Example: Actual parameter is an instance of +String+. -
Other tags:
- See: Kernel#instance_of? -
See: Expectation#with -
Returns:
-
(InstanceOf)
- parameter matcher.
Parameters:
-
klass
(Class
) -- expected class.
def instance_of(klass) InstanceOf.new(klass) end
def is_a(klass) # rubocop:disable Naming/PredicateName
- Example: Actual parameter is not a +Integer+. -
Example: Actual parameter is a +Integer+. -
Other tags:
- See: Kernel#is_a? -
See: Expectation#with -
Returns:
-
(IsA)
- parameter matcher.
Parameters:
-
klass
(Class
) -- expected class.
def is_a(klass) # rubocop:disable Naming/PredicateName IsA.new(klass) end
def kind_of(klass)
- Example: Actual parameter is not a kind of +Integer+. -
Example: Actual parameter is a kind of +Integer+. -
Other tags:
- See: Kernel#kind_of? -
See: Expectation#with -
Returns:
-
(KindOf)
- parameter matcher.
Parameters:
-
klass
(Class
) -- expected class.
def kind_of(klass) KindOf.new(klass) end
def optionally(*matchers)
- Example: One of the actual optional parameters does not match the expected value. -
Example: Both required parameters and both of the optional parameters are supplied and they all match their expected value. -
Example: Both required parameters and one of the optional parameters are supplied and they all match their expected value. -
Example: Only the two required parameters are supplied and they both match their expected value. -
Other tags:
- See: Expectation#with -
Returns:
-
(Optionally)
- parameter matcher.
Parameters:
-
matchers
(*Array
) -- matchers for optional parameters.
def optionally(*matchers) Optionally.new(*matchers) end
def parse_option(option)
- Private: -
def parse_option(option) case option when Hash case option.length when 0 raise ArgumentError, 'Argument has no entries.' when 1 option.first else raise ArgumentError, 'Argument has multiple entries. Use Mocha::ParameterMatchers#has_entries instead.' end else raise ArgumentError, 'Argument is not a Hash.' end end
def regexp_matches(regexp)
- Example: Actual parameter is not matched by specified regular expression. -
Example: Actual parameter is matched by specified regular expression. -
Other tags:
- See: Expectation#with -
Returns:
-
(RegexpMatches)
- parameter matcher.
Parameters:
-
regexp
(Regexp
) -- regular expression to match.
def regexp_matches(regexp) RegexpMatches.new(regexp) end
def responds_with(*options)
- Example: Actual parameter responds with "FOO" when :upcase is invoked and "oof" when :reverse is invoked. -
Example: Actual parameter does not respond with "FOO" when :upcase is invoked. -
Example: Actual parameter responds with "FOO" when :upcase is invoked. -
Other tags:
- See: Expectation#with -
Returns:
-
(RespondsWith)
- parameter matcher.
Raises:
-
(ArgumentError)
- if +messages_vs_results+ does not contain at least one entry.
Parameters:
-
messages_vs_results
(Hash
) -- +Hash+ of messages vs results. -
result
(Object
) -- expected result of sending +message+. -
message
(Symbol
) -- method to invoke.
Overloads:
-
def responds_with(messages_vs_results)
-
def responds_with(message, result)
def responds_with(*options) case options.length when 0 raise ArgumentError, 'No arguments. Expecting at least one.' when 1 option = options.first raise ArgumentError, 'Argument is not a Hash.' unless option.is_a?(Hash) raise ArgumentError, 'Argument has no entries.' if option.empty? matchers = option.map { |message, result| RespondsWith.new(message, result) } AllOf.new(*matchers) when 2 message, result = options RespondsWith.new(message, result) else raise ArgumentError, 'Too many arguments; use either a single argument (must be a Hash) or two arguments (a message and a result).' end end
def yaml_equivalent(object)
- Example: Actual parameter is not YAML equivalent of specified +object+. -
Example: Actual parameter is YAML equivalent of specified +object+. -
Other tags:
- See: Expectation#with -
Returns:
-
(YamlEquivalent)
- parameter matcher.
Parameters:
-
object
(Object
) -- object whose YAML to compare.
def yaml_equivalent(object) YamlEquivalent.new(object) end