Skip to content

Commit

Permalink
Add test for Response initialized with obj responding to #each
Browse files Browse the repository at this point in the history
  • Loading branch information
mattbrictson committed Jan 30, 2024
1 parent 9b6a823 commit 578243c
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test/spec_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,21 @@ def object_with_each.each
header['content-length'].must_equal '9'
end

it "correctly updates content-length when writing when initialized with object body that responds to #each" do
obj = Object.new
def obj.each
yield 'foo'
yield 'bar'
end
r = Rack::Response.new(obj)
r.write('baz')
r.write('baz')
_, header, body = r.finish
str = "".dup; body.each { |part| str << part }
str.must_equal "foobarbazbaz"
header['content-length'].must_equal '12'
end

it "doesn't return invalid responses" do
r = Rack::Response.new(["foo", "bar"], 204)
_, header, body = r.finish
Expand Down

0 comments on commit 578243c

Please sign in to comment.