Show command when remote execution fail
This commit is contained in:
@@ -17,35 +17,33 @@ module Producer::Core
|
||||
let(:output) { StringIO.new }
|
||||
subject(:run) { described_class.run! arguments, output: output }
|
||||
|
||||
before { allow(described_class).to receive(:new) { cli } }
|
||||
|
||||
it 'builds a new CLI with given arguments' do
|
||||
expect(described_class)
|
||||
.to receive(:new).with(arguments).and_call_original
|
||||
expect(described_class).to receive(:new).with(arguments)
|
||||
run
|
||||
end
|
||||
|
||||
it 'runs the CLI' do
|
||||
allow(described_class).to receive(:new) { cli }
|
||||
expect(cli).to receive :run
|
||||
run
|
||||
end
|
||||
|
||||
it 'parses CLI arguments' do
|
||||
allow(described_class).to receive(:new) { cli }
|
||||
expect(cli).to receive :parse_arguments!
|
||||
run
|
||||
end
|
||||
|
||||
context 'when an argument error is raised' do
|
||||
before do
|
||||
allow(described_class).to receive(:new) { cli }
|
||||
allow(cli).to receive(:parse_arguments!)
|
||||
.and_raise described_class::ArgumentError
|
||||
end
|
||||
|
||||
it 'exits with a return status of 64' do
|
||||
expect { run }.to raise_error(SystemExit) { |e|
|
||||
expect { run }.to raise_error(SystemExit) do |e|
|
||||
expect(e.status).to eq 64
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
it 'prints the usage' do
|
||||
@@ -53,6 +51,24 @@ module Producer::Core
|
||||
expect(output.string).to match /\AUsage: .+/
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a runtime error is raised' do
|
||||
before do
|
||||
allow(cli).to receive(:run)
|
||||
.and_raise RuntimeError, 'some message'
|
||||
end
|
||||
|
||||
it 'exits with a return status of 70' do
|
||||
expect { run }.to raise_error(SystemExit) do |e|
|
||||
expect(e.status).to eq 70
|
||||
end
|
||||
end
|
||||
|
||||
it 'prints exception name and message' do
|
||||
trap_exit { run }
|
||||
expect(output.string).to match /\ARuntimeError: some message/
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#initialize' do
|
||||
|
@@ -106,14 +106,23 @@ module Producer::Core
|
||||
expect(output.string).to eq arguments
|
||||
end
|
||||
|
||||
it 'raises an exception when the exit status code is not 0' do
|
||||
story_with_new_channel do |ch|
|
||||
ch.sends_exec command
|
||||
ch.gets_data arguments
|
||||
ch.gets_exit_status 1
|
||||
context 'when command execution fails' do
|
||||
before do
|
||||
story_with_new_channel do |ch|
|
||||
ch.sends_exec command
|
||||
ch.gets_data arguments
|
||||
ch.gets_exit_status 1
|
||||
end
|
||||
end
|
||||
|
||||
it 'raises an exception' do
|
||||
expect { remote.execute command }
|
||||
.to raise_error(RemoteCommandExecutionError)
|
||||
end
|
||||
|
||||
it 'includes the command in the exception message' do
|
||||
expect { remote.execute command }.to raise_error /#{command}/
|
||||
end
|
||||
expect { remote.execute command }
|
||||
.to raise_error(RemoteCommandExecutionError)
|
||||
end
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user