Skip to content

Commit

Permalink
fix: do not blow up when there are no matchers
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Apr 6, 2020
1 parent 5a20fea commit ac70846
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/pact/matching_rules/v3/merge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 18 additions & 0 deletions spec/lib/pact/matching_rules/v3/merge_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ac70846

Please sign in to comment.