Handle and format Uh::WM::RuntimeError in CLI.run

This commit is contained in:
Thibault Jouan
2015-04-12 23:44:42 +00:00
parent 34d84ad111
commit c3e1f9639a
2 changed files with 39 additions and 1 deletions

View File

@@ -52,6 +52,39 @@ module Uh
end
end
end
context 'when the new CLI raises a runtime error' do
before do
allow(cli).to receive(:run) { fail RuntimeError, 'some error' }
allow(described_class).to receive(:new) { cli }
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 'formats the error' do
trap_exit { run }
expect(stderr.string)
.to match /\AUh::WM::RuntimeError: some error\n/
end
it 'does not output a backtrace' do
trap_exit { run }
expect(stderr.string).not_to include __FILE__
end
context 'when debug mode is enabled' do
let(:arguments) { %w[-d] }
it 'outputs a backtrace' do
trap_exit { run }
expect(stderr.string).to include __FILE__
end
end
end
end
describe '#initialize' do