From 8577d52cb92f364c43629f492664797ad823c7b3 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Fri, 7 Jun 2019 08:27:36 +1000 Subject: [PATCH] fix: gracefully handle diff between an expected multipart form request and an actual application/json request Fixes: https://github.com/pact-foundation/pact-support/issues/68 --- lib/pact/shared/multipart_form_differ.rb | 2 ++ spec/lib/pact/shared/multipart_form_differ_spec.rb | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/pact/shared/multipart_form_differ.rb b/lib/pact/shared/multipart_form_differ.rb index 7191f63..481d0f4 100644 --- a/lib/pact/shared/multipart_form_differ.rb +++ b/lib/pact/shared/multipart_form_differ.rb @@ -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 diff --git a/spec/lib/pact/shared/multipart_form_differ_spec.rb b/spec/lib/pact/shared/multipart_form_differ_spec.rb index baed782..edd6d00 100644 --- a/spec/lib/pact/shared/multipart_form_differ_spec.rb +++ b/spec/lib/pact/shared/multipart_form_differ_spec.rb @@ -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 @@ -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