Skip to content

Commit cfb0259

Browse files
authored
Merge pull request #104 from lextiz/patch-1
feat: improve logging robustness for non utf-8 characters
2 parents 3c26b46 + e3cd33f commit cfb0259

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/pact/mock_service/request_handlers/interaction_replay.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ module RequestHandlers
1313
module PrettyGenerate
1414
#Doesn't seem to reliably pretty generate unless we go to JSON and back again :(
1515
def pretty_generate object
16-
JSON.pretty_generate(JSON.parse(object.to_json))
16+
begin
17+
JSON.pretty_generate(JSON.parse(object.to_json))
18+
rescue
19+
object.to_s
20+
end
1721
end
1822
end
1923

spec/lib/pact/mock_service/request_handlers/interaction_replay_spec.rb

+12
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,18 @@ module RequestHandlers
143143
end
144144
end
145145
end
146+
147+
context "when the body contains special charachters" do
148+
let(:actual_body) { '\xEB' }
149+
150+
let(:expected_response_body) do
151+
{"message"=>"No interaction found for GET /path", "interaction_diffs"=>[{"body"=>{"ACTUAL"=>"\\xEB", "EXPECTED"=>{"a"=>"body"}}, "description"=>"a request"}]}
152+
end
153+
154+
it "returns the specified response status" do
155+
expect(response_status).to eq 500
156+
end
157+
end
146158
end
147159

148160
context "when no request is found with a matching method and path" do

0 commit comments

Comments
 (0)