Allow access to registry from conditions
This commit is contained in:
		| @@ -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" | ||||||
|   | |||||||
| @@ -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 | ||||||
|   | |||||||
| @@ -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 | ||||||
|   | |||||||
| @@ -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 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user