Implement `set?' task keyword:
When called from a task, will return true when given key exists and false when key does not exist.
This commit is contained in:
parent
1465b98f18
commit
3b413a242f
@ -56,3 +56,16 @@ Feature: key/value registry
|
||||
"""
|
||||
When I successfully execute the recipe
|
||||
Then the output must contain "some_value"
|
||||
|
||||
Scenario: `set?' keyword tests wether given key is defined
|
||||
Given a recipe with:
|
||||
"""
|
||||
set :some_key, 'some_value'
|
||||
task :registry_testing do
|
||||
echo 'some_value_set' if set? :some_key
|
||||
echo 'other_value' if set? :other_key
|
||||
end
|
||||
"""
|
||||
When I execute the recipe
|
||||
Then the output must contain "some_value_set"
|
||||
And the output must not contain "other_value"
|
||||
|
@ -2,7 +2,7 @@ module Producer
|
||||
module Core
|
||||
class Env
|
||||
extend Forwardable
|
||||
def_delegators :@registry, :[]=
|
||||
def_delegators :@registry, :[]=, :key?
|
||||
|
||||
attr_reader :input, :output, :error_output, :registry, :logger
|
||||
attr_accessor :target, :verbose, :debug, :dry_run
|
||||
|
@ -17,6 +17,7 @@ module Producer
|
||||
def_delegators :@name, :to_s
|
||||
def_delegators :@env, :target
|
||||
def_delegator :@env, :[], :get
|
||||
def_delegator :@env, :key?, :set?
|
||||
|
||||
define_action :echo, Actions::Echo
|
||||
define_action :sh, Actions::ShellCommand
|
||||
|
@ -160,6 +160,18 @@ module Producer::Core
|
||||
end
|
||||
end
|
||||
|
||||
describe '#set?' do
|
||||
before { env[:some_key] = :some_value }
|
||||
|
||||
it 'returns true when given key exists' do
|
||||
expect(task.set? :some_key).to be true
|
||||
end
|
||||
|
||||
it 'returns false when given key does not exist' do
|
||||
expect(task.set? :other_key).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#target' do
|
||||
before { env.target = :some_target }
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user