Skip to content

Commit 9610faa

Browse files
committed
Failing tests.
1 parent 6a6829e commit 9610faa

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

test/protocol/rack/body/enumerable.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55

66
require "protocol/rack/body/enumerable"
77

8+
begin
9+
require "rack"
10+
rescue LoadError
11+
# Rack not available
12+
end
13+
814
describe Protocol::Rack::Body::Enumerable do
915
with "empty body" do
1016
let(:body) {subject.new([], nil)}
@@ -77,4 +83,40 @@
7783
end.to raise_exception(RuntimeError, message: be =~ /Bad Callable/)
7884
end
7985
end
86+
87+
with ".wrap with Rack::BodyProxy", if: defined?(Rack::BodyProxy) do
88+
it "calls close on the body proxy" do
89+
closed = false
90+
rack_body = Rack::BodyProxy.new(["Hello", "World"]) do
91+
closed = true
92+
end
93+
94+
wrapped = subject.wrap(rack_body)
95+
96+
# Consume the body
97+
chunks = []
98+
wrapped.each { |chunk| chunks << chunk }
99+
100+
# The close callback should have been called
101+
expect(closed).to be == true
102+
end
103+
104+
it "calls close even when reading the body" do
105+
closed = false
106+
rack_body = Rack::BodyProxy.new(["Hello", "World"]) do
107+
closed = true
108+
end
109+
110+
wrapped = subject.wrap(rack_body)
111+
112+
# Read all chunks
113+
chunks = []
114+
while chunk = wrapped.read
115+
chunks << chunk
116+
end
117+
118+
# The close callback should have been called
119+
expect(closed).to be == true
120+
end
121+
end
80122
end

0 commit comments

Comments
 (0)