From bd1bdba9cf871617b9d525b93987aacc2b28ed36 Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Tue, 6 Aug 2013 19:38:33 +0000 Subject: [PATCH] Fix CLI#evaluate_recipe_file spec: The spec wasn't covering the case when recipe evaluation raises an unexpected error. --- spec/producer/core/cli_spec.rb | 48 +++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/spec/producer/core/cli_spec.rb b/spec/producer/core/cli_spec.rb index 48c0733..26b47e1 100644 --- a/spec/producer/core/cli_spec.rb +++ b/spec/producer/core/cli_spec.rb @@ -80,26 +80,38 @@ module Producer::Core let(:stdout) { StringIO.new } subject(:cli) { CLI.new(arguments, stdout) } - it 'exits with a return status of 70' do - expect { cli.evaluate_recipe_file } - .to raise_error(SystemExit) { |e| - expect(e.status).to eq 70 - } + context 'when error is known' do + it 'exits with a return status of 70' do + expect { cli.evaluate_recipe_file } + .to raise_error(SystemExit) { |e| + expect(e.status).to eq 70 + } + end + + it 'prints the specific error' do + trap_exit { cli.evaluate_recipe_file } + expect(stdout.string).to match(/ + \A + #{recipe_file}:4: + .+ + invalid\srecipe\skeyword\s`invalid_keyword' + /x) + end + + it 'excludes producer own source code from the error backtrace' do + trap_exit { cli.evaluate_recipe_file } + expect(stdout.string).to_not match /\/producer-core\// + end end - it 'prints the specific error' do - trap_exit { cli.evaluate_recipe_file } - expect(stdout.string).to match(/ - \A - #{recipe_file}:4: - .+ - invalid\srecipe\skeyword\s`invalid_keyword' - /x) - end - - it 'excludes producer own source code from the error backtrace' do - trap_exit { cli.evaluate_recipe_file } - expect(stdout.string).to_not match /\/producer-core\// + context 'when error is unknown (unexpected)' do + it 'lets the error be' do + UnexpectedError = Class.new(StandardError) + recipe = double('recipe') + allow(Recipe).to receive(:from_file).and_return(recipe) + allow(recipe).to receive(:evaluate).and_raise(UnexpectedError) + expect { cli.evaluate_recipe_file }.to raise_error(UnexpectedError) + end end end end