Allow access to registry from conditions

This commit is contained in:
Thibault Jouan 2014-09-25 00:01:03 +00:00
parent d335abce57
commit 77582ef843
4 changed files with 23 additions and 0 deletions

View File

@ -24,3 +24,13 @@ Feature: key/value registry
""" """
When I successfully execute the recipe When I successfully execute the recipe
Then the output must contain "some_value" Then the output must contain "some_value"
Scenario: `get' keyword fetches a value from a condition
Given a recipe with:
"""
set :some_key, 'some_value'
task(:ok) { condition { get :some_key }; echo get :some_key }
"""
When I successfully execute the recipe
Then the output must contain "some_value"

View File

@ -29,6 +29,9 @@ module Producer
end end
end end
extend Forwardable
def_delegators :@env, :get
define_test :`, Tests::ShellCommandStatus define_test :`, Tests::ShellCommandStatus
define_test :sh, Tests::ShellCommandStatus define_test :sh, Tests::ShellCommandStatus
define_test :file_contains, Tests::FileContains define_test :file_contains, Tests::FileContains

View File

@ -20,6 +20,7 @@ module Producer
def [](key) def [](key)
@registry[key] @registry[key]
end end
alias get []
def []=(key, value) def []=(key, value)
@registry[key] = value @registry[key] = value

View File

@ -173,5 +173,14 @@ module Producer::Core
end end
end end
end end
describe '#get' do
let(:env) { Env.new }
it 'delegates to env registry' do
expect(env).to receive(:get).with :some_key
described_class.evaluate(env, []) { get :some_key }
end
end
end end
end end