Skip to content

Commit ac70846

Browse files
committed
fix: do not blow up when there are no matchers
1 parent 5a20fea commit ac70846

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lib/pact/matching_rules/v3/merge.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,10 @@ def handle_regex object, path, rules
108108
def log_ignored_rules
109109
@matching_rules.each do | jsonpath, rules_hash |
110110
rules_array = rules_hash["matchers"]
111-
((rules_array.length - 1)..0).each do | index |
112-
rules_array.delete_at(index) if rules_array[index].empty?
111+
if rules_array
112+
((rules_array.length - 1)..0).each do | index |
113+
rules_array.delete_at(index) if rules_array[index].empty?
114+
end
113115
end
114116
end
115117

spec/lib/pact/matching_rules/v3/merge_spec.rb

+18
Original file line numberDiff line numberDiff line change
@@ -513,5 +513,23 @@
513513
expect(subject).to eq Pact::SomethingLike.new("/some/path")
514514
end
515515
end
516+
517+
context "when there are no matchers" do
518+
let(:expected) do
519+
{
520+
"name" => "Mary"
521+
}
522+
end
523+
524+
let(:matching_rules) do
525+
{
526+
"$.name" => {}
527+
}
528+
end
529+
530+
it "does not blow up" do
531+
subject
532+
end
533+
end
516534
end
517535
end

0 commit comments

Comments
 (0)