Implement recipe error reporting feature

This commit is contained in:
Thibault Jouan
2013-07-29 22:12:03 +00:00
parent f6d9dd2c90
commit e12dd5c0e7
6 changed files with 85 additions and 9 deletions

View File

@@ -5,7 +5,7 @@ module Producer::Core
include FixturesHelpers
let(:code) { 'nil' }
let(:env) { double('env') }
let(:env) { double('env').as_null_object }
subject(:recipe) { Recipe.new(code) }
describe '.from_file' do
@@ -88,6 +88,24 @@ module Producer::Core
it 'returns itself' do
expect(dsl.evaluate(env)).to eq dsl
end
context 'invalid recipe' do
let(:filepath) { fixture_path_for 'recipes/error.rb' }
let(:recipe) { Recipe.from_file(filepath) }
subject(:dsl) { Recipe::DSL.new File.read(filepath) }
it 'reports the recipe file path in the error' do
allow(env).to receive(:current_recipe) { recipe }
expect { dsl.evaluate(env) }.to raise_error(RuntimeError) { |e|
expect(e.backtrace.first).to match /\A#{filepath}/
}
end
it 'raises a RecipeEvaluationError on NameError' do
dsl = Recipe::DSL.new { incorrect_keyword }
expect { dsl.evaluate(env) }.to raise_error(Recipe::RecipeEvaluationError)
end
end
end
context 'DSL specific methods' do