File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55
66require "protocol/rack/body/enumerable"
77
8+ begin
9+ require "rack"
10+ rescue LoadError
11+ # Rack not available
12+ end
13+
814describe Protocol ::Rack ::Body ::Enumerable do
915 with "empty body" do
1016 let ( :body ) { subject . new ( [ ] , nil ) }
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
80122end
You can’t perform that action at this time.
0 commit comments