diff --git a/lib/pact/matching_rules/v3/merge.rb b/lib/pact/matching_rules/v3/merge.rb index a8acafd..2a276b1 100644 --- a/lib/pact/matching_rules/v3/merge.rb +++ b/lib/pact/matching_rules/v3/merge.rb @@ -108,8 +108,10 @@ def handle_regex object, path, rules def log_ignored_rules @matching_rules.each do | jsonpath, rules_hash | rules_array = rules_hash["matchers"] - ((rules_array.length - 1)..0).each do | index | - rules_array.delete_at(index) if rules_array[index].empty? + if rules_array + ((rules_array.length - 1)..0).each do | index | + rules_array.delete_at(index) if rules_array[index].empty? + end end end diff --git a/spec/lib/pact/matching_rules/v3/merge_spec.rb b/spec/lib/pact/matching_rules/v3/merge_spec.rb index 7d69209..05d5dec 100644 --- a/spec/lib/pact/matching_rules/v3/merge_spec.rb +++ b/spec/lib/pact/matching_rules/v3/merge_spec.rb @@ -513,5 +513,23 @@ expect(subject).to eq Pact::SomethingLike.new("/some/path") end end + + context "when there are no matchers" do + let(:expected) do + { + "name" => "Mary" + } + end + + let(:matching_rules) do + { + "$.name" => {} + } + end + + it "does not blow up" do + subject + end + end end end