File tree 2 files changed +30
-12
lines changed
2 files changed +30
-12
lines changed Original file line number Diff line number Diff line change @@ -47,14 +47,11 @@ def initialize(input, block)
47
47
@fiber = Fiber . new do |from |
48
48
@from = from
49
49
block . call ( stream )
50
+ rescue => error
51
+ # Ignore.
50
52
ensure
51
53
@fiber = nil
52
-
53
- # No more chunks will be generated:
54
- if from = @from
55
- @from = nil
56
- from . transfer ( nil )
57
- end
54
+ self . close ( error )
58
55
end
59
56
end
60
57
@@ -182,10 +179,6 @@ def stream(input)
182
179
@input &.write ( chunk )
183
180
end
184
181
@input &.close_write
185
- rescue => error
186
- raise
187
- ensure
188
- self . close ( error )
189
182
end
190
183
end
191
184
end
Original file line number Diff line number Diff line change 127
127
128
128
it "closes the stream if an error occurs" do
129
129
stream = StringIO . new
130
- expect ( body ) . to receive ( :close )
131
130
132
131
expect do
133
132
body . call ( stream )
136
135
expect ( stream . string ) . to be == "Hello"
137
136
138
137
body . stream ( nil )
138
+ body . close
139
139
end
140
140
end
141
141
end
149
149
150
150
it "can raise an error on the block" do
151
151
expect ( body . read ) . to be == "Hello"
152
- body . close ( RuntimeError . new ( "Oh no!" ) )
152
+
153
+ expect do
154
+ body . close ( RuntimeError . new ( "Oh no!" ) )
155
+ end . to raise_exception ( RuntimeError , message : be =~ /Oh no!/ )
153
156
end
154
157
end
155
158
202
205
end
203
206
end
204
207
end
208
+
209
+ with "#stream" do
210
+ let ( :block ) do
211
+ proc do |stream |
212
+ while chunk = stream . read_partial
213
+ stream . write ( chunk )
214
+ end
215
+ end
216
+ end
217
+
218
+ it "can stream to output" do
219
+ input = Protocol ::HTTP ::Body ::Buffered . new ( [ "Hello" , " " , "World" ] )
220
+
221
+ body . stream ( input )
222
+
223
+ expect ( body . read ) . to be == "Hello"
224
+ expect ( body . read ) . to be == " "
225
+ expect ( body . read ) . to be == "World"
226
+
227
+ body . close
228
+ end
229
+ end
205
230
end
You can’t perform that action at this time.
0 commit comments