From a565a5605fe4d32a89ba9d6f001283f297a535f1 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Wed, 25 Mar 2020 16:20:49 +1100 Subject: [PATCH] fix: don't blow up when there is a term inside an each like This will probably break something else, as I can't remember why the unpack_regexps was in there in the first place. Closes: https://github.com/pact-foundation/pact-ruby-standalone/issues/47 --- lib/pact/matchers/matchers.rb | 6 +++++- spec/lib/pact/matchers/matchers_spec.rb | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/pact/matchers/matchers.rb b/lib/pact/matchers/matchers.rb index 114ffd3..8f5bb88 100644 --- a/lib/pact/matchers/matchers.rb +++ b/lib/pact/matchers/matchers.rb @@ -120,7 +120,11 @@ def actual_array_diff expected, actual, options def array_like_diff array_like, actual, options if actual.is_a? Array expected_size = [array_like.min, actual.size].max - expected_array = expected_size.times.collect{ Pact::Term.unpack_regexps(array_like.contents) } + # I know changing this is going to break something, but I don't know what it is, as there's no + # test that fails when I make this change. I know the unpack regexps was there for a reason however. + # Guess we'll have to change it and see! + # expected_array = expected_size.times.collect{ Pact::Term.unpack_regexps(array_like.contents) } + expected_array = expected_size.times.collect{ array_like.contents } actual_array_diff expected_array, actual, options.merge(:type => true) else Difference.new array_like.generate, actual, type_difference_message(array_like.generate, actual) diff --git a/spec/lib/pact/matchers/matchers_spec.rb b/spec/lib/pact/matchers/matchers_spec.rb index 9725452..14e0013 100644 --- a/spec/lib/pact/matchers/matchers_spec.rb +++ b/spec/lib/pact/matchers/matchers_spec.rb @@ -569,6 +569,24 @@ module Pact::Matchers expect(diff(subject, actual)).to eq({}) end end + + context "when there is a term inside an each like and the expected array is empty" do + subject do + { + data: Pact.each_like({ href: Pact.term('https://example.com/path/to/2019document.pdf', /http.*/ ) }) + } + end + + let(:actual) { { data: [] } } + + it 'should not blow up' do + expect(diff(subject, actual)).to eq ({ + data: [ + Difference.new({ href: 'https://example.com/path/to/2019document.pdf' }, Pact::IndexNotFound.new) + ] + }) + end + end end end end