Improve source recipe keyword feature:
* Improve error reporting from sourced recipe; * Extract cucumber feature from recipe one.
This commit is contained in:
parent
b1c99dbeeb
commit
3792f60a5c
@ -23,16 +23,3 @@ Feature: recipe evaluation
|
|||||||
\AOK
|
\AOK
|
||||||
recipe.rb:3:.+invalid recipe keyword `invalid_keyword'
|
recipe.rb:3:.+invalid recipe keyword `invalid_keyword'
|
||||||
"""
|
"""
|
||||||
|
|
||||||
Scenario: source keyword, requires a recipe file
|
|
||||||
Given a recipe with:
|
|
||||||
"""
|
|
||||||
source 'sourced_recipe'
|
|
||||||
"""
|
|
||||||
And a file named "sourced_recipe.rb" with:
|
|
||||||
"""
|
|
||||||
puts 'sourced recipe'
|
|
||||||
"""
|
|
||||||
When I execute the recipe
|
|
||||||
Then the exit status must be 0
|
|
||||||
And the output must contain "sourced recipe"
|
|
||||||
|
33
features/source.feature
Normal file
33
features/source.feature
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
Feature: source recipe keyword
|
||||||
|
|
||||||
|
Scenario: requires a recipe file
|
||||||
|
Given a recipe with:
|
||||||
|
"""
|
||||||
|
source 'sourced_recipe'
|
||||||
|
"""
|
||||||
|
And a file named "sourced_recipe.rb" with:
|
||||||
|
"""
|
||||||
|
puts 'sourced recipe'
|
||||||
|
"""
|
||||||
|
When I execute the recipe
|
||||||
|
Then the exit status must be 0
|
||||||
|
And the output must contain "sourced recipe"
|
||||||
|
|
||||||
|
Scenario: reports errors from sourced recipes
|
||||||
|
Given a recipe with:
|
||||||
|
"""
|
||||||
|
source 'sourced_recipe'
|
||||||
|
"""
|
||||||
|
And a file named "sourced_recipe.rb" with:
|
||||||
|
"""
|
||||||
|
puts 'OK'
|
||||||
|
|
||||||
|
invalid_keyword
|
||||||
|
"""
|
||||||
|
When I execute the recipe
|
||||||
|
Then the output must match:
|
||||||
|
"""
|
||||||
|
\AOK
|
||||||
|
sourced_recipe.rb:3:.+invalid recipe keyword `invalid_keyword'
|
||||||
|
recipe.rb:1:.+
|
||||||
|
"""
|
@ -27,7 +27,7 @@ module Producer
|
|||||||
private
|
private
|
||||||
|
|
||||||
def source(filepath)
|
def source(filepath)
|
||||||
instance_eval File.read("./#{filepath}.rb")
|
instance_eval File.read("./#{filepath}.rb"), "#{filepath}.rb"
|
||||||
end
|
end
|
||||||
|
|
||||||
def task(name, &block)
|
def task(name, &block)
|
||||||
|
@ -59,12 +59,21 @@ module Producer::Core
|
|||||||
subject(:dsl) { Recipe::DSL.new(&code).evaluate(env) }
|
subject(:dsl) { Recipe::DSL.new(&code).evaluate(env) }
|
||||||
|
|
||||||
describe '#source' do
|
describe '#source' do
|
||||||
let(:code) { "source '#{fixture_path_for 'recipes/error'}'" }
|
let(:filepath) { fixture_path_for 'recipes/error' }
|
||||||
subject(:dsl) { Recipe::DSL.new code }
|
let(:code) { "source '#{filepath}'" }
|
||||||
|
subject(:dsl) { Recipe::DSL.new code }
|
||||||
|
|
||||||
it 'sources the recipe given as argument' do
|
it 'sources the recipe given as argument' do
|
||||||
expect { dsl.evaluate(env) }.to raise_error(RuntimeError, 'error from recipe')
|
expect { dsl.evaluate(env) }.to raise_error(RuntimeError, 'error from recipe')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'invalid sourced recipe' do
|
||||||
|
it 'reports the sourced recipe file path in the error' do
|
||||||
|
expect { dsl.evaluate(env) }.to raise_error(RuntimeError) { |e|
|
||||||
|
expect(e.backtrace.first).to match /\A#{filepath}/
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#tasks' do
|
describe '#tasks' do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user