From d03a67f0f05ca39bc10e5fa8c30940b67d23dd1b Mon Sep 17 00:00:00 2001 From: Andrey Koleshko Date: Thu, 31 Oct 2013 11:50:43 +0300 Subject: [PATCH] Pass Errno::ENOENT message to local exception --- lib/cocaine/command_line.rb | 4 ++-- spec/cocaine/command_line_spec.rb | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/cocaine/command_line.rb b/lib/cocaine/command_line.rb index b31100f..25bcc37 100644 --- a/lib/cocaine/command_line.rb +++ b/lib/cocaine/command_line.rb @@ -74,8 +74,8 @@ def run(interpolations = {}) full_command = command(interpolations) log("#{colored("Command")} :: #{full_command}") output = execute(full_command) - rescue Errno::ENOENT - raise Cocaine::CommandNotFoundError + rescue Errno::ENOENT => e + raise Cocaine::CommandNotFoundError, e.message ensure @exit_status = $?.exitstatus if $?.respond_to?(:exitstatus) end diff --git a/spec/cocaine/command_line_spec.rb b/spec/cocaine/command_line_spec.rb index 2d066ea..b1ba8c1 100644 --- a/spec/cocaine/command_line_spec.rb +++ b/spec/cocaine/command_line_spec.rb @@ -312,5 +312,16 @@ cmd.runner.class.should eq Cocaine::CommandLine::FakeRunner end + it 'passes error message to exception when command is failed with Errono::ENOENT' do + cmd = Cocaine::CommandLine.new('test command', '') + cmd.stubs(:execute).with('test command') do + raise Errno::ENOENT, 'fail message' + end + begin + cmd.run + rescue Cocaine::CommandNotFoundError => e + expect(e.message).to eq 'No such file or directory - fail message' + end + end end end