Skip to content

Commit 2ee7cd4

Browse files
committed
Add tests for Writable#<<.
1 parent 6b800cf commit 2ee7cd4

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

test/io/stream/buffered.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,37 @@ def before
247247
end
248248
end
249249

250+
with "#<<" do
251+
it "should append string and return self for method chaining" do
252+
result = server << "Hello"
253+
expect(result).to be_equal(server)
254+
255+
server << " " << "World!"
256+
server.flush
257+
258+
expect(client.read(12)).to be == "Hello World!"
259+
end
260+
261+
it "should write data without explicit flush" do
262+
server.minimum_write_size = 5
263+
264+
expect(server).to receive(:syswrite).once
265+
266+
server << "Hello"
267+
268+
expect(client.read(5)).to be == "Hello"
269+
end
270+
271+
it "should buffer data when below minimum write size" do
272+
server.minimum_write_size = 10
273+
274+
expect(server).not.to receive(:syswrite)
275+
276+
server << "Hi"
277+
# Data should still be in buffer, not flushed
278+
end
279+
end
280+
250281
with "#flush" do
251282
it "should not call write if write buffer is empty" do
252283
expect(server).not.to receive(:syswrite)

0 commit comments

Comments
 (0)