Skip to content

Commit

Permalink
Consolidate to_matcher definitions in one place
Browse files Browse the repository at this point in the history
  • Loading branch information
floehopper committed Jul 16, 2024
1 parent 600ee2a commit e9de64e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
5 changes: 0 additions & 5 deletions lib/mocha/parameter_matchers/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ 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
# @private
def to_matcher(_expectation = nil, _top_level = false)
self
end

# 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: 4 additions & 1 deletion lib/mocha/parameter_matchers/instance_methods.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'mocha/parameter_matchers/base'
require 'mocha/parameter_matchers/equals'
require 'mocha/parameter_matchers/positional_or_keyword_hash'

Expand All @@ -7,7 +8,9 @@ module ParameterMatchers
module InstanceMethods
# @private
def to_matcher(expectation = nil, top_level = false)
if is_a?(Hash) && top_level
if is_a?(Base)
self
elsif is_a?(Hash) && top_level
Mocha::ParameterMatchers::PositionalOrKeywordHash.new(self, expectation)
else
Mocha::ParameterMatchers::Equals.new(self)
Expand Down

0 comments on commit e9de64e

Please sign in to comment.