Skip to content

Commit 375b6cc

Browse files
committed
Add tests for Stream#close_read.
1 parent 4764c5a commit 375b6cc

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/protocol/http/body/stream.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ def flush
148148

149149
def close_read
150150
@closed_read = true
151+
@buffer = nil
152+
151153
@input&.close
152154
@input = nil
153155
end

test/protocol/http/body/stream.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@
1111
let(:output) {Protocol::HTTP::Body::Buffered.new}
1212
let(:stream) {subject.new(input, output)}
1313

14+
with 'no input' do
15+
let(:input) {nil}
16+
17+
it "should be empty" do
18+
expect(stream).to be(:empty?)
19+
end
20+
21+
it "should read nothing" do
22+
expect(stream.read).to be == ""
23+
end
24+
end
25+
1426
with '#empty?' do
1527
it "should be empty" do
1628
expect(stream).to be(:empty?)
@@ -113,8 +125,9 @@
113125

114126
with '#close_read' do
115127
it "should close the input" do
128+
stream.read(1)
116129
stream.close_read
117-
expect{stream.read(5)}.to raise_exception(IOError)
130+
expect{stream.read(1)}.to raise_exception(IOError)
118131
end
119132
end
120133

0 commit comments

Comments
 (0)