From c7295fb9774713b5d39df818664241db678140c3 Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Sun, 28 Jul 2013 18:38:00 +0000 Subject: [PATCH] Implement source keyword feature for recipes --- features/recipe.feature | 13 +++++++++++++ lib/producer/core/recipe.rb | 7 +++++++ spec/fixtures/recipes/error.rb | 1 + spec/producer/core/recipe_spec.rb | 9 +++++++++ 4 files changed, 30 insertions(+) create mode 100644 spec/fixtures/recipes/error.rb diff --git a/features/recipe.feature b/features/recipe.feature index 8984e54..b8e85e6 100644 --- a/features/recipe.feature +++ b/features/recipe.feature @@ -8,3 +8,16 @@ Feature: recipe evaluation When I execute the recipe Then the exit status must be 0 And the output must contain "hello from recipe" + + 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" diff --git a/lib/producer/core/recipe.rb b/lib/producer/core/recipe.rb index beb49f0..ea37846 100644 --- a/lib/producer/core/recipe.rb +++ b/lib/producer/core/recipe.rb @@ -24,6 +24,13 @@ module Producer instance_eval &block end end + + + private + + def source(filepath) + instance_eval File.read("./#{filepath}.rb") + end end end end diff --git a/spec/fixtures/recipes/error.rb b/spec/fixtures/recipes/error.rb new file mode 100644 index 0000000..1c3b23b --- /dev/null +++ b/spec/fixtures/recipes/error.rb @@ -0,0 +1 @@ +raise 'error from recipe' diff --git a/spec/producer/core/recipe_spec.rb b/spec/producer/core/recipe_spec.rb index 533a0dc..d31b00c 100644 --- a/spec/producer/core/recipe_spec.rb +++ b/spec/producer/core/recipe_spec.rb @@ -45,6 +45,15 @@ module Producer::Core expect { dsl }.to raise_error(RuntimeError, 'error from recipe') end end + + describe '#source' do + let(:code) { "source '#{fixture_path_for 'recipes/error'}'" } + let(:dsl) { Recipe::DSL.new code } + + it 'evaluates its code' do + expect { dsl }.to raise_error(RuntimeError, 'error from recipe') + end + end end end end