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