Skip to content

Commit

Permalink
The default stubbed response body, which is an empty String, is utf-8…
Browse files Browse the repository at this point in the history
… encoded.
  • Loading branch information
bblimke committed Feb 5, 2024
1 parent 25934a1 commit 39ef745
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/webmock/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def headers=(headers)
end

def body
@body || String.new
@body || String.new("")
end

def body=(body)
Expand Down
4 changes: 4 additions & 0 deletions spec/unit/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@
expect(@response.body).to_not be_frozen
end

it "shoud return utf-8 encoded string by default" do
expect(@response.body.encoding).to eq(Encoding::UTF_8)
end

it "should report body if assigned" do
@response = WebMock::Response.new(body: "abc")
expect(@response.body).to eq("abc")
Expand Down

0 comments on commit 39ef745

Please sign in to comment.