From 1835b0fa15bd7270f1cb871e3bfc23c1870bf427 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sat, 18 May 2019 19:11:41 +0200 Subject: [PATCH 1/5] Allow multiple arguments to xProcess#write --- lib/aruba/api/commands.rb | 2 +- lib/aruba/processes/in_process.rb | 9 ++++----- lib/aruba/processes/spawn_process.rb | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/aruba/api/commands.rb b/lib/aruba/api/commands.rb index 7997cf75a..9d2067c7a 100644 --- a/lib/aruba/api/commands.rb +++ b/lib/aruba/api/commands.rb @@ -210,7 +210,7 @@ def run_command_and_stop(cmd, opts = {}) def type(input) return close_input if input == "\u0004" - last_command_started.write(input << "\n") + last_command_started.write(input, "\n") end # Close stdin diff --git a/lib/aruba/processes/in_process.rb b/lib/aruba/processes/in_process.rb index 96c332e65..0260db717 100644 --- a/lib/aruba/processes/in_process.rb +++ b/lib/aruba/processes/in_process.rb @@ -99,12 +99,11 @@ def stderr(*) @stderr.string end - # Write strint to stdin + # Write strings to stdin # - # @param [String] input - # Write string to stdin in - def write(input) - @stdin.write input + # @param *input [Array of String] + def write(*input) + @stdin.write *input end # Close io diff --git a/lib/aruba/processes/spawn_process.rb b/lib/aruba/processes/spawn_process.rb index 19b3fbd88..541491200 100644 --- a/lib/aruba/processes/spawn_process.rb +++ b/lib/aruba/processes/spawn_process.rb @@ -155,10 +155,10 @@ def stderr(opts = {}) end end - def write(input) + def write(*input) return if stopped? - @process.io.stdin.write(input) + @process.io.stdin.write(*input) @process.io.stdin.flush self From 2781e975c94e00b790ad02ded482596694358b63 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Thu, 30 May 2019 14:15:02 +0200 Subject: [PATCH 2/5] Fix some BasicProcess method implementations --- spec/aruba/processes/basic_process_spec.rb | 72 ++++++++++++++-------- 1 file changed, 46 insertions(+), 26 deletions(-) diff --git a/spec/aruba/processes/basic_process_spec.rb b/spec/aruba/processes/basic_process_spec.rb index 0311c0092..815f1ce14 100644 --- a/spec/aruba/processes/basic_process_spec.rb +++ b/spec/aruba/processes/basic_process_spec.rb @@ -1,35 +1,37 @@ require "spec_helper" RSpec.describe Aruba::Processes::BasicProcess do - let(:process) do - Class.new(described_class) do - def initialize(*args) - @stdout = args.shift - @stderr = args.shift - super(*args) - end - - def stdout(*_args) - @stdout - end - - def stderr(*_args) - @stderr - end - end.new(stdout, stderr, cmd, exit_timeout, io_wait_timeout, working_directory) - end - let(:cmd) { "foobar" } let(:exit_timeout) { 0 } let(:io_wait_timeout) { 0 } let(:working_directory) { Dir.pwd } - let(:stdout) { "foo output" } - let(:stderr) { "foo error output" } + let(:process) { described_class.new(cmd, exit_timeout, io_wait_timeout, working_directory) } + + describe '#inspect' do + let(:stdout) { 'foo output' } + let(:stderr) { 'foo error output' } + + let(:derived_process) do + Class.new(described_class) do + def initialize(*args) + @stdout = args.shift + @stderr = args.shift + super(*args) + end - describe "#inspect" do - it "shows useful info" do + def stdout(*_args) + @stdout + end + + def stderr(*_args) + @stderr + end + end.new(stdout, stderr, cmd, exit_timeout, io_wait_timeout, working_directory) + end + + it 'shows useful info' do expected = /commandline="foobar": stdout="foo output" stderr="foo error output"/ - expect(process.inspect).to match(expected) + expect(derived_process.inspect).to match(expected) end context "with no stdout" do @@ -37,7 +39,7 @@ def stderr(*_args) it "shows useful info" do expected = /commandline="foobar": stdout=nil stderr="foo error output"/ - expect(process.inspect).to match(expected) + expect(derived_process.inspect).to match(expected) end end @@ -46,7 +48,7 @@ def stderr(*_args) it "shows useful info" do expected = /commandline="foobar": stdout="foo output" stderr=nil/ - expect(process.inspect).to match(expected) + expect(derived_process.inspect).to match(expected) end end @@ -56,8 +58,26 @@ def stderr(*_args) it "shows useful info" do expected = /commandline="foobar": stdout=nil stderr=nil/ - expect(process.inspect).to match(expected) + expect(derived_process.inspect).to match(expected) end end end + + describe '#stdin' do + it 'raises NotImplementedError' do + expect { process.stdin }.to raise_error NotImplementedError + end + end + + describe '#stdout' do + it 'raises NotImplementedError' do + expect { process.stdout }.to raise_error NotImplementedError + end + end + + describe '#stderr' do + it 'raises NotImplementedError' do + expect { process.stderr }.to raise_error NotImplementedError + end + end end From 239c163f25b8e2cab00931182e888e0da7d15367 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Thu, 30 May 2019 14:21:35 +0200 Subject: [PATCH 3/5] 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 } From 2660b3dca0b3a5c88eec74e56034a964b97635e8 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Thu, 30 May 2019 14:24:41 +0200 Subject: [PATCH 4/5] Correct RuboCop offenses --- lib/aruba/processes/in_process.rb | 2 +- spec/aruba/processes/in_process_spec.rb | 4 ++-- spec/aruba/processes/spawn_process_spec.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/aruba/processes/in_process.rb b/lib/aruba/processes/in_process.rb index 0260db717..f5b387dd8 100644 --- a/lib/aruba/processes/in_process.rb +++ b/lib/aruba/processes/in_process.rb @@ -103,7 +103,7 @@ def stderr(*) # # @param *input [Array of String] def write(*input) - @stdin.write *input + @stdin.write(*input) end # Close io diff --git a/spec/aruba/processes/in_process_spec.rb b/spec/aruba/processes/in_process_spec.rb index 8fb7d0902..51483f835 100644 --- a/spec/aruba/processes/in_process_spec.rb +++ b/spec/aruba/processes/in_process_spec.rb @@ -156,14 +156,14 @@ def run_process(&block) let(:main_class) { stdin_runner } it 'writes single strings to the process' do - process.write "World" + 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.write 'Wor', 'ld' process.start process.stop expect(process.stdout).to eq "Hello, World!\n" diff --git a/spec/aruba/processes/spawn_process_spec.rb b/spec/aruba/processes/spawn_process_spec.rb index 84dbe2eca..377073e9e 100644 --- a/spec/aruba/processes/spawn_process_spec.rb +++ b/spec/aruba/processes/spawn_process_spec.rb @@ -58,7 +58,7 @@ it 'writes multiple strings to the process' do process.start - process.write "hel", "lo\n" + process.write 'hel', "lo\n" process.stop expect(process.stdout).to eq "hello\n" From 8fde2962fb97a9198ee1322cefc2797c2365be85 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sat, 1 Jun 2019 09:13:13 +0200 Subject: [PATCH 5/5] Fix YARD syntax for array of strings Co-Authored-By: Olle Jonsson --- lib/aruba/processes/in_process.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/aruba/processes/in_process.rb b/lib/aruba/processes/in_process.rb index f5b387dd8..bbe00590f 100644 --- a/lib/aruba/processes/in_process.rb +++ b/lib/aruba/processes/in_process.rb @@ -101,7 +101,7 @@ def stderr(*) # Write strings to stdin # - # @param *input [Array of String] + # @param *input [Array] def write(*input) @stdin.write(*input) end