From 239c163f25b8e2cab00931182e888e0da7d15367 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Thu, 30 May 2019 14:21:35 +0200 Subject: [PATCH] Add specs for xProcess#write --- spec/aruba/processes/in_process_spec.rb | 28 ++++++++++++++++++++++ spec/aruba/processes/spawn_process_spec.rb | 20 ++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/spec/aruba/processes/in_process_spec.rb b/spec/aruba/processes/in_process_spec.rb index ca275084d..8fb7d0902 100644 --- a/spec/aruba/processes/in_process_spec.rb +++ b/spec/aruba/processes/in_process_spec.rb @@ -29,6 +29,16 @@ def execute! end end + let(:stdin_runner) do + Class.new(base_runner) do + def execute! + @stdin.rewind + item = @stdin.gets.to_s.chomp + @stdout.puts "Hello, #{item}!" + end + end + end + let(:failed_runner) do Class.new(base_runner) do def execute! @@ -141,4 +151,22 @@ def run_process(&block) .to raise_error(TypeError, "no implicit conversion of String into Integer") end end + + describe '#write' do + let(:main_class) { stdin_runner } + + it 'writes single strings to the process' do + process.write "World" + process.start + process.stop + expect(process.stdout).to eq "Hello, World!\n" + end + + it 'writes multiple strings to the process' do + process.write "Wor", "ld" + process.start + process.stop + expect(process.stdout).to eq "Hello, World!\n" + end + end end diff --git a/spec/aruba/processes/spawn_process_spec.rb b/spec/aruba/processes/spawn_process_spec.rb index 920761369..84dbe2eca 100644 --- a/spec/aruba/processes/spawn_process_spec.rb +++ b/spec/aruba/processes/spawn_process_spec.rb @@ -45,6 +45,26 @@ end end + describe '#write' do + let(:command_line) { "ruby -e 'puts gets'" } + + it 'writes single strings to the process' do + process.start + process.write "hello\n" + process.stop + + expect(process.stdout).to eq "hello\n" + end + + it 'writes multiple strings to the process' do + process.start + process.write "hel", "lo\n" + process.stop + + expect(process.stdout).to eq "hello\n" + end + end + describe "#stop" do before { process.start }