From 097db5e6725d426aa8594f51281a9f2883b57bc8 Mon Sep 17 00:00:00 2001 From: Cezary Baginski Date: Thu, 31 Mar 2016 02:12:32 +0200 Subject: [PATCH] Fix missing variable in exception handler Previously, "cmd" was passed to a different method. The reason this never came up earlier is because on Unix, if a file is not in the PATH, a Aruba::LaunchError is raised much earlier. One way this could've been triggered is: if the program file existed, but wasn't accessible (e.g. EACCES error). That way it wouldn't fail the `which` test, but would fail once it was attempted to be executed. --- lib/aruba/processes/spawn_process.rb | 2 +- spec/aruba/spawn_process_spec.rb | 30 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/aruba/processes/spawn_process.rb b/lib/aruba/processes/spawn_process.rb index 1d4dcc474..1f4da7852 100644 --- a/lib/aruba/processes/spawn_process.rb +++ b/lib/aruba/processes/spawn_process.rb @@ -83,7 +83,7 @@ def start sleep startup_wait_time end rescue ChildProcess::LaunchError => e - raise LaunchError, "It tried to start #{cmd}. " + e.message + raise LaunchError, "It tried to start #{commandline}. " + e.message end after_run diff --git a/spec/aruba/spawn_process_spec.rb b/spec/aruba/spawn_process_spec.rb index fe32a576f..cfe3fbef0 100644 --- a/spec/aruba/spawn_process_spec.rb +++ b/spec/aruba/spawn_process_spec.rb @@ -56,5 +56,35 @@ it { expect {process.start}.to raise_error Aruba::LaunchError } end + + context "with a childprocess launch error" do + let(:child) { instance_double(ChildProcess::AbstractProcess) } + let(:command) { 'foo' } + + before do + allow(ChildProcess).to receive(:build).and_return(child) + + # 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(child).to receive(:start).and_raise(ChildProcess::LaunchError, "Foobar!") + allow(child).to receive(:leader=) + + io = instance_double(ChildProcess::Unix::IO) + allow(io).to receive(:stdout=) + allow(io).to receive(:stderr=) + + allow(child).to receive(:io).and_return(io) + + allow(child).to receive(:duplex=) + allow(child).to receive(:cwd=) + + 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!") + end + end end end