Skip to content

Commit 8577d52

Browse files
committed
fix: gracefully handle diff between an expected multipart form request and an actual application/json request
Fixes: pact-foundation#68
1 parent 721dc31 commit 8577d52

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/pact/shared/multipart_form_differ.rb

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ def self.call expected, actual, options = {}
99
actual_boundary = actual.split.first
1010
actual_with_hardcoded_boundary = actual.gsub(actual_boundary, expected_boundary)
1111
TextDiffer.call(expected, actual_with_hardcoded_boundary, options)
12+
rescue StandardError
13+
TextDiffer.call(expected, actual, options)
1214
end
1315
end
1416
end

spec/lib/pact/shared/multipart_form_differ_spec.rb

+12-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
module Pact
44
describe MultipartFormDiffer do
5-
65
describe ".call" do
7-
86
let(:expected_body) do
97
"-------------RubyMultipartPost-1e4912957c7bb64de3c444568326663b\r\nContent-Disposition: form-data; name=\"file\"; filename=\"text.txt\"\r\nContent-Length: 14\r\nContent-Type: text/plain\r\nContent-Transfer-Encoding: binary\r\n\r\nThis is a file\r\n-------------RubyMultipartPost-1e4912957c7bb64de3c444568326663b--\r\n\r\n"
108
end
@@ -34,6 +32,18 @@ module Pact
3432
expect(subject).to_not eq({})
3533
end
3634
end
35+
36+
context "when the actual is the hash body of application/json request" do
37+
let(:actual_body) do
38+
{
39+
"some" => "hash"
40+
}
41+
end
42+
43+
it "doesn't blow up" do
44+
subject
45+
end
46+
end
3747
end
3848
end
3949
end

0 commit comments

Comments
 (0)