Accept a default value for `get' registry keyword

This commit is contained in:
Thibault Jouan 2014-11-18 15:56:25 +00:00
parent 2d3975d47f
commit 1465b98f18
2 changed files with 13 additions and 3 deletions

View File

@ -46,3 +46,13 @@ Feature: key/value registry
When I execute the recipe When I execute the recipe
Then the output must not contain "after_fail" Then the output must not contain "after_fail"
And the output must match /\A\w+Error:\s+:no_key/ And the output must match /\A\w+Error:\s+:no_key/
Scenario: `get' keyword accepts a default value
Given a recipe with:
"""
task :registry_testing do
echo get(:some_key, 'some_value')
end
"""
When I successfully execute the recipe
Then the output must contain "some_value"

View File

@ -20,10 +20,10 @@ module Producer
@remote ||= Remote.new(target) @remote ||= Remote.new(target)
end end
def [](key) def [](*args)
@registry.fetch key @registry.fetch *args
rescue KeyError rescue KeyError
fail RegistryKeyError, key.inspect fail RegistryKeyError, args.first.inspect
end end
alias get [] alias get []