From f92ad8128d207063894aed8dbd74beb0c4e30392 Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Tue, 21 Jan 2014 17:11:17 +0000 Subject: [PATCH] Implement `set' and `get' recipe keywords: `set' registers a value at given index in env registry, `get' retrieves a value at given index. --- features/recipes/registry.feature | 21 +++++++++++++++++++++ lib/producer/core/recipe/dsl.rb | 8 ++++++++ spec/producer/core/recipe/dsl_spec.rb | 14 ++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 features/recipes/registry.feature diff --git a/features/recipes/registry.feature b/features/recipes/registry.feature new file mode 100644 index 0000000..5cf984d --- /dev/null +++ b/features/recipes/registry.feature @@ -0,0 +1,21 @@ +Feature: key/value registry + + Scenario: `set' keyword registers a value in the registry + Given a recipe with: + """ + set :some_key, 'some_value' + + puts env.registry[:some_key] + """ + When I successfully execute the recipe + Then the output must contain "some_value" + + Scenario: `get' keyword fetches a value from the registry + Given a recipe with: + """ + set :some_key, 'some_value' + + puts get :some_key + """ + When I successfully execute the recipe + Then the output must contain "some_value" diff --git a/lib/producer/core/recipe/dsl.rb b/lib/producer/core/recipe/dsl.rb index 55f5362..311de7e 100644 --- a/lib/producer/core/recipe/dsl.rb +++ b/lib/producer/core/recipe/dsl.rb @@ -37,6 +37,14 @@ module Producer task("#{name}", *args, &block) end end + + def set(key, value) + env[key] = value + end + + def get(key) + env[key] + end end end end diff --git a/spec/producer/core/recipe/dsl_spec.rb b/spec/producer/core/recipe/dsl_spec.rb index a7c39d0..4b0b4d6 100644 --- a/spec/producer/core/recipe/dsl_spec.rb +++ b/spec/producer/core/recipe/dsl_spec.rb @@ -100,5 +100,19 @@ module Producer::Core end end end + + describe '#set' do + it 'registers a key/value pair in env registry' do + dsl.set :some_key, :some_value + expect(env[:some_key]).to eq :some_value + end + end + + describe '#get' do + it 'fetches a value from the registry at given index' do + dsl.set :some_key, :some_value + expect(dsl.get :some_key).to eq :some_value + end + end end end