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/has_keys.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,
 lib/mocha/parameter_matchers/instance_methods.rb,
 lib/mocha/parameter_matchers/positional_or_keyword_hash.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, HasKeys, 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_key(key)  ⇒ HasKey 
    
    
  
  
  
  
  
  
  
  
  
    Matches Hashcontainingkey.
- 
  
    
      #has_keys(*keys)  ⇒ HasKeys 
    
    
  
  
  
  
  
  
  
  
  
    Matches Hashcontainingkeys.
- 
  
    
      #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(*options)  ⇒ RespondsWith 
    
    
  
  
  
  
  
  
  
  
  
    Parameter matcher. 
- 
  
    
      #yaml_equivalent(object)  ⇒ YamlEquivalent 
    
    
  
  
  
  
  
  
  
  
  
    Matches any YAML that represents the specified object.
Instance Method Details
#all_of(*matchers) ⇒ AllOf
Matches if all matchers match.
| 23 24 25 | # File 'lib/mocha/parameter_matchers/all_of.rb', line 23 def all_of(*matchers) AllOf.new(*matchers) end | 
#any_of(*matchers) ⇒ AnyOf
Matches if any matchers match.
| 29 30 31 | # File 'lib/mocha/parameter_matchers/any_of.rb', line 29 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.
| 21 22 23 | # File 'lib/mocha/parameter_matchers/any_parameters.rb', line 21 def any_parameters AnyParameters.new end | 
#anything ⇒ Anything
Matches any object.
| 18 19 20 | # File 'lib/mocha/parameter_matchers/anything.rb', line 18 def anything Anything.new end | 
#equals(value) ⇒ Equals
Matches any Object equalling value.
| 24 25 26 | # File 'lib/mocha/parameter_matchers/equals.rb', line 24 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.
| 25 26 27 | # File 'lib/mocha/parameter_matchers/equivalent_uri.rb', line 25 def equivalent_uri(uri) EquivalentUri.new(uri) end | 
#has_entries(entries) ⇒ HasEntries
Matches Hash containing all entries.
| 26 27 28 | # File 'lib/mocha/parameter_matchers/has_entries.rb', line 26 def has_entries(entries) # rubocop:disable Naming/PredicateName HasEntries.new(entries) end | 
#has_entry(key, value) ⇒ HasEntry #has_entry(single_entry_hash) ⇒ HasEntry
Matches Hash containing entry with key and value.
| 43 44 45 46 47 48 49 50 51 52 53 54 55 | # File 'lib/mocha/parameter_matchers/has_entry.rb', line 43 def has_entry(*) # rubocop:disable Naming/PredicateName case .length when 0 raise ArgumentError, 'No arguments. Expecting at least one.' when 1 key, value = parse_option([0]) when 2 key, value = 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 | 
#has_key(key) ⇒ HasKey
Matches Hash containing key.
| 24 25 26 | # File 'lib/mocha/parameter_matchers/has_key.rb', line 24 def has_key(key) # rubocop:disable Naming/PredicateName HasKey.new(key) end | 
#has_keys(*keys) ⇒ HasKeys
Matches Hash containing keys.
| 24 25 26 | # File 'lib/mocha/parameter_matchers/has_keys.rb', line 24 def has_keys(*keys) # rubocop:disable Naming/PredicateName HasKeys.new(*keys) end | 
#has_value(value) ⇒ HasValue
Matches Hash containing value.
| 24 25 26 | # File 'lib/mocha/parameter_matchers/has_value.rb', line 24 def has_value(value) # rubocop:disable Naming/PredicateName HasValue.new(value) end | 
#includes(*items) ⇒ Includes
Matches any object that responds with true to include?(item) for all items.
| 63 64 65 | # File 'lib/mocha/parameter_matchers/includes.rb', line 63 def includes(*items) Includes.new(*items) end | 
#instance_of(klass) ⇒ InstanceOf
Matches any object that is an instance of klass
| 24 25 26 | # File 'lib/mocha/parameter_matchers/instance_of.rb', line 24 def instance_of(klass) InstanceOf.new(klass) end | 
#is_a(klass) ⇒ IsA
Matches any object that is a klass.
| 25 26 27 | # File 'lib/mocha/parameter_matchers/is_a.rb', line 25 def is_a(klass) # rubocop:disable Naming/PredicateName IsA.new(klass) end | 
#kind_of(klass) ⇒ KindOf
Matches any Object that is a kind of klass.
| 24 25 26 | # File 'lib/mocha/parameter_matchers/kind_of.rb', line 24 def kind_of(klass) KindOf.new(klass) end | 
#Not(matcher) ⇒ Not
Matches if matcher does not match.
| 24 25 26 | # File 'lib/mocha/parameter_matchers/not.rb', line 24 def Not(matcher) # rubocop:disable Naming/MethodName Not.new(matcher) end | 
#optionally(*matchers) ⇒ Optionally
Matches optional parameters if available.
| 33 34 35 | # File 'lib/mocha/parameter_matchers/optionally.rb', line 33 def optionally(*matchers) Optionally.new(*matchers) end | 
#regexp_matches(regexp) ⇒ RegexpMatches
Matches any object that matches regexp.
| 24 25 26 | # File 'lib/mocha/parameter_matchers/regexp_matches.rb', line 24 def regexp_matches(regexp) RegexpMatches.new(regexp) end | 
#responds_with(message, result) ⇒ RespondsWith #responds_with(messages_vs_results) ⇒ RespondsWith
Returns parameter matcher.
| 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | # File 'lib/mocha/parameter_matchers/responds_with.rb', line 37 def responds_with(*) case .length when 0 raise ArgumentError, 'No arguments. Expecting at least one.' when 1 option = .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 { |, result| RespondsWith.new(, result) } AllOf.new(*matchers) when 2 , result = RespondsWith.new(, 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 | 
#yaml_equivalent(object) ⇒ YamlEquivalent
Matches any YAML that represents the specified object
| 24 25 26 | # File 'lib/mocha/parameter_matchers/yaml_equivalent.rb', line 24 def yaml_equivalent(object) YamlEquivalent.new(object) end |