Make the SimpleExecutor rescue exceptions in the executing Checks

This commit is contained in:
Gabriel Mazetto 2017-06-27 17:41:58 +02:00
parent 6b86ce75cf
commit b0f2861c3d
2 changed files with 19 additions and 2 deletions

View file

@ -75,6 +75,8 @@ module SystemCheck
check.show_error check.show_error
end end
rescue StandardError => e
$stdout.puts "Exception: #{e.message}".color(:red)
end end
private private

View file

@ -75,6 +75,15 @@ describe SystemCheck::SimpleExecutor, lib: true do
end end
end end
class BugousCheck < SystemCheck::BaseCheck
CustomError = Class.new(StandardError)
set_name 'my bugous check'
def check?
raise CustomError, 'omg'
end
end
describe '#component' do describe '#component' do
it 'returns stored component name' do it 'returns stored component name' do
expect(subject.component).to eq('Test') expect(subject.component).to eq('Test')
@ -138,14 +147,14 @@ describe SystemCheck::SimpleExecutor, lib: true do
context 'when check pass' do context 'when check pass' do
it 'prints yes' do it 'prints yes' do
expect_any_instance_of(SimpleCheck).to receive(:check?).and_call_original expect_any_instance_of(SimpleCheck).to receive(:check?).and_call_original
expect { subject.run_check(SimpleCheck) }.to output(/ \.\.\. yes/).to_stdout expect { subject.run_check(SimpleCheck) }.to output(/ \.\.\. \e\[32myes/).to_stdout
end end
end end
context 'when check fails' do context 'when check fails' do
it 'prints no' do it 'prints no' do
expect_any_instance_of(OtherCheck).to receive(:check?).and_call_original expect_any_instance_of(OtherCheck).to receive(:check?).and_call_original
expect { subject.run_check(OtherCheck) }.to output(/ \.\.\. no/).to_stdout expect { subject.run_check(OtherCheck) }.to output(/ \.\.\. \e\[31mno/).to_stdout
end end
it 'displays error message from #show_error' do it 'displays error message from #show_error' do
@ -219,5 +228,11 @@ describe SystemCheck::SimpleExecutor, lib: true do
end end
end end
end end
context 'when there is an exception' do
it 'rescues the exception' do
expect{ subject.run_check(BugousCheck) }.not_to raise_exception
end
end
end end
end end