Improve CLI error reporting

This commit is contained in:
Thibault Jouan
2014-10-11 17:34:19 +00:00
parent f6237bfc0c
commit 25d03d4322
8 changed files with 142 additions and 7 deletions

View File

@@ -44,7 +44,7 @@ module Producer::Core
end
end
context 'when a runtime error is raised' do
context 'when an error is raised' do
let(:recipe_file) { fixture_path_for 'recipes/raise.rb' }
it 'exits with a return status of 70' do
@@ -52,9 +52,9 @@ module Producer::Core
.to raise_error(SystemExit) { |e| expect(e.status).to eq 70 }
end
it 'prints exception name and message and the error stream' do
it 'prints a report to the error stream' do
expect { trap_exit { run! } }
.to output("RemoteCommandExecutionError: false\n").to_stderr
.to output(/\ARemoteCommandExecutionError: false$/).to_stderr
end
end
end

View File

@@ -0,0 +1,50 @@
require 'spec_helper'
module Producer
module Core
describe ErrorFormatter do
let(:debug) { false }
let(:force_cause) { [] }
let(:options) { { debug: debug, force_cause: force_cause } }
subject(:formatter) { described_class.new(options) }
describe '#debug?' do
it 'returns false' do
expect(formatter.debug?).to be false
end
context 'when debug is enabled' do
let(:debug) { true }
it 'returns true' do
expect(formatter.debug?).to be true
end
end
end
describe '#format' do
let(:message) { 'some exception' }
let(:exception) { Exception.new(message) }
before { exception.set_backtrace %w[back trace] }
it 'formats the message' do
expect(formatter.format exception)
.to match /^Exception: some exception$/
end
it 'indents the backtrace' do
expect(formatter.format exception).to match /^\s+back$/
end
context 'filtering' do
before { exception.set_backtrace %w[back trace /producer-core/lib/] }
it 'excludes producer code from the backtrace' do
expect(formatter.format exception).not_to include 'producer-core'
end
end
end
end
end
end