Skip to content

Commit

Permalink
Fix missing variable in exception handler
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
e2 committed Mar 31, 2016
1 parent 3502d8c commit 097db5e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/aruba/processes/spawn_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions spec/aruba/spawn_process_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 097db5e

Please sign in to comment.