Add env recipe keyword feature

This commit is contained in:
Thibault Jouan 2013-08-03 23:06:34 +00:00
parent d677c3aa97
commit a6e27edfd2
3 changed files with 28 additions and 0 deletions

10
features/cli/env.feature Normal file
View 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"

View File

@ -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

View File

@ -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}'" }