Skip to content

Commit

Permalink
Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Sep 7, 2024
1 parent af0a266 commit 11a8c5b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
8 changes: 8 additions & 0 deletions lib/protocol/http/body/streamable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ module Body
#
# When invoking `call(stream)`, the stream can be read from and written to, and closed. However, the stream is only guaranteed to be open for the duration of the `call(stream)` call. Once the method returns, the stream **should** be closed by the server.
module Streamable
def self.new(*arguments)
if arguments.size == 1
RequestBody.new(*arguments)
else
ResponseBody.new(*arguments)
end
end

# Represents an output wrapper around a stream, that can invoke a fiber when `#read`` is called.
#
# This behaves a little bit like a generator or lazy enumerator, in that it can be used to generate chunks of data on demand.
Expand Down
9 changes: 5 additions & 4 deletions test/protocol/http/body/streamable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
end
end

let(:input) {nil}
let(:body) {subject.new(block, input)}
let(:body) {subject.new(block)}

with "#stream?" do
it "should be streamable" do
Expand Down Expand Up @@ -75,7 +74,7 @@
end
end

let(:body) {subject.new(block, input)}
let(:body) {subject.new(block)}

it "can close the output body" do
expect(body.read).to be == nil
Expand Down Expand Up @@ -118,7 +117,7 @@

expect(stream.string).to be == "Hello"

body.stream(input)
body.stream(nil)
end
end
end
Expand Down Expand Up @@ -155,6 +154,8 @@
end
end

let(:body) {subject.new(block, input)}

it "can read from input" do
expect(body.read).to be == "Hello"
expect(body.read).to be == " "
Expand Down

0 comments on commit 11a8c5b

Please sign in to comment.