diff --git a/features/cli/env.feature b/features/cli/env.feature new file mode 100644 index 0000000..07e7b22 --- /dev/null +++ b/features/cli/env.feature @@ -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" diff --git a/lib/producer/core/recipe/dsl.rb b/lib/producer/core/recipe/dsl.rb index 03bb34d..c57d490 100644 --- a/lib/producer/core/recipe/dsl.rb +++ b/lib/producer/core/recipe/dsl.rb @@ -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 diff --git a/spec/producer/core/recipe/dsl_spec.rb b/spec/producer/core/recipe/dsl_spec.rb index 5cd49b6..389bc93 100644 --- a/spec/producer/core/recipe/dsl_spec.rb +++ b/spec/producer/core/recipe/dsl_spec.rb @@ -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}'" }