diff options
author | Jeremy Evans <code@jeremyevans.net> | 2022-08-29 11:21:43 -0700 |
---|---|---|
committer | Jeremy Evans <code@jeremyevans.net> | 2022-08-29 14:58:30 -0700 |
commit | 6fc4a3225289eb2e4b60ed8b4dd250eb74c85936 (patch) | |
tree | fbbf69105c3405b96803319c872880ccc5c2a689 | |
parent | 1a9b98db1f51d91d6c4f0259d61ba94d669c1b73 (diff) | |
download | rack-6fc4a3225289eb2e4b60ed8b4dd250eb74c85936.tar.gz |
Make MockResponse#body work if body.each reuses strings for performance
This passes all specs, but may result in different behavior.
Fixes #1957
-rw-r--r-- | lib/rack/mock_response.rb | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/rack/mock_response.rb b/lib/rack/mock_response.rb index 3142f68a..3c70bb71 100644 --- a/lib/rack/mock_response.rb +++ b/lib/rack/mock_response.rb @@ -45,6 +45,8 @@ module Rack end def body + return @buffered_body if defined?(@buffered_body) + # FIXME: apparently users of MockResponse expect the return value of # MockResponse#body to be a string. However, the real response object # returns the body as a list. @@ -55,9 +57,9 @@ module Rack # ... # res.body.should == "foo!" # end - buffer = String.new + buffer = @buffered_body = String.new - super.each do |chunk| + @body.each do |chunk| buffer << chunk end |