From 19fe24cc0395f743c05644cd516d3436e52e8868 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Tue, 7 Nov 2017 09:57:02 +0100 Subject: [PATCH 01/24] Test on appveyor only with Ruby 2.0 and up - The fat binaries for the ffi gem do not support Ruby 1.9.3, hence testing on this version on Windows makes no sense. - To set Ruby version 2.0.0, the micro version also needs to be set. --- appveyor.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 2d6618705..852b08abb 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -24,8 +24,7 @@ test_script: environment: matrix: - - ruby_version: '19' - - ruby_version: '20' + - ruby_version: '200' - ruby_version: '21' - ruby_version: '22' From 45f9f46d5079a35002182e828509e2711a5de5ff Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Wed, 8 Nov 2017 08:22:24 +0100 Subject: [PATCH 02/24] Wrap long lines --- lib/aruba/processes/basic_process.rb | 4 +++- lib/aruba/processes/spawn_process.rb | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/aruba/processes/basic_process.rb b/lib/aruba/processes/basic_process.rb index 93970a333..824b9dbf2 100644 --- a/lib/aruba/processes/basic_process.rb +++ b/lib/aruba/processes/basic_process.rb @@ -14,7 +14,9 @@ class BasicProcess attr_reader :exit_status, :environment, :working_directory, :main_class, :io_wait_timeout, :exit_timeout, :startup_wait_time, :stop_signal - def initialize(cmd, exit_timeout, io_wait_timeout, working_directory, environment = ENV.to_hash.dup, main_class = nil, stop_signal = nil, startup_wait_time = 0) + def initialize(cmd, exit_timeout, io_wait_timeout, working_directory, + environment = ENV.to_hash.dup, + main_class = nil, stop_signal = nil, startup_wait_time = 0) @cmd = cmd @working_directory = working_directory @environment = environment diff --git a/lib/aruba/processes/spawn_process.rb b/lib/aruba/processes/spawn_process.rb index 4e4a48b2a..b84c127ec 100644 --- a/lib/aruba/processes/spawn_process.rb +++ b/lib/aruba/processes/spawn_process.rb @@ -48,7 +48,9 @@ def self.match?(_mode) # # @param [Numeric] startup_wait_time # The amount of seconds to wait after Aruba has started a command. - def initialize(cmd, exit_timeout, io_wait_timeout, working_directory, environment = ENV.to_hash.dup, main_class = nil, stop_signal = nil, startup_wait_time = 0) + def initialize(cmd, exit_timeout, io_wait_timeout, working_directory, + environment = ENV.to_hash.dup, + main_class = nil, stop_signal = nil, startup_wait_time = 0) super @process = nil From 113d5cf7ff7a7b9a1800a93219661dc838254b75 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Wed, 8 Nov 2017 08:26:01 +0100 Subject: [PATCH 03/24] Remove trailing blank space --- .../command_runtime_environment.feature | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/features/02_configure_aruba/command_runtime_environment.feature b/features/02_configure_aruba/command_runtime_environment.feature index 1d1cc337c..a3cf1cee9 100644 --- a/features/02_configure_aruba/command_runtime_environment.feature +++ b/features/02_configure_aruba/command_runtime_environment.feature @@ -23,7 +23,7 @@ Feature: Define default process environment ENV['LONG_LONG_VARIABLE'] = 'y' Aruba.configure do |config| - config.command_runtime_environment = { 'LONG_LONG_VARIABLE' => 'x' } + config.command_runtime_environment = { 'LONG_LONG_VARIABLE' => 'x' } end RSpec.describe 'Environment command', :type => :aruba do @@ -44,7 +44,7 @@ Feature: Define default process environment ENV['LONG_LONG_VARIABLE'] = 'y' Aruba.configure do |config| - config.command_runtime_environment = { 'LONG_LONG_VARIABLE' => 'x' } + config.command_runtime_environment = { 'LONG_LONG_VARIABLE' => 'x' } end RSpec.describe 'Environment command', :type => :aruba do @@ -67,7 +67,7 @@ Feature: Define default process environment ENV['LONG_LONG_VARIABLE'] = 'y' Aruba.configure do |config| - config.command_runtime_environment = { 'LONG_LONG_VARIABLE' => 'x' } + config.command_runtime_environment = { 'LONG_LONG_VARIABLE' => 'x' } end RSpec.describe 'Environment command', :type => :aruba do @@ -90,7 +90,7 @@ Feature: Define default process environment ENV['LONG_LONG_VARIABLE'] = 'y' Aruba.configure do |config| - config.command_runtime_environment = { 'LONG_LONG_VARIABLE' => 'x' } + config.command_runtime_environment = { 'LONG_LONG_VARIABLE' => 'x' } end RSpec.describe 'Environment command', :type => :aruba do @@ -113,7 +113,7 @@ Feature: Define default process environment ENV['LONG_LONG_VARIABLE'] = 'y' Aruba.configure do |config| - config.command_runtime_environment = { 'LONG_LONG_VARIABLE' => 'x' } + config.command_runtime_environment = { 'LONG_LONG_VARIABLE' => 'x' } end RSpec.describe 'Environment command', :type => :aruba do From eb645e49e200e626ae246ad2d8c3acc90566fc99 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Wed, 8 Nov 2017 08:26:15 +0100 Subject: [PATCH 04/24] Make command_runtime_environment blank by default The existing default is not needed, since ENV is always used as a base for the local environment. --- lib/aruba/configuration.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/aruba/configuration.rb b/lib/aruba/configuration.rb index 14be27866..ce3953fda 100644 --- a/lib/aruba/configuration.rb +++ b/lib/aruba/configuration.rb @@ -28,7 +28,7 @@ class Configuration < BasicConfiguration option_accessor :io_wait_timeout, contract: { Num => Num }, default: 0.1 option_accessor :startup_wait_time, contract: { Num => Num }, default: 0 option_accessor :fixtures_directories, contract: { Array => ArrayOf[String] }, default: %w(features/fixtures spec/fixtures test/fixtures fixtures) - option_accessor :command_runtime_environment, contract: { Hash => Hash }, default: ENV.to_hash + option_accessor :command_runtime_environment, contract: { Hash => Hash }, default: {} # rubocop:disable Metrics/LineLength option_accessor(:command_search_paths, contract: { ArrayOf[String] => ArrayOf[String] }) { |config| [File.join(config.root_directory.value, 'bin'), File.join(config.root_directory.value, 'exe')] } # rubocop:enable Metrics/LineLength From f5a8fba44c848109d1475ba877c79e3576a07d78 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Wed, 8 Nov 2017 08:39:31 +0100 Subject: [PATCH 05/24] Clean up environment variable handling - Use inject on all versions of Ruby, not need to make a distinction here. - Clean up overrides in WindowsEnvironmentVariables - Override to_h in WindowsEnvironmentVariables so it correctly upcases ENV values. --- .../platforms/unix_environment_variables.rb | 18 ++--------------- .../windows_environment_variables.rb | 20 ++++++++++++------- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/lib/aruba/platforms/unix_environment_variables.rb b/lib/aruba/platforms/unix_environment_variables.rb index 964a270de..84b558e12 100644 --- a/lib/aruba/platforms/unix_environment_variables.rb +++ b/lib/aruba/platforms/unix_environment_variables.rb @@ -73,7 +73,7 @@ def initialize(env = ENV) def update(other_env) actions << UpdateAction.new(other_env) - UnixEnvironmentVariables.new(to_h) + self end # Fetch variable from environment @@ -184,11 +184,7 @@ def respond_to_missing?(name, _private) # @return [Hash] # A new hash from environment def to_h - if RUBY_VERSION < '2.0' - Marshal.load(Marshal.dump(prepared_environment.to_hash)) - else - Marshal.load(Marshal.dump(prepared_environment.to_h)) - end + actions.inject(ENV.to_hash.merge(env)) { |a, e| e.call(a) } end # Reset environment @@ -199,16 +195,6 @@ def clear value end - - private - - def prepared_environment - if RUBY_VERSION == '1.9.3' - actions.inject(ENV.to_hash.merge(env)) { |a, e| e.call(a) } - else - actions.each_with_object(ENV.to_hash.merge(env)) { |e, a| a = e.call(a) } - end - end end end end diff --git a/lib/aruba/platforms/windows_environment_variables.rb b/lib/aruba/platforms/windows_environment_variables.rb index d782fcae2..c8d4c33c2 100644 --- a/lib/aruba/platforms/windows_environment_variables.rb +++ b/lib/aruba/platforms/windows_environment_variables.rb @@ -28,16 +28,12 @@ module Platforms # env["PATH"] # # => nil class WindowsEnvironmentVariables < UnixEnvironmentVariables - def initialize(env = ENV.to_hash) - @actions = [] - - @env = env.each_with_object({}) { |(k, v), a| a[k.to_s.upcase] = v } + def initialize(env = ENV) + super(upcase_env env) end def update(other_env, &block) - other_env = other_env.each_with_object({}) { |(k, v), a| a[k.to_s.upcase] = v } - - super(other_env, &block) + super(upcase_env(other_env), &block) end def fetch(name, default = UnixEnvironmentVariables::UNDEFINED) @@ -67,6 +63,16 @@ def prepend(name, value) def delete(name) super(name.upcase) end + + def to_h + actions.inject(upcase_env(ENV).merge(env)) { |a, e| e.call(a) } + end + + private + + def upcase_env(env) + env.each_with_object({}) { |(k, v), a| a[k.to_s.upcase] = v } + end end end end From 6b51f06dabdfc78387b56546afbcc7b98671b405 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Wed, 8 Nov 2017 08:42:26 +0100 Subject: [PATCH 06/24] Remove parameters with defaults SpawnProcess should work without specifying these, and there are no specs that essentially override these defaults. --- spec/aruba/processes/spawn_process_spec.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/spec/aruba/processes/spawn_process_spec.rb b/spec/aruba/processes/spawn_process_spec.rb index 664d82ac1..2e0b3461e 100644 --- a/spec/aruba/processes/spawn_process_spec.rb +++ b/spec/aruba/processes/spawn_process_spec.rb @@ -1,14 +1,12 @@ require 'spec_helper' RSpec.describe Aruba::Processes::SpawnProcess do - subject(:process) { described_class.new(command, exit_timeout, io_wait, working_directory, environment, main_class) } + subject(:process) { described_class.new(command, exit_timeout, io_wait, working_directory) } let(:command) { 'echo "yo"' } let(:exit_timeout) { 1 } let(:io_wait) { 1 } let(:working_directory) { Dir.getwd } - let(:environment) { ENV.to_hash.dup } - let(:main_class) { nil } describe "#stdout" do before(:each) { process.start } From e871767cc10acc83ce7dd4a66a4505c03ab5e76f Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Wed, 8 Nov 2017 09:04:52 +0100 Subject: [PATCH 07/24] Replace ENV.to_hash with platform-specific code --- lib/aruba/platforms/local_environment.rb | 2 +- lib/aruba/platforms/unix_environment_variables.rb | 12 +++++++++++- lib/aruba/platforms/windows_environment_variables.rb | 10 +++++++--- lib/aruba/processes/basic_process.rb | 2 +- lib/aruba/processes/in_process.rb | 4 +++- lib/aruba/processes/spawn_process.rb | 2 +- 6 files changed, 24 insertions(+), 8 deletions(-) diff --git a/lib/aruba/platforms/local_environment.rb b/lib/aruba/platforms/local_environment.rb index 3f6d638df..2f5403289 100644 --- a/lib/aruba/platforms/local_environment.rb +++ b/lib/aruba/platforms/local_environment.rb @@ -14,7 +14,7 @@ class LocalEnvironment # @yield # The block of code which should with local ENV def call(env) - old_env = ENV.to_hash.dup + old_env = Aruba.platform.environment_variables.hash_from_env ENV.clear ENV.update env diff --git a/lib/aruba/platforms/unix_environment_variables.rb b/lib/aruba/platforms/unix_environment_variables.rb index 84b558e12..9e68b75a6 100644 --- a/lib/aruba/platforms/unix_environment_variables.rb +++ b/lib/aruba/platforms/unix_environment_variables.rb @@ -184,7 +184,7 @@ def respond_to_missing?(name, _private) # @return [Hash] # A new hash from environment def to_h - actions.inject(ENV.to_hash.merge(env)) { |a, e| e.call(a) } + actions.inject(hash_from_env.merge(env)) { |a, e| e.call(a) } end # Reset environment @@ -195,6 +195,16 @@ def clear value end + + def self.hash_from_env + ENV.to_hash + end + + private + + def hash_from_env + self.class.hash_from_env + end end end end diff --git a/lib/aruba/platforms/windows_environment_variables.rb b/lib/aruba/platforms/windows_environment_variables.rb index c8d4c33c2..96b11dd1d 100644 --- a/lib/aruba/platforms/windows_environment_variables.rb +++ b/lib/aruba/platforms/windows_environment_variables.rb @@ -64,14 +64,18 @@ def delete(name) super(name.upcase) end - def to_h - actions.inject(upcase_env(ENV).merge(env)) { |a, e| e.call(a) } + def self.hash_from_env + upcase_env(ENV) + end + + def self.upcase_env(env) + env.each_with_object({}) { |(k, v), a| a[k.to_s.upcase] = v } end private def upcase_env(env) - env.each_with_object({}) { |(k, v), a| a[k.to_s.upcase] = v } + self.class.upcase_env(env) end end end diff --git a/lib/aruba/processes/basic_process.rb b/lib/aruba/processes/basic_process.rb index 824b9dbf2..177ab8c40 100644 --- a/lib/aruba/processes/basic_process.rb +++ b/lib/aruba/processes/basic_process.rb @@ -15,7 +15,7 @@ class BasicProcess :io_wait_timeout, :exit_timeout, :startup_wait_time, :stop_signal def initialize(cmd, exit_timeout, io_wait_timeout, working_directory, - environment = ENV.to_hash.dup, + environment = Aruba.platform.environment_variables.hash_from_env, main_class = nil, stop_signal = nil, startup_wait_time = 0) @cmd = cmd @working_directory = working_directory diff --git a/lib/aruba/processes/in_process.rb b/lib/aruba/processes/in_process.rb index 4c578ccb5..db1ce31b6 100644 --- a/lib/aruba/processes/in_process.rb +++ b/lib/aruba/processes/in_process.rb @@ -40,7 +40,9 @@ def exit(exitstatus) # @private attr_reader :main_class - def initialize(cmd, exit_timeout, io_wait_timeout, working_directory, environment = ENV.to_hash.dup, main_class = nil, stop_signal = nil, startup_wait_time = 0) + def initialize(cmd, exit_timeout, io_wait_timeout, working_directory, + environment = Aruba.platform.environment_variables.hash_from_env, + main_class = nil, stop_signal = nil, startup_wait_time = 0) @cmd = cmd @argv = arguments @stdin = StringIO.new diff --git a/lib/aruba/processes/spawn_process.rb b/lib/aruba/processes/spawn_process.rb index b84c127ec..8ec8bcf22 100644 --- a/lib/aruba/processes/spawn_process.rb +++ b/lib/aruba/processes/spawn_process.rb @@ -49,7 +49,7 @@ def self.match?(_mode) # @param [Numeric] startup_wait_time # The amount of seconds to wait after Aruba has started a command. def initialize(cmd, exit_timeout, io_wait_timeout, working_directory, - environment = ENV.to_hash.dup, + environment = Aruba.platform.environment_variables.hash_from_env, main_class = nil, stop_signal = nil, startup_wait_time = 0) super From 5073f66b93d0d101e314866c4e7ead5cf033cdcc Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Wed, 8 Nov 2017 13:56:14 +0100 Subject: [PATCH 08/24] Simplify specs for stderr handling Instead of setting up or using a shell script, just use Ruby with a script on the command line. --- fixtures/spawn_process/stderr.sh | 3 -- spec/aruba/matchers/command_spec.rb | 45 ++-------------------- spec/aruba/processes/spawn_process_spec.rb | 2 +- 3 files changed, 4 insertions(+), 46 deletions(-) delete mode 100755 fixtures/spawn_process/stderr.sh diff --git a/fixtures/spawn_process/stderr.sh b/fixtures/spawn_process/stderr.sh deleted file mode 100755 index f42392209..000000000 --- a/fixtures/spawn_process/stderr.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -echo $* >&2 diff --git a/spec/aruba/matchers/command_spec.rb b/spec/aruba/matchers/command_spec.rb index 68e76f1b9..ed6d5b699 100644 --- a/spec/aruba/matchers/command_spec.rb +++ b/spec/aruba/matchers/command_spec.rb @@ -71,20 +71,7 @@ def announcer(*args) end context 'when have output hello world on stderr' do - before :each do - string = <<-EOS.strip_heredoc - #!/usr/bin/env bash - - echo $* >&2 - EOS - - File.open(expand_path('cmd.sh'), 'w') { |f| f.puts string } - - File.chmod 0o755, expand_path('cmd.sh') - prepend_environment_variable 'PATH', "#{expand_path('.')}#{File::PATH_SEPARATOR}" - end - - let(:cmd) { "cmd.sh #{output}" } + let(:cmd) { "ruby -e 'warn \"#{output}\"'" } before(:each) { run_command(cmd) } @@ -108,20 +95,7 @@ def announcer(*args) end context 'when have output hello world on stderr' do - before :each do - string = <<-EOS.strip_heredoc - #!/usr/bin/env bash - - echo $* >&2 - EOS - - File.open(expand_path('cmd.sh'), 'w') { |f| f.puts string } - - File.chmod 0o755, expand_path('cmd.sh') - prepend_environment_variable 'PATH', "#{expand_path('.')}#{File::PATH_SEPARATOR}" - end - - let(:cmd) { "cmd.sh #{output}" } + let(:cmd) { "ruby -e 'warn \"#{output}\"'" } before(:each) { run_command(cmd) } @@ -145,20 +119,7 @@ def announcer(*args) end context 'when have output hello world on stderr' do - before :each do - string = <<-EOS.strip_heredoc - #!/usr/bin/env bash - - echo $* >&2 - EOS - - File.open(expand_path('cmd.sh'), 'w') { |f| f.puts string } - - File.chmod 0o755, expand_path('cmd.sh') - prepend_environment_variable 'PATH', "#{expand_path('.')}#{File::PATH_SEPARATOR}" - end - - let(:cmd) { "cmd.sh #{output}" } + let(:cmd) { "ruby -e 'warn \"#{output}\"'" } before(:each) { run_command(cmd) } diff --git a/spec/aruba/processes/spawn_process_spec.rb b/spec/aruba/processes/spawn_process_spec.rb index 2e0b3461e..e80f5eafa 100644 --- a/spec/aruba/processes/spawn_process_spec.rb +++ b/spec/aruba/processes/spawn_process_spec.rb @@ -22,7 +22,7 @@ end describe "#stderr" do - let(:command) { 'fixtures/spawn_process/stderr.sh yo' } + let(:command) { "ruby -e 'warn \"yo\"'" } before(:each) { process.start } before(:each) { process.stop } From 1f24406aff972bbf2f5a548d8481adea3ed2df2f Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Wed, 8 Nov 2017 16:13:31 +0100 Subject: [PATCH 09/24] Test command and arguments for SpawnProcess --- lib/aruba/processes/basic_process.rb | 4 ++-- spec/aruba/processes/spawn_process_spec.rb | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/aruba/processes/basic_process.rb b/lib/aruba/processes/basic_process.rb index 177ab8c40..9091f08e3 100644 --- a/lib/aruba/processes/basic_process.rb +++ b/lib/aruba/processes/basic_process.rb @@ -122,8 +122,6 @@ def inspect alias to_s inspect - private - def command Shellwords.split(commandline).first end @@ -134,6 +132,8 @@ def arguments [] end + private + def truncate(string, max_length) return string if string.length <= max_length string[0, max_length - 1] + ' ...' diff --git a/spec/aruba/processes/spawn_process_spec.rb b/spec/aruba/processes/spawn_process_spec.rb index e80f5eafa..9c7c615e4 100644 --- a/spec/aruba/processes/spawn_process_spec.rb +++ b/spec/aruba/processes/spawn_process_spec.rb @@ -28,6 +28,11 @@ before(:each) { process.stop } context 'when invoked once' do + it 'has the right args' do + expect(process.command).to eq 'ruby' + expect(process.arguments).to eq ['-e', 'warn "yo"'] + end + it { expect(process.stderr).to eq "yo\n" } end From 330fb905c6e16389092c37624f083c2a5e2c7351 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sun, 11 Mar 2018 13:18:38 +0100 Subject: [PATCH 10/24] Clean up spec for ChildProcess launch error This splits the specs in a Unix and Windows versions, just like for the specs for commands with spaces. --- spec/aruba/processes/spawn_process_spec.rb | 45 ++++++++++++++-------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/spec/aruba/processes/spawn_process_spec.rb b/spec/aruba/processes/spawn_process_spec.rb index 9c7c615e4..f339f7377 100644 --- a/spec/aruba/processes/spawn_process_spec.rb +++ b/spec/aruba/processes/spawn_process_spec.rb @@ -70,37 +70,48 @@ it { expect { process.start }.to raise_error Aruba::LaunchError } end - context "with a childprocess launch error" do - let(:child) { instance_double(ChildProcess::AbstractProcess) } + context 'with a childprocess launch error on unix' do + let(:child) { instance_double(ChildProcess::AbstractProcess).as_null_object } + let(:io) { instance_double(ChildProcess::AbstractIO).as_null_object } let(:command) { 'foo' } + let(:command_path) { '/bar/foo' } before do - allow(ChildProcess).to receive(:build).and_return(child) - - # STEP 1: Simlulate the program exists (but will fail to run, e.g. EACCESS?) - allow(Aruba.platform).to receive(:which).with(command, anything).and_return("/foo") + allow(Aruba.platform).to receive(:command_string).and_return Aruba::Platforms::UnixCommandString + allow(Aruba.platform).to receive(:which).with(command, anything).and_return(command_path) + allow(ChildProcess).to receive(:build).with(command_path).and_return(child) - # STEP 2: Simulate the failure on Windows allow(child).to receive(:start).and_raise(ChildProcess::LaunchError, "Foobar!") + allow(child).to receive(:io).and_return(io) + allow(child).to receive(:environment).and_return({}) + end - # TODO: wrap the result of ChildProcess.build with a special Aruba - # class , so the remaining mocks below won't be needed - allow(child).to receive(:leader=) + it "reraises LaunchError as Aruba's LaunchError" do + expect { process.start }.to raise_error(Aruba::LaunchError, "It tried to start #{command}. Foobar!") + end + end - io = instance_double(ChildProcess::AbstractIO) - allow(io).to receive(:stdout=) - allow(io).to receive(:stderr=) + context 'with a childprocess launch error on windows' do + let(:child) { instance_double(ChildProcess::AbstractProcess).as_null_object } + let(:io) { instance_double(ChildProcess::AbstractIO).as_null_object } + let(:command) { 'foo' } + let(:cmd_path) { 'C:\Bar\cmd.exe' } + let(:command_path) { 'D:\Foo\foo' } - allow(child).to receive(:io).and_return(io) + before do + allow(Aruba.platform).to receive(:command_string).and_return Aruba::Platforms::WindowsCommandString + allow(Aruba.platform).to receive(:which).with('cmd.exe').and_return(cmd_path) + allow(Aruba.platform).to receive(:which).with(command, anything).and_return(command_path) + allow(ChildProcess).to receive(:build).with(cmd_path, '/c', command_path).and_return(child) - allow(child).to receive(:duplex=) - allow(child).to receive(:cwd=) + allow(child).to receive(:start).and_raise(ChildProcess::LaunchError, "Foobar!") + allow(child).to receive(:io).and_return(io) allow(child).to receive(:environment).and_return({}) end it "reraises LaunchError as Aruba's LaunchError" do - expect { process.start }.to raise_error(Aruba::LaunchError, "It tried to start foo. Foobar!") + expect { process.start }.to raise_error(Aruba::LaunchError, "It tried to start #{command}. Foobar!") end end From 85f4b99b75107568a5893e62ded9b80f620b62cc Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sun, 11 Mar 2018 14:51:25 +0100 Subject: [PATCH 11/24] Unify preparations for specs for SpawnProcess#start --- spec/aruba/processes/spawn_process_spec.rb | 88 +++++++++++----------- 1 file changed, 45 insertions(+), 43 deletions(-) diff --git a/spec/aruba/processes/spawn_process_spec.rb b/spec/aruba/processes/spawn_process_spec.rb index f339f7377..6675063dd 100644 --- a/spec/aruba/processes/spawn_process_spec.rb +++ b/spec/aruba/processes/spawn_process_spec.rb @@ -70,7 +70,7 @@ it { expect { process.start }.to raise_error Aruba::LaunchError } end - context 'with a childprocess launch error on unix' do + context 'when on unix' do let(:child) { instance_double(ChildProcess::AbstractProcess).as_null_object } let(:io) { instance_double(ChildProcess::AbstractIO).as_null_object } let(:command) { 'foo' } @@ -79,19 +79,42 @@ before do allow(Aruba.platform).to receive(:command_string).and_return Aruba::Platforms::UnixCommandString allow(Aruba.platform).to receive(:which).with(command, anything).and_return(command_path) - allow(ChildProcess).to receive(:build).with(command_path).and_return(child) + allow(ChildProcess).to receive(:build).and_return(child) - allow(child).to receive(:start).and_raise(ChildProcess::LaunchError, "Foobar!") allow(child).to receive(:io).and_return(io) allow(child).to receive(:environment).and_return({}) end - it "reraises LaunchError as Aruba's LaunchError" do - expect { process.start }.to raise_error(Aruba::LaunchError, "It tried to start #{command}. Foobar!") + context 'with a childprocess launch error' do + before do + allow(child).to receive(:start).and_raise(ChildProcess::LaunchError, "Foobar!") + end + + it "reraises LaunchError as Aruba's LaunchError" do + expect { process.start }. + to raise_error(Aruba::LaunchError, "It tried to start #{command}. Foobar!") + end + end + + context 'with a command with a space in the path' do + let(:command_path) { '/path with space/foo' } + + before do + allow(Aruba.platform).to receive(:command_string).and_return Aruba::Platforms::UnixCommandString + allow(Aruba.platform).to receive(:which).with(command, anything).and_return(command_path) + allow(ChildProcess).to receive(:build).with(command_path).and_return(child) + allow(child).to receive(:io).and_return io + allow(child).to receive(:environment).and_return({}) + end + + it 'passes the command path as a single string to ChildProcess.build' do + process.start + expect(ChildProcess).to have_received(:build).with(command_path) + end end end - context 'with a childprocess launch error on windows' do + context 'when on windows' do let(:child) { instance_double(ChildProcess::AbstractProcess).as_null_object } let(:io) { instance_double(ChildProcess::AbstractIO).as_null_object } let(:command) { 'foo' } @@ -102,53 +125,32 @@ allow(Aruba.platform).to receive(:command_string).and_return Aruba::Platforms::WindowsCommandString allow(Aruba.platform).to receive(:which).with('cmd.exe').and_return(cmd_path) allow(Aruba.platform).to receive(:which).with(command, anything).and_return(command_path) - allow(ChildProcess).to receive(:build).with(cmd_path, '/c', command_path).and_return(child) - - allow(child).to receive(:start).and_raise(ChildProcess::LaunchError, "Foobar!") + allow(ChildProcess).to receive(:build).and_return(child) allow(child).to receive(:io).and_return(io) allow(child).to receive(:environment).and_return({}) end - it "reraises LaunchError as Aruba's LaunchError" do - expect { process.start }.to raise_error(Aruba::LaunchError, "It tried to start #{command}. Foobar!") - end - end + context 'with a childprocess launch error' do + before do + allow(child).to receive(:start).and_raise(ChildProcess::LaunchError, "Foobar!") + end - context 'with a command with a space in the path on unix' do - let(:child) { instance_double(ChildProcess::AbstractProcess).as_null_object } - let(:io) { instance_double(ChildProcess::AbstractIO).as_null_object } - let(:command) { 'foo' } - let(:command_path) { '/path with space/foo' } - - before do - allow(Aruba.platform).to receive(:command_string).and_return Aruba::Platforms::UnixCommandString - allow(Aruba.platform).to receive(:which).with(command, anything).and_return(command_path) - allow(ChildProcess).to receive(:build).with(command_path).and_return(child) - allow(child).to receive(:io).and_return io - allow(child).to receive(:environment).and_return({}) + it "reraises LaunchError as Aruba's LaunchError" do + expect { process.start }. + to raise_error(Aruba::LaunchError, "It tried to start #{command}. Foobar!") + end end - it { expect { process.start }.to_not raise_error } - end - - context 'with a command with a space in the path on windows' do - let(:child) { instance_double(ChildProcess::AbstractProcess).as_null_object } - let(:io) { instance_double(ChildProcess::AbstractIO).as_null_object } - let(:command) { 'foo' } - let(:cmd_path) { 'C:\Some Path\cmd.exe' } - let(:command_path) { 'D:\Bar Baz\foo' } + context 'with a command with a space in the path on windows' do + let(:cmd_path) { 'C:\Some Path\cmd.exe' } + let(:command_path) { 'D:\Bar Baz\foo' } - before do - allow(Aruba.platform).to receive(:command_string).and_return Aruba::Platforms::WindowsCommandString - allow(Aruba.platform).to receive(:which).with('cmd.exe').and_return(cmd_path) - allow(Aruba.platform).to receive(:which).with(command, anything).and_return(command_path) - allow(ChildProcess).to receive(:build).with(cmd_path, '/c', command_path).and_return(child) - allow(child).to receive(:io).and_return io - allow(child).to receive(:environment).and_return({}) + it 'passes the command and shell paths as single strings to ChildProcess.build' do + process.start + expect(ChildProcess).to have_received(:build).with(cmd_path, '/c', command_path) + end end - - it { expect { process.start }.to_not raise_error } end end end From c77da7bba35138738dbf2fae17822a0e28f534f5 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sun, 11 Mar 2018 15:08:00 +0100 Subject: [PATCH 12/24] Add specs for #to_s for command string classes --- spec/aruba/platforms/unix_command_string_spec.rb | 12 ++++++++++++ spec/aruba/platforms/windows_command_string_spec.rb | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/spec/aruba/platforms/unix_command_string_spec.rb b/spec/aruba/platforms/unix_command_string_spec.rb index 8fefc1c00..c72f3f0e2 100644 --- a/spec/aruba/platforms/unix_command_string_spec.rb +++ b/spec/aruba/platforms/unix_command_string_spec.rb @@ -14,4 +14,16 @@ it { expect(command_string.to_a).to eq [base_command] } end end + + describe '#to_s' do + context 'with a command with a path' do + let(:base_command) { '/foo/bar' } + it { expect(command_string.to_s).to eq base_command } + end + + context 'with a command with a path containing spaces' do + let(:base_command) { '/foo bar/baz' } + it { expect(command_string.to_s).to eq base_command } + end + end end diff --git a/spec/aruba/platforms/windows_command_string_spec.rb b/spec/aruba/platforms/windows_command_string_spec.rb index 7c391478d..e86fea938 100644 --- a/spec/aruba/platforms/windows_command_string_spec.rb +++ b/spec/aruba/platforms/windows_command_string_spec.rb @@ -19,4 +19,16 @@ it { expect(command_string.to_a).to eq [cmd_path, '/c', base_command] } end end + + describe '#to_s' do + context 'with a command with a path' do + let(:base_command) { 'C:\Foo\Bar' } + it { expect(command_string.to_s).to eq base_command } + end + + context 'with a command with a path containing spaces' do + let(:base_command) { 'C:\Foo Bar\Baz' } + it { expect(command_string.to_s).to eq base_command } + end + end end From a295dd604f57daea89cfcb8056ef78322b2fbbd8 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sun, 11 Mar 2018 19:08:18 +0100 Subject: [PATCH 13/24] Properly escape command and arguments on windows --- lib/aruba/platforms/unix_command_string.rb | 15 +++++-- lib/aruba/platforms/windows_command_string.rb | 24 ++++++++-- lib/aruba/processes/spawn_process.rb | 4 +- .../platforms/unix_command_string_spec.rb | 15 ++++++- .../platforms/windows_command_string_spec.rb | 17 ++++++- spec/aruba/processes/spawn_process_spec.rb | 44 +++++++++++++++---- 6 files changed, 98 insertions(+), 21 deletions(-) diff --git a/lib/aruba/platforms/unix_command_string.rb b/lib/aruba/platforms/unix_command_string.rb index 9058e9c5e..cbbd1abf8 100644 --- a/lib/aruba/platforms/unix_command_string.rb +++ b/lib/aruba/platforms/unix_command_string.rb @@ -6,14 +6,21 @@ module Aruba # Platforms module Platforms # This is a command which should be run - class UnixCommandString < SimpleDelegator - def initialize(cmd) - __setobj__ cmd + # + # @private + class UnixCommandString + def initialize(command, *arguments) + @command = command + @arguments = arguments end # Convert to array def to_a - [__getobj__] + [@command, *@arguments] + end + + def to_s + @command end end end diff --git a/lib/aruba/platforms/windows_command_string.rb b/lib/aruba/platforms/windows_command_string.rb index 80e128173..2d6df2111 100644 --- a/lib/aruba/platforms/windows_command_string.rb +++ b/lib/aruba/platforms/windows_command_string.rb @@ -1,5 +1,3 @@ -require 'delegate' - # Aruba module Aruba # Platforms @@ -9,14 +7,32 @@ module Platforms # This adds `cmd.exec` in front of commmand # # @private - class WindowsCommandString < SimpleDelegator + class WindowsCommandString + def initialize(command, *arguments) + @command = command + @arguments = arguments + end + # Convert to array def to_a - [cmd_path, '/c', __getobj__] + [cmd_path, '/c', [escaped_command, *escaped_arguments].join(' ')] + end + + def to_s + @command end private + def escaped_arguments + @arguments.map { |arg| arg.gsub(/"/, '"""') }. + map { |arg| arg.match?(/ /) ? "\"#{arg}\"" : arg } + end + + def escaped_command + @command.gsub(/ /, '""" """') + end + def cmd_path Aruba.platform.which('cmd.exe') end diff --git a/lib/aruba/processes/spawn_process.rb b/lib/aruba/processes/spawn_process.rb index 8ec8bcf22..e04d874c0 100644 --- a/lib/aruba/processes/spawn_process.rb +++ b/lib/aruba/processes/spawn_process.rb @@ -71,7 +71,7 @@ def start @started = true - @process = ChildProcess.build(*command_string.to_a, *arguments) + @process = ChildProcess.build(*command_string.to_a) @stdout_file = Tempfile.new('aruba-stdout-') @stderr_file = Tempfile.new('aruba-stderr-') @@ -263,7 +263,7 @@ def command_string fail LaunchError, %(Command "#{command}" not found in PATH-variable "#{environment['PATH']}".) if cmd.nil? - Aruba.platform.command_string.new(cmd) + Aruba.platform.command_string.new(cmd, *arguments) end def wait_for_io(time_to_wait) diff --git a/spec/aruba/platforms/unix_command_string_spec.rb b/spec/aruba/platforms/unix_command_string_spec.rb index c72f3f0e2..d982b5202 100644 --- a/spec/aruba/platforms/unix_command_string_spec.rb +++ b/spec/aruba/platforms/unix_command_string_spec.rb @@ -1,7 +1,8 @@ require 'spec_helper' RSpec.describe Aruba::Platforms::UnixCommandString do - let(:command_string) { described_class.new(base_command) } + let(:command_string) { described_class.new(base_command, *arguments) } + let(:arguments) { [] } describe '#to_a' do context 'with a command with a path' do @@ -13,6 +14,12 @@ let(:base_command) { '/foo bar/baz' } it { expect(command_string.to_a).to eq [base_command] } end + + context 'with a command and arguments' do + let(:base_command) { '/foo/bar' } + let(:arguments) { ['-w', 'baz quux'] } + it { expect(command_string.to_a).to eq [base_command, *arguments] } + end end describe '#to_s' do @@ -25,5 +32,11 @@ let(:base_command) { '/foo bar/baz' } it { expect(command_string.to_s).to eq base_command } end + + context 'with a command and arguments' do + let(:base_command) { '/foo/bar' } + let(:arguments) { ['-w', 'baz quux'] } + it { expect(command_string.to_s).to eq base_command } + end end end diff --git a/spec/aruba/platforms/windows_command_string_spec.rb b/spec/aruba/platforms/windows_command_string_spec.rb index e86fea938..795671538 100644 --- a/spec/aruba/platforms/windows_command_string_spec.rb +++ b/spec/aruba/platforms/windows_command_string_spec.rb @@ -1,8 +1,9 @@ require 'spec_helper' RSpec.describe Aruba::Platforms::WindowsCommandString do - let(:command_string) { described_class.new(base_command) } + let(:command_string) { described_class.new(base_command, *arguments) } let(:cmd_path) { 'C:\Some Path\cmd.exe' } + let(:arguments) { [] } before do allow(Aruba.platform).to receive(:which).with('cmd.exe').and_return(cmd_path) @@ -16,7 +17,13 @@ context 'with a command with a path containing spaces' do let(:base_command) { 'C:\Foo Bar\Baz' } - it { expect(command_string.to_a).to eq [cmd_path, '/c', base_command] } + it { expect(command_string.to_a).to eq [cmd_path, '/c', 'C:\Foo""" """Bar\Baz'] } + end + + context 'with a command and arguments' do + let(:base_command) { 'C:\Foo\Bar' } + let(:arguments) { ['-w', 'baz quux'] } + it { expect(command_string.to_a).to eq [cmd_path, '/c', "#{base_command} -w \"baz quux\""] } end end @@ -30,5 +37,11 @@ let(:base_command) { 'C:\Foo Bar\Baz' } it { expect(command_string.to_s).to eq base_command } end + + context 'with a command and arguments' do + let(:base_command) { 'C:\Foo\Bar' } + let(:arguments) { ['-w', 'baz quux'] } + it { expect(command_string.to_s).to eq base_command } + end end end diff --git a/spec/aruba/processes/spawn_process_spec.rb b/spec/aruba/processes/spawn_process_spec.rb index 6675063dd..1195162a0 100644 --- a/spec/aruba/processes/spawn_process_spec.rb +++ b/spec/aruba/processes/spawn_process_spec.rb @@ -1,9 +1,9 @@ require 'spec_helper' RSpec.describe Aruba::Processes::SpawnProcess do - subject(:process) { described_class.new(command, exit_timeout, io_wait, working_directory) } + subject(:process) { described_class.new(command_line, exit_timeout, io_wait, working_directory) } - let(:command) { 'echo "yo"' } + let(:command_line) { 'echo "yo"' } let(:exit_timeout) { 1 } let(:io_wait) { 1 } let(:working_directory) { Dir.getwd } @@ -22,7 +22,7 @@ end describe "#stderr" do - let(:command) { "ruby -e 'warn \"yo\"'" } + let(:command_line) { "ruby -e 'warn \"yo\"'" } before(:each) { process.start } before(:each) { process.stop } @@ -65,7 +65,7 @@ end context "when process run fails" do - let(:command) { 'does_not_exists' } + let(:command_line) { 'does_not_exists' } it { expect { process.start }.to raise_error Aruba::LaunchError } end @@ -73,6 +73,7 @@ context 'when on unix' do let(:child) { instance_double(ChildProcess::AbstractProcess).as_null_object } let(:io) { instance_double(ChildProcess::AbstractIO).as_null_object } + let(:command_line) { 'foo' } let(:command) { 'foo' } let(:command_path) { '/bar/foo' } @@ -112,11 +113,22 @@ expect(ChildProcess).to have_received(:build).with(command_path) end end + + context 'with a command with arguments' do + let(:command_line) { 'foo -x "bar baz"' } + + it 'passes the command and arguments as separate items to ChildProcess.build' do + process.start + expect(ChildProcess).to have_received(:build). + with(command_path, '-x', 'bar baz') + end + end end context 'when on windows' do let(:child) { instance_double(ChildProcess::AbstractProcess).as_null_object } let(:io) { instance_double(ChildProcess::AbstractIO).as_null_object } + let(:command_line) { 'foo' } let(:command) { 'foo' } let(:cmd_path) { 'C:\Bar\cmd.exe' } let(:command_path) { 'D:\Foo\foo' } @@ -142,15 +154,31 @@ end end - context 'with a command with a space in the path on windows' do - let(:cmd_path) { 'C:\Some Path\cmd.exe' } - let(:command_path) { 'D:\Bar Baz\foo' } - + context 'with a command without a space in the path' do it 'passes the command and shell paths as single strings to ChildProcess.build' do process.start expect(ChildProcess).to have_received(:build).with(cmd_path, '/c', command_path) end end + + context 'with a command with a space in the path' do + let(:command_path) { 'D:\Bar Baz\foo' } + + it 'escapes the spaces using excessive double quotes' do + process.start + expect(ChildProcess).to have_received(:build).with(cmd_path, '/c', 'D:\Bar""" """Baz\foo') + end + end + + context 'with a command with arguments' do + let(:command_line) { "foo -x 'bar \"baz\"'" } + + it 'passes the command and arguments as one string to ChildProcess.build, with escaped quotes' do + process.start + expect(ChildProcess).to have_received(:build). + with(cmd_path, '/c', "#{command_path} -x \"bar \"\"\"baz\"\"\"\"") + end + end end end end From ea5c3b6338d00553ba7818681f17e030bb1809b9 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sun, 11 Mar 2018 19:16:57 +0100 Subject: [PATCH 14/24] Remove #to_s from CommandString classes This method basically returns one of the initializer arguments so makes little sense. --- lib/aruba/platforms/unix_command_string.rb | 4 ---- lib/aruba/platforms/windows_command_string.rb | 4 ---- lib/aruba/processes/spawn_process.rb | 13 +++++++------ .../platforms/unix_command_string_spec.rb | 18 ------------------ .../platforms/windows_command_string_spec.rb | 18 ------------------ 5 files changed, 7 insertions(+), 50 deletions(-) diff --git a/lib/aruba/platforms/unix_command_string.rb b/lib/aruba/platforms/unix_command_string.rb index cbbd1abf8..a396417ca 100644 --- a/lib/aruba/platforms/unix_command_string.rb +++ b/lib/aruba/platforms/unix_command_string.rb @@ -18,10 +18,6 @@ def initialize(command, *arguments) def to_a [@command, *@arguments] end - - def to_s - @command - end end end end diff --git a/lib/aruba/platforms/windows_command_string.rb b/lib/aruba/platforms/windows_command_string.rb index 2d6df2111..b9af55d02 100644 --- a/lib/aruba/platforms/windows_command_string.rb +++ b/lib/aruba/platforms/windows_command_string.rb @@ -18,10 +18,6 @@ def to_a [cmd_path, '/c', [escaped_command, *escaped_arguments].join(' ')] end - def to_s - @command - end - private def escaped_arguments diff --git a/lib/aruba/processes/spawn_process.rb b/lib/aruba/processes/spawn_process.rb index e04d874c0..65cf13e3e 100644 --- a/lib/aruba/processes/spawn_process.rb +++ b/lib/aruba/processes/spawn_process.rb @@ -239,7 +239,7 @@ def send_signal(signal) # @return [Aruba::Platforms::FilesystemStatus] # This returns a File::Stat-object def filesystem_status - Aruba.platform.filesystem_status.new(command_string.to_s) + Aruba.platform.filesystem_status.new(command_path) end # Content of command @@ -248,7 +248,7 @@ def filesystem_status # The content of the script/command. This might be binary output as # string if your command is a binary executable. def content - File.read command_string.to_s + File.read command_path end def interactive? @@ -258,12 +258,13 @@ def interactive? private def command_string - # gather fully qualified path - cmd = Aruba.platform.which(command, environment['PATH']) + fail LaunchError, %(Command "#{command}" not found in PATH-variable "#{environment['PATH']}".) if command_path.nil? - fail LaunchError, %(Command "#{command}" not found in PATH-variable "#{environment['PATH']}".) if cmd.nil? + Aruba.platform.command_string.new(command_path, *arguments) + end - Aruba.platform.command_string.new(cmd, *arguments) + def command_path + @command_path ||= Aruba.platform.which(command, environment['PATH']) end def wait_for_io(time_to_wait) diff --git a/spec/aruba/platforms/unix_command_string_spec.rb b/spec/aruba/platforms/unix_command_string_spec.rb index d982b5202..98a50df27 100644 --- a/spec/aruba/platforms/unix_command_string_spec.rb +++ b/spec/aruba/platforms/unix_command_string_spec.rb @@ -21,22 +21,4 @@ it { expect(command_string.to_a).to eq [base_command, *arguments] } end end - - describe '#to_s' do - context 'with a command with a path' do - let(:base_command) { '/foo/bar' } - it { expect(command_string.to_s).to eq base_command } - end - - context 'with a command with a path containing spaces' do - let(:base_command) { '/foo bar/baz' } - it { expect(command_string.to_s).to eq base_command } - end - - context 'with a command and arguments' do - let(:base_command) { '/foo/bar' } - let(:arguments) { ['-w', 'baz quux'] } - it { expect(command_string.to_s).to eq base_command } - end - end end diff --git a/spec/aruba/platforms/windows_command_string_spec.rb b/spec/aruba/platforms/windows_command_string_spec.rb index 795671538..88141d0a0 100644 --- a/spec/aruba/platforms/windows_command_string_spec.rb +++ b/spec/aruba/platforms/windows_command_string_spec.rb @@ -26,22 +26,4 @@ it { expect(command_string.to_a).to eq [cmd_path, '/c', "#{base_command} -w \"baz quux\""] } end end - - describe '#to_s' do - context 'with a command with a path' do - let(:base_command) { 'C:\Foo\Bar' } - it { expect(command_string.to_s).to eq base_command } - end - - context 'with a command with a path containing spaces' do - let(:base_command) { 'C:\Foo Bar\Baz' } - it { expect(command_string.to_s).to eq base_command } - end - - context 'with a command and arguments' do - let(:base_command) { 'C:\Foo\Bar' } - let(:arguments) { ['-w', 'baz quux'] } - it { expect(command_string.to_s).to eq base_command } - end - end end From 95dc752aac421c05894215c86bacb2b0008392e4 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sun, 11 Mar 2018 19:29:05 +0100 Subject: [PATCH 15/24] Replace match? to support older Rubies --- lib/aruba/platforms/windows_command_string.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/aruba/platforms/windows_command_string.rb b/lib/aruba/platforms/windows_command_string.rb index b9af55d02..42bf93e75 100644 --- a/lib/aruba/platforms/windows_command_string.rb +++ b/lib/aruba/platforms/windows_command_string.rb @@ -22,7 +22,7 @@ def to_a def escaped_arguments @arguments.map { |arg| arg.gsub(/"/, '"""') }. - map { |arg| arg.match?(/ /) ? "\"#{arg}\"" : arg } + map { |arg| arg =~ / / ? "\"#{arg}\"" : arg } end def escaped_command From 7ca2e64d66086d5c4ce583f42c3deb2b02876cd9 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sun, 11 Mar 2018 20:21:14 +0100 Subject: [PATCH 16/24] Allow any line ending --- spec/aruba/processes/spawn_process_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/aruba/processes/spawn_process_spec.rb b/spec/aruba/processes/spawn_process_spec.rb index 1195162a0..e1aa111ae 100644 --- a/spec/aruba/processes/spawn_process_spec.rb +++ b/spec/aruba/processes/spawn_process_spec.rb @@ -13,11 +13,11 @@ before(:each) { process.stop } context 'when invoked once' do - it { expect(process.stdout).to eq "yo\n" } + it { expect(process.stdout.chomp).to eq 'yo' } end context 'when invoked twice' do - it { 2.times { expect(process.stdout).to eq "yo\n" } } + it { 2.times { expect(process.stdout.chomp).to eq 'yo' } } end end @@ -33,11 +33,11 @@ expect(process.arguments).to eq ['-e', 'warn "yo"'] end - it { expect(process.stderr).to eq "yo\n" } + it { expect(process.stderr.chomp).to eq 'yo'} end context 'when invoked twice' do - it { 2.times { expect(process.stderr).to eq "yo\n" } } + it { 2.times { expect(process.stderr.chomp).to eq 'yo'} } end end From 6d01a375716f48aa1ed52a161bf6824b25c8567c Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sun, 11 Mar 2018 21:13:22 +0100 Subject: [PATCH 17/24] Make spec pass with Windows' read-only permissions --- spec/aruba/matchers/path_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/aruba/matchers/path_spec.rb b/spec/aruba/matchers/path_spec.rb index 70f20f4ad..ff4152c65 100644 --- a/spec/aruba/matchers/path_spec.rb +++ b/spec/aruba/matchers/path_spec.rb @@ -81,7 +81,7 @@ def expand_path(*args) end context 'and permissions are given as octal number' do - let(:permissions) { 0o666 } + let(:permissions) { 0o644 } it { expect(file_name).to have_permissions permissions } end From 9f899bf6ffd3fbaac5b6e74101b6728973a3d444 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sun, 11 Mar 2018 21:15:01 +0100 Subject: [PATCH 18/24] Skip permission scenarios on Windows --- features/05_use_rspec_matchers/path/have_permissions.feature | 1 + 1 file changed, 1 insertion(+) diff --git a/features/05_use_rspec_matchers/path/have_permissions.feature b/features/05_use_rspec_matchers/path/have_permissions.feature index b0a9d6e60..88bbabff5 100644 --- a/features/05_use_rspec_matchers/path/have_permissions.feature +++ b/features/05_use_rspec_matchers/path/have_permissions.feature @@ -1,3 +1,4 @@ +@unsupported-on-platform-windows Feature: Check if path has permissions in filesystem If you need to check if a given path has some permissions in filesystem, you From 8b441b943ea40b2499a98462f91f76f3b9e5a72f Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Wed, 14 Mar 2018 16:58:24 +0100 Subject: [PATCH 19/24] Use correct path separator in RSpec setup --- lib/aruba/rspec.rb | 3 ++- spec/aruba/rspec_spec.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/aruba/rspec.rb b/lib/aruba/rspec.rb index 9f430d805..d89ac0704 100644 --- a/lib/aruba/rspec.rb +++ b/lib/aruba/rspec.rb @@ -13,7 +13,8 @@ setup_aruba # Modify PATH to include project/bin - prepend_environment_variable 'PATH', aruba.config.command_search_paths.join(':') + ':' + prepend_environment_variable 'PATH', + aruba.config.command_search_paths.join(File::PATH_SEPARATOR) + File::PATH_SEPARATOR # Use configured home directory as HOME set_environment_variable 'HOME', aruba.config.home_directory diff --git a/spec/aruba/rspec_spec.rb b/spec/aruba/rspec_spec.rb index e48e9394c..b36c3845b 100644 --- a/spec/aruba/rspec_spec.rb +++ b/spec/aruba/rspec_spec.rb @@ -19,7 +19,7 @@ end it 'includes configured command search paths in PATH' do - expect(ENV['PATH']).to include aruba.config.command_search_paths.join(':') + expect(ENV['PATH']).to include aruba.config.command_search_paths.join(File::PATH_SEPARATOR) end end end From 9f97f96573cf73927c543681ae8c2161bc5d1bc2 Mon Sep 17 00:00:00 2001 From: Andrew Walter Date: Sat, 19 May 2018 19:31:02 +1000 Subject: [PATCH 20/24] Skip scenarios tagged with `@requires-bash` unless bash is installed --- features/support/env.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/features/support/env.rb b/features/support/env.rb index 92194fe0e..171a7ea16 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -26,3 +26,7 @@ # set environment variable so child processes will merge their coverage data with parent process's coverage data. ENV['RUBYOPT'] = "-r#{simplecov_setup_pathname} #{ENV['RUBYOPT']}" end + +Before('@requires-bash') do |scenario| + skip_this_scenario unless Aruba.platform.which('bash') +end \ No newline at end of file From 22101898147538b2086127955409d56182b35cea Mon Sep 17 00:00:00 2001 From: Andrew Walter Date: Sat, 19 May 2018 21:17:39 +1000 Subject: [PATCH 21/24] Moved `@requires-bash` before hook to hooks.rb --- features/step_definitions/hooks.rb | 4 ++++ features/support/env.rb | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/features/step_definitions/hooks.rb b/features/step_definitions/hooks.rb index b0e67136e..d64e50e03 100644 --- a/features/step_definitions/hooks.rb +++ b/features/step_definitions/hooks.rb @@ -136,3 +136,7 @@ skip_this_scenario end end + +Before('@requires-bash') do |scenario| + skip_this_scenario unless Aruba.platform.which('bash') +end diff --git a/features/support/env.rb b/features/support/env.rb index 171a7ea16..e1cdc6550 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -25,8 +25,4 @@ # set environment variable so child processes will merge their coverage data with parent process's coverage data. ENV['RUBYOPT'] = "-r#{simplecov_setup_pathname} #{ENV['RUBYOPT']}" -end - -Before('@requires-bash') do |scenario| - skip_this_scenario unless Aruba.platform.which('bash') end \ No newline at end of file From bdad6eac0cc35e59feb9f9e7bc0493d424c5c636 Mon Sep 17 00:00:00 2001 From: Andrew Walter Date: Sat, 19 May 2018 21:23:02 +1000 Subject: [PATCH 22/24] Updated `@requires-bash` before hook. --- features/step_definitions/hooks.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/features/step_definitions/hooks.rb b/features/step_definitions/hooks.rb index d64e50e03..faa0ea557 100644 --- a/features/step_definitions/hooks.rb +++ b/features/step_definitions/hooks.rb @@ -138,5 +138,11 @@ end Before('@requires-bash') do |scenario| - skip_this_scenario unless Aruba.platform.which('bash') + next if Aruba.platform.which('bash') + + if Cucumber::VERSION < '2' + scenario.skip_invoke! + else + skip_this_scenario + end end From dcd00159a83700dd3ef1ca8e7021dbfa5bc819a8 Mon Sep 17 00:00:00 2001 From: Andrew Walter Date: Sat, 19 May 2018 21:50:45 +1000 Subject: [PATCH 23/24] Fixed `run_commands` feature on Windows --- features/01_getting_started_with_aruba/run_commands.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/01_getting_started_with_aruba/run_commands.feature b/features/01_getting_started_with_aruba/run_commands.feature index bbed97733..07cc86750 100644 --- a/features/01_getting_started_with_aruba/run_commands.feature +++ b/features/01_getting_started_with_aruba/run_commands.feature @@ -53,7 +53,7 @@ Feature: Run commands with Aruba When I successfully run `cucumber` Then the features should all pass - @requires-ruby + @requires-ruby @unsupported-on-platform-windows Scenario: Ruby Program Given an executable named "bin/aruba-test-cli" with: """ruby From 5859fb3b6b477131bc24877071f1496719c53878 Mon Sep 17 00:00:00 2001 From: Andrew Walter Date: Sat, 19 May 2018 22:09:00 +1000 Subject: [PATCH 24/24] Feature - Run_commands: Added Batch program scenarios --- .../run_commands.feature | 39 +++++++++++++++++++ features/step_definitions/hooks.rb | 10 +++++ 2 files changed, 49 insertions(+) diff --git a/features/01_getting_started_with_aruba/run_commands.feature b/features/01_getting_started_with_aruba/run_commands.feature index 07cc86750..4e07c6214 100644 --- a/features/01_getting_started_with_aruba/run_commands.feature +++ b/features/01_getting_started_with_aruba/run_commands.feature @@ -53,6 +53,45 @@ Feature: Run commands with Aruba When I successfully run `cucumber` Then the features should all pass + + @requires-cmd + Scenario: Batch Program + Given an executable named "bin/aruba-test-cli.bat" with: + """bash + echo "Hello, Aruba!" + """ + And a file named "features/hello_aruba.feature" with: + """ + Feature: Getting Started With Aruba + Scenario: First Run of Command + Given I successfully run `aruba-test-cli` + Then the output should contain: + \"\"\" + Hello, Aruba! + \"\"\" + """ + When I successfully run `cucumber` + Then the features should all pass + + @requires-cmd + Scenario: Batch Program run via cmd + Given a file named "features/hello_aruba.feature" with: + """ + Feature: Getting Started With Aruba + Scenario: First Run of Command + Given a file named "cli.bat" with: + \"\"\" + echo "Hello, Aruba!" + \"\"\" + When I successfully run `cmd.exe /c cli.bat` + Then the output should contain: + \"\"\" + Hello, Aruba! + \"\"\" + """ + When I successfully run `cucumber` + Then the features should all pass + @requires-ruby @unsupported-on-platform-windows Scenario: Ruby Program Given an executable named "bin/aruba-test-cli" with: diff --git a/features/step_definitions/hooks.rb b/features/step_definitions/hooks.rb index faa0ea557..b824f48f9 100644 --- a/features/step_definitions/hooks.rb +++ b/features/step_definitions/hooks.rb @@ -146,3 +146,13 @@ skip_this_scenario end end + +Before('@requires-cmd') do |scenario| + next if Aruba.platform.which('cmd') + + if Cucumber::VERSION < '2' + scenario.skip_invoke! + else + skip_this_scenario + end +end \ No newline at end of file