From 3589479c9f7eb9c4dbe844c54a9b1faf37017a15 Mon Sep 17 00:00:00 2001 From: Charles Rossi Date: Mon, 15 Jun 2026 03:05:00 -0300 Subject: [PATCH] fix(resource): allow puts with no arguments on STDOUT Ruby stdlib puts() with no args prints a blank line. The server-side STDOUT resource required a positional data argument, raising ArgumentError when called as puts(). Change def puts(data) to def puts(data = nil) and call .to_s on data so nil coerces to the empty string, producing the expected blank line. Closes #6 --- .../lib/terminalwire/server/resource.rb | 4 ++-- spec/integration/resources/stdout_spec.rb | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/gem/terminalwire-server/lib/terminalwire/server/resource.rb b/gem/terminalwire-server/lib/terminalwire/server/resource.rb index 51d262f..4679e6c 100644 --- a/gem/terminalwire-server/lib/terminalwire/server/resource.rb +++ b/gem/terminalwire-server/lib/terminalwire/server/resource.rb @@ -36,8 +36,8 @@ def read(name) end class STDOUT < Base - def puts(data) - command("print_line", data: data) + def puts(data = nil) + command("print_line", data: data.to_s) end def print(data) diff --git a/spec/integration/resources/stdout_spec.rb b/spec/integration/resources/stdout_spec.rb index 2b222f5..c4ab027 100644 --- a/spec/integration/resources/stdout_spec.rb +++ b/spec/integration/resources/stdout_spec.rb @@ -18,6 +18,14 @@ it 'prints line with newline to stdout through client' do expect { server_stdout.puts("Hello line") }.to output("Hello line\n").to_stdout end + + it 'prints a blank line when called with no arguments' do + expect { server_stdout.puts }.to output("\n").to_stdout + end + + it 'prints a blank line when called with nil' do + expect { server_stdout.puts(nil) }.to output("\n").to_stdout + end end describe '#flush' do