@@ -126,6 +126,41 @@ def body.each
126126 end
127127 end
128128
129+ with "array body" do
130+ it "wraps array body and returns chunks via #read" do
131+ result = subject . wrap ( env , 200 , headers , [ "Hello" , " " , "World" ] )
132+
133+ expect ( result ) . not . to be_nil
134+ expect ( result . read ) . to be == "Hello"
135+ expect ( result . read ) . to be == " "
136+ expect ( result . read ) . to be == "World"
137+ expect ( result . read ) . to be_nil
138+ end
139+
140+ it "wraps array body and yields chunks via #each" do
141+ result = subject . wrap ( env , 200 , headers , [ "chunk1" , "chunk2" ] )
142+ chunks = [ ]
143+ result . each { |chunk | chunks << chunk }
144+
145+ expect ( chunks ) . to be == [ "chunk1" , "chunk2" ]
146+ end
147+
148+ it "wraps empty array body" do
149+ result = subject . wrap ( env , 200 , headers , [ ] )
150+
151+ expect ( result ) . not . to be_nil
152+ expect ( result ) . to be ( :empty? )
153+ expect ( result . read ) . to be_nil
154+ end
155+
156+ it "uses content-length when provided" do
157+ headers [ "content-length" ] = "11"
158+ result = subject . wrap ( env , 200 , headers , [ "Hello" , " World" ] )
159+
160+ expect ( result . length ) . to be == 11
161+ end
162+ end
163+
129164 with "response finished callback" do
130165 it "returns a body that calls the callback when closed" do
131166 called = false
0 commit comments