From 6c041315494199b3682f549bba804ebb0ec73e9d Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sat, 18 May 2019 18:10:01 +0200 Subject: [PATCH 01/20] Build on recent Rubies in AppVeyor --- appveyor.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 2d6618705..004d11d6f 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -24,8 +24,9 @@ test_script: environment: matrix: - - ruby_version: '19' - - ruby_version: '20' - - ruby_version: '21' - ruby_version: '22' + - ruby_version: '23' + - ruby_version: '24' + - ruby_version: '25' + - ruby_version: '26' From 43dea0c4076a184dbaaeddad8472fdacc642db76 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sat, 18 May 2019 19:44:21 +0200 Subject: [PATCH 02/20] Run only the RSpec part of the test suite on appveyor --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 004d11d6f..d27eb64b7 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -20,7 +20,7 @@ install: - cinst ansicon test_script: - - bundle exec rake test --trace + - bundle exec rake test:rspec --trace environment: matrix: From e002b4bdbfcce05837a5b341fd0d9efc741140da Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Wed, 8 Nov 2017 08:22:24 +0100 Subject: [PATCH 03/20] 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 1d2e7d3c0..bc442bc3e 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 093b51e5c..2393103d1 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 e08caa49446bbef9ac8856699efe0a07084ea8c9 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Wed, 8 Nov 2017 08:26:01 +0100 Subject: [PATCH 04/20] 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 0e5b7ba36cfd946b4ab8597868f9f627fa7738e4 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Wed, 8 Nov 2017 08:26:15 +0100 Subject: [PATCH 05/20] 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 8349b623d2586987a02c7aec75442f4a27dc33b3 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Wed, 8 Nov 2017 08:39:31 +0100 Subject: [PATCH 06/20] 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 e57c4680d489180177842bcfcf69e4dfe4e71cf4 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Wed, 8 Nov 2017 08:42:26 +0100 Subject: [PATCH 07/20] 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 dc08d21fa..7005c5e6c 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 500ce53735bfe52dbd121201c3380c29d21a2999 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Wed, 8 Nov 2017 09:04:52 +0100 Subject: [PATCH 08/20] 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 bc442bc3e..cd27a0115 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 3ddc92150..3d0fae2c5 100644 --- a/lib/aruba/processes/in_process.rb +++ b/lib/aruba/processes/in_process.rb @@ -46,7 +46,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 2393103d1..684d9c1d1 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 9b78d1b1e6425946b7ec00ab0a3fdef5a2605165 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Wed, 8 Nov 2017 13:56:14 +0100 Subject: [PATCH 09/20] 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 7005c5e6c..983439ca2 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 2633b0b2268542f294d823b2428da1cb26abfa62 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Wed, 8 Nov 2017 16:13:31 +0100 Subject: [PATCH 10/20] 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 cd27a0115..2bb526759 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 diff --git a/spec/aruba/processes/spawn_process_spec.rb b/spec/aruba/processes/spawn_process_spec.rb index 983439ca2..22044705f 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 cc4823299b021b252d4227d3e49d74f80fd108fc Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sun, 11 Mar 2018 13:18:38 +0100 Subject: [PATCH 11/20] 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 22044705f..d35f8b22e 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 3ea6dd013808106fee12caede9e214f78ee0edbf Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sun, 11 Mar 2018 14:51:25 +0100 Subject: [PATCH 12/20] 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 d35f8b22e..9de917239 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 70f0a93d88ba7cbb872b93bfe1ad6ed5c9e5be69 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sun, 11 Mar 2018 15:08:00 +0100 Subject: [PATCH 13/20] 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 82db73a6e946c2003aba311f3adba781e9d8e3e9 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sun, 11 Mar 2018 19:08:18 +0100 Subject: [PATCH 14/20] 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 684d9c1d1..4fea638fd 100644 --- a/lib/aruba/processes/spawn_process.rb +++ b/lib/aruba/processes/spawn_process.rb @@ -72,7 +72,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-') @@ -264,7 +264,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 9de917239..3632aaf31 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 bdf636872140e6ab8d228f9c760b57bfe2cf85cc Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sun, 11 Mar 2018 19:16:57 +0100 Subject: [PATCH 15/20] 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 4fea638fd..43efa35b2 100644 --- a/lib/aruba/processes/spawn_process.rb +++ b/lib/aruba/processes/spawn_process.rb @@ -240,7 +240,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 @@ -249,7 +249,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? @@ -259,12 +259,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 12fb604b2f9787034b88e9b580754001a1a05e23 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sun, 11 Mar 2018 19:29:05 +0100 Subject: [PATCH 16/20] 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 0a775b9e0ee3326208f8c55a4574f142e6c994fd Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sun, 11 Mar 2018 20:21:14 +0100 Subject: [PATCH 17/20] 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 3632aaf31..488817dab 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 fc76f31bd7c85d1c1e7bcb8641449f80de96b890 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sun, 11 Mar 2018 21:13:22 +0100 Subject: [PATCH 18/20] 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 9321cca14..d0449f3de 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 216fe028d7f6cade683026f9f6ec2d040db078cf Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sun, 11 Mar 2018 21:15:01 +0100 Subject: [PATCH 19/20] 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 2f0d91b85d7c998e949c00e1d020e60d97ca0566 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Wed, 14 Mar 2018 16:58:24 +0100 Subject: [PATCH 20/20] 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 50067b12f..d052741ec 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