Skip to content

Commit

Permalink
Merge pull request #723 from freerange/convert-parameter-matchers-bas…
Browse files Browse the repository at this point in the history
…e-into-module

Convert `ParameterMatchers::Base` class -> module
  • Loading branch information
floehopper authored Jan 1, 2025
2 parents 1c5dda3 + a1a50bb commit b04143e
Show file tree
Hide file tree
Showing 22 changed files with 65 additions and 42 deletions.
5 changes: 3 additions & 2 deletions lib/mocha/parameter_matchers/all_of.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ def all_of(*matchers)
end

# Parameter matcher which combines a number of other matchers using a logical AND.
class AllOf < Base
class AllOf
include Base

# @private
def initialize(*matchers)
super()
@matchers = matchers
end

Expand Down
5 changes: 3 additions & 2 deletions lib/mocha/parameter_matchers/any_of.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ def any_of(*matchers)
end

# Parameter matcher which combines a number of other matchers using a logical OR.
class AnyOf < Base
class AnyOf
include Base

# @private
def initialize(*matchers)
super()
@matchers = matchers
end

Expand Down
4 changes: 3 additions & 1 deletion lib/mocha/parameter_matchers/any_parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ def any_parameters
end

# Parameter matcher which always matches whatever the parameters.
class AnyParameters < Base
class AnyParameters
include Base

# @private
def matches?(available_parameters)
until available_parameters.empty?
Expand Down
4 changes: 3 additions & 1 deletion lib/mocha/parameter_matchers/anything.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ def anything
end

# Parameter matcher which always matches a single parameter.
class Anything < Base
class Anything
include Base

# @private
def matches?(available_parameters)
available_parameters.shift
Expand Down
4 changes: 2 additions & 2 deletions lib/mocha/parameter_matchers/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

module Mocha
module ParameterMatchers
# @abstract Subclass and implement +#matches?+ and +#mocha_inspect+ to define a custom matcher. Also add a suitably named instance method to {ParameterMatchers} to build an instance of the new matcher c.f. {#equals}.
class Base
# @abstract Include and implement +#matches?+ and +#mocha_inspect+ to define a custom matcher. Also add a suitably named instance method to {ParameterMatchers} to build an instance of the new matcher c.f. {#equals}.
module Base
# A shorthand way of combining two matchers when both must match.
#
# Returns a new {AllOf} parameter matcher combining two matchers using a logical AND.
Expand Down
5 changes: 3 additions & 2 deletions lib/mocha/parameter_matchers/equals.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ def equals(value)
end

# Parameter matcher which matches when actual parameter equals expected value.
class Equals < Base
class Equals
include Base

# @private
def initialize(value)
super()
@value = value
end

Expand Down
5 changes: 3 additions & 2 deletions lib/mocha/parameter_matchers/equivalent_uri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ def equivalent_uri(uri)
end

# Parameter matcher which matches URIs with equivalent query strings.
class EquivalentUri < Base
class EquivalentUri
include Base

# @private
def initialize(uri)
super()
@uri = URI.parse(uri)
end

Expand Down
5 changes: 3 additions & 2 deletions lib/mocha/parameter_matchers/has_entries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ def has_entries(entries) # rubocop:disable Naming/PredicateName
end

# Parameter matcher which matches when actual parameter contains all expected +Hash+ entries.
class HasEntries < Base
class HasEntries
include Base

# @private
def initialize(entries, exact: false)
super()
@entries = entries
@exact = exact
end
Expand Down
5 changes: 3 additions & 2 deletions lib/mocha/parameter_matchers/has_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ def has_entry(*options) # rubocop:disable Naming/PredicateName
end

# Parameter matcher which matches when actual parameter contains expected +Hash+ entry.
class HasEntry < Base
class HasEntry
include Base

# @private
def initialize(key, value)
super()
@key = key
@value = value
end
Expand Down
5 changes: 3 additions & 2 deletions lib/mocha/parameter_matchers/has_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ def has_key(key) # rubocop:disable Naming/PredicateName
end

# Parameter matcher which matches when actual parameter contains +Hash+ entry with expected key.
class HasKey < Base
class HasKey
include Base

# @private
def initialize(key)
super()
@key = key
end

Expand Down
5 changes: 3 additions & 2 deletions lib/mocha/parameter_matchers/has_keys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ def has_keys(*keys) # rubocop:disable Naming/PredicateName
end

# Parameter matcher which matches when actual parameter contains +Hash+ with all expected keys.
class HasKeys < Base
class HasKeys
include Base

# @private
def initialize(*keys)
super()
raise ArgumentError, 'No arguments. Expecting at least one.' if keys.empty?

@keys = keys
Expand Down
5 changes: 3 additions & 2 deletions lib/mocha/parameter_matchers/has_value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ def has_value(value) # rubocop:disable Naming/PredicateName
end

# Parameter matcher which matches when actual parameter contains +Hash+ entry with expected value.
class HasValue < Base
class HasValue
include Base

# @private
def initialize(value)
super()
@value = value
end

Expand Down
5 changes: 3 additions & 2 deletions lib/mocha/parameter_matchers/includes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ def includes(*items)
end

# Parameter matcher which matches when actual parameter includes expected values.
class Includes < Base
class Includes
include Base

# @private
def initialize(*items)
super()
@items = items
end

Expand Down
5 changes: 3 additions & 2 deletions lib/mocha/parameter_matchers/instance_of.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ def instance_of(klass)
end

# Parameter matcher which matches when actual parameter is an instance of the specified class.
class InstanceOf < Base
class InstanceOf
include Base

# @private
def initialize(klass)
super()
@klass = klass
end

Expand Down
5 changes: 3 additions & 2 deletions lib/mocha/parameter_matchers/is_a.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ def is_a(klass) # rubocop:disable Naming/PredicateName
end

# Parameter matcher which matches when actual parameter is a specific class.
class IsA < Base
class IsA
include Base

# @private
def initialize(klass)
super()
@klass = klass
end

Expand Down
5 changes: 3 additions & 2 deletions lib/mocha/parameter_matchers/kind_of.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ def kind_of(klass)
end

# Parameter matcher which matches when actual parameter is a kind of specified class.
class KindOf < Base
class KindOf
include Base

# @private
def initialize(klass)
super()
@klass = klass
end

Expand Down
5 changes: 3 additions & 2 deletions lib/mocha/parameter_matchers/not.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ def Not(matcher) # rubocop:disable Naming/MethodName
end

# Parameter matcher which inverts the logic of the specified matcher using a logical NOT operation.
class Not < Base
class Not
include Base

# @private
def initialize(matcher)
super()
@matcher = matcher
end

Expand Down
5 changes: 3 additions & 2 deletions lib/mocha/parameter_matchers/optionally.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ def optionally(*matchers)
end

# Parameter matcher which allows optional parameters to be specified.
class Optionally < Base
class Optionally
include Base

# @private
def initialize(*parameters)
super()
@matchers = parameters.map(&:to_matcher)
end

Expand Down
5 changes: 3 additions & 2 deletions lib/mocha/parameter_matchers/positional_or_keyword_hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
module Mocha
module ParameterMatchers
# @private
class PositionalOrKeywordHash < Base
class PositionalOrKeywordHash
include Base

def initialize(value, expectation)
super()
@value = value
@expectation = expectation
end
Expand Down
5 changes: 3 additions & 2 deletions lib/mocha/parameter_matchers/regexp_matches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ def regexp_matches(regexp)
end

# Parameter matcher which matches if specified regular expression matches actual paramter.
class RegexpMatches < Base
class RegexpMatches
include Base

# @private
def initialize(regexp)
super()
@regexp = regexp
end

Expand Down
5 changes: 3 additions & 2 deletions lib/mocha/parameter_matchers/responds_with.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ def responds_with(*options)
end

# Parameter matcher which matches if actual parameter returns expected result when specified method is invoked.
class RespondsWith < Base
class RespondsWith
include Base

# @private
def initialize(message, result)
super()
@message = message
@result = result
end
Expand Down
5 changes: 3 additions & 2 deletions lib/mocha/parameter_matchers/yaml_equivalent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ def yaml_equivalent(object)
end

# Parameter matcher which matches if actual parameter is YAML equivalent of specified object.
class YamlEquivalent < Base
class YamlEquivalent
include Base

# @private
def initialize(object)
super()
@object = object
end

Expand Down

0 comments on commit b04143e

Please sign in to comment.