Add env recipe keyword feature
This commit is contained in:
parent
d677c3aa97
commit
a6e27edfd2
10
features/cli/env.feature
Normal file
10
features/cli/env.feature
Normal file
@ -0,0 +1,10 @@
|
||||
Feature: env recipe keyword
|
||||
|
||||
Scenario: exposes the internal env object
|
||||
Given a recipe with:
|
||||
"""
|
||||
puts env.current_recipe.filepath
|
||||
"""
|
||||
When I execute the recipe
|
||||
Then the exit status must be 0
|
||||
And the output must contain exactly "recipe.rb\n"
|
@ -11,6 +11,7 @@ module Producer
|
||||
end
|
||||
|
||||
def evaluate(env)
|
||||
@env = env
|
||||
if @code
|
||||
instance_eval @code, env.current_recipe.filepath
|
||||
else
|
||||
@ -25,10 +26,18 @@ module Producer
|
||||
|
||||
private
|
||||
|
||||
def env
|
||||
@env
|
||||
end
|
||||
|
||||
def source(filepath)
|
||||
instance_eval File.read("./#{filepath}.rb"), "#{filepath}.rb"
|
||||
end
|
||||
|
||||
def target(hostname)
|
||||
env.target = hostname
|
||||
end
|
||||
|
||||
def task(name, &block)
|
||||
@tasks << Task.new(name, &block)
|
||||
end
|
||||
|
@ -58,6 +58,15 @@ module Producer::Core
|
||||
context 'DSL specific methods' do
|
||||
subject(:dsl) { Recipe::DSL.new(&code).evaluate(env) }
|
||||
|
||||
describe '#env' do
|
||||
let(:code) { proc { env.some_message } }
|
||||
|
||||
it 'returns the current environment' do
|
||||
expect(env).to receive(:some_message)
|
||||
dsl.evaluate(env)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#source' do
|
||||
let(:filepath) { fixture_path_for 'recipes/throw' }
|
||||
let(:code) { "source '#{filepath}'" }
|
||||
|
Loading…
x
Reference in New Issue
Block a user