Skip to content

Commit

Permalink
fix: don't blow up when there is a term inside an each like
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bethesque committed Mar 25, 2020
1 parent f060482 commit a565a56
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/pact/matchers/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions spec/lib/pact/matchers/matchers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a565a56

Please sign in to comment.