Skip to content

Commit a2614c7

Browse files
Add test for failed enumerable stream.
1 parent ac6beb4 commit a2614c7

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/protocol/rack/body/enumerable.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,10 @@ def stream?
107107
# @parameter stream [Object] The stream to write the body to.
108108
def call(stream)
109109
@body.call(stream)
110+
rescue => error
111+
raise
110112
ensure
111-
self.close($!)
113+
self.close(error)
112114
end
113115

114116
# Read the next chunk from the response body.

test/protocol/rack/body/enumerable.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,22 @@
4141
end.to raise_exception(RuntimeError, message: be =~ /Bad Enumerable/)
4242
end
4343
end
44+
45+
with "#call" do
46+
let(:bad_callable) do
47+
proc do |stream|
48+
raise "Bad Callable"
49+
end
50+
end
51+
52+
let(:body) {subject.new(bad_callable, 1)}
53+
54+
it "streams the body" do
55+
expect(body).to receive(:close)
56+
57+
expect do
58+
body.call(nil)
59+
end.to raise_exception(RuntimeError, message: be =~ /Bad Callable/)
60+
end
61+
end
4462
end

0 commit comments

Comments
 (0)