From a74035b93d637c9e58a745d2b2d0d0dfe8255a13 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Sun, 10 Nov 2024 00:34:01 +1300 Subject: [PATCH] Restore 100% coverage. --- test/protocol/http/body/stream.rb | 17 +++++++++++++++++ test/protocol/http/body/wrapper.rb | 7 +++++++ 2 files changed, 24 insertions(+) diff --git a/test/protocol/http/body/stream.rb b/test/protocol/http/body/stream.rb index 2eb7caa..0b3b4b2 100644 --- a/test/protocol/http/body/stream.rb +++ b/test/protocol/http/body/stream.rb @@ -164,6 +164,10 @@ expect(stream.read_until("o")).to be == "Hello" expect(stream.read_until("d")).to be == "World" end + + it "can read until a pattern which isn't encountered" do + expect(stream.read_until("X")).to be_nil + end end with "#gets" do @@ -175,6 +179,10 @@ expect(stream.gets).to be == nil end + it "can read up until the limit" do + expect(stream.gets("X", 2)).to be == "He" + end + it "can read lines with limit" do expect(stream.gets(2)).to be == "He" expect(stream.gets(6)).to be == "llo\n" @@ -195,6 +203,15 @@ expect(stream.gets(nil, 4)).to be == "rld\n" expect(stream.gets(nil, 4)).to be == nil end + + with "several chunks" do + let(:input) {Protocol::HTTP::Body::Buffered.new(["Hello ", "World\n"])} + + it "can read lines" do + expect(stream.gets).to be == "Hello World\n" + expect(stream.gets).to be == nil + end + end end with "#close_read" do diff --git a/test/protocol/http/body/wrapper.rb b/test/protocol/http/body/wrapper.rb index 17c2dfe..ad03513 100644 --- a/test/protocol/http/body/wrapper.rb +++ b/test/protocol/http/body/wrapper.rb @@ -60,6 +60,13 @@ end end + with "#buffered" do + it "should proxy buffered" do + expect(source).to receive(:buffered).and_return(true) + expect(body.buffered).to be == true + end + end + with "#rewindable?" do it "should proxy rewindable?" do expect(source).to receive(:rewindable?).and_return(true)