Skip to content

Commit

Permalink
fix: gracefully handle diff between an expected multipart form reques…
Browse files Browse the repository at this point in the history
…t and an actual application/json request

Fixes: #68
  • Loading branch information
bethesque committed Jun 6, 2019
1 parent 721dc31 commit 8577d52
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/pact/shared/multipart_form_differ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ def self.call expected, actual, options = {}
actual_boundary = actual.split.first
actual_with_hardcoded_boundary = actual.gsub(actual_boundary, expected_boundary)
TextDiffer.call(expected, actual_with_hardcoded_boundary, options)
rescue StandardError
TextDiffer.call(expected, actual, options)
end
end
end
14 changes: 12 additions & 2 deletions spec/lib/pact/shared/multipart_form_differ_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

module Pact
describe MultipartFormDiffer do

describe ".call" do

let(:expected_body) do
"-------------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"
end
Expand Down Expand Up @@ -34,6 +32,18 @@ module Pact
expect(subject).to_not eq({})
end
end

context "when the actual is the hash body of application/json request" do
let(:actual_body) do
{
"some" => "hash"
}
end

it "doesn't blow up" do
subject
end
end
end
end
end

0 comments on commit 8577d52

Please sign in to comment.