From 9a4d08e983b102179cbdfc3587b63f0d81a0cae5 Mon Sep 17 00:00:00 2001 From: Mike Countis Date: Tue, 11 May 2021 16:00:15 -0700 Subject: [PATCH] Evaluate given block in the current module context I'm guessing the original intent of the blocks provided to MatcherFactory were to mimic blocks provided to RSpec::Matchers.define calls. In that spirit, evaluate the provided block in the module context of RSpec's original matcher definition method so that any methods defined within the block are defined on the module/class rather than in a main/global context. This alleviates warning messages about the traverse method already being defined in the context and getting redefined. --- lib/rspec/json_expectations/matcher_factory.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rspec/json_expectations/matcher_factory.rb b/lib/rspec/json_expectations/matcher_factory.rb index bd0da9e..6a125b5 100644 --- a/lib/rspec/json_expectations/matcher_factory.rb +++ b/lib/rspec/json_expectations/matcher_factory.rb @@ -7,7 +7,7 @@ def initialize(matcher_name) def define_matcher(&block) RSpec::Matchers.define(@matcher_name) do |expected| - yield + self.module_eval(&block) match do |actual| traverse(expected, actual, false)