From ac7084682dfb15a4d43f6caa0598029a8cafa456 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Mon, 6 Apr 2020 17:26:04 +1000 Subject: [PATCH] fix: do not blow up when there are no matchers --- lib/pact/matching_rules/v3/merge.rb | 6 ++++-- spec/lib/pact/matching_rules/v3/merge_spec.rb | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) 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