diff --git a/lib/pact/mock_service/request_handlers/interaction_replay.rb b/lib/pact/mock_service/request_handlers/interaction_replay.rb index 09986ab..0e201d3 100644 --- a/lib/pact/mock_service/request_handlers/interaction_replay.rb +++ b/lib/pact/mock_service/request_handlers/interaction_replay.rb @@ -13,7 +13,11 @@ module RequestHandlers module PrettyGenerate #Doesn't seem to reliably pretty generate unless we go to JSON and back again :( def pretty_generate object - JSON.pretty_generate(JSON.parse(object.to_json)) + begin + JSON.pretty_generate(JSON.parse(object.to_json)) + rescue + object.to_s + end end end diff --git a/spec/lib/pact/mock_service/request_handlers/interaction_replay_spec.rb b/spec/lib/pact/mock_service/request_handlers/interaction_replay_spec.rb index 3bb5677..dbd116e 100644 --- a/spec/lib/pact/mock_service/request_handlers/interaction_replay_spec.rb +++ b/spec/lib/pact/mock_service/request_handlers/interaction_replay_spec.rb @@ -143,6 +143,18 @@ module RequestHandlers end end end + + context "when the body contains special charachters" do + let(:actual_body) { '\xEB' } + + let(:expected_response_body) do + {"message"=>"No interaction found for GET /path", "interaction_diffs"=>[{"body"=>{"ACTUAL"=>"\\xEB", "EXPECTED"=>{"a"=>"body"}}, "description"=>"a request"}]} + end + + it "returns the specified response status" do + expect(response_status).to eq 500 + end + end end context "when no request is found with a matching method and path" do