Skip to content

Commit a565a56

Browse files
committed
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: pact-foundation/pact-ruby-standalone#47
1 parent f060482 commit a565a56

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/pact/matchers/matchers.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ def actual_array_diff expected, actual, options
120120
def array_like_diff array_like, actual, options
121121
if actual.is_a? Array
122122
expected_size = [array_like.min, actual.size].max
123-
expected_array = expected_size.times.collect{ Pact::Term.unpack_regexps(array_like.contents) }
123+
# I know changing this is going to break something, but I don't know what it is, as there's no
124+
# test that fails when I make this change. I know the unpack regexps was there for a reason however.
125+
# Guess we'll have to change it and see!
126+
# expected_array = expected_size.times.collect{ Pact::Term.unpack_regexps(array_like.contents) }
127+
expected_array = expected_size.times.collect{ array_like.contents }
124128
actual_array_diff expected_array, actual, options.merge(:type => true)
125129
else
126130
Difference.new array_like.generate, actual, type_difference_message(array_like.generate, actual)

spec/lib/pact/matchers/matchers_spec.rb

+18
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,24 @@ module Pact::Matchers
569569
expect(diff(subject, actual)).to eq({})
570570
end
571571
end
572+
573+
context "when there is a term inside an each like and the expected array is empty" do
574+
subject do
575+
{
576+
data: Pact.each_like({ href: Pact.term('https://example.com/path/to/2019document.pdf', /http.*/ ) })
577+
}
578+
end
579+
580+
let(:actual) { { data: [] } }
581+
582+
it 'should not blow up' do
583+
expect(diff(subject, actual)).to eq ({
584+
data: [
585+
Difference.new({ href: 'https://example.com/path/to/2019document.pdf' }, Pact::IndexNotFound.new)
586+
]
587+
})
588+
end
589+
end
572590
end
573591
end
574592
end

0 commit comments

Comments
 (0)