From 1465b98f18260c39daafe52d0568cd2cd1b88de2 Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Tue, 18 Nov 2014 15:56:25 +0000 Subject: [PATCH] Accept a default value for `get' registry keyword --- features/registry.feature | 10 ++++++++++ lib/producer/core/env.rb | 6 +++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/features/registry.feature b/features/registry.feature index b11f610..5cc0524 100644 --- a/features/registry.feature +++ b/features/registry.feature @@ -46,3 +46,13 @@ Feature: key/value registry When I execute the recipe Then the output must not contain "after_fail" 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" diff --git a/lib/producer/core/env.rb b/lib/producer/core/env.rb index 035582b..38f47c6 100644 --- a/lib/producer/core/env.rb +++ b/lib/producer/core/env.rb @@ -20,10 +20,10 @@ module Producer @remote ||= Remote.new(target) end - def [](key) - @registry.fetch key + def [](*args) + @registry.fetch *args rescue KeyError - fail RegistryKeyError, key.inspect + fail RegistryKeyError, args.first.inspect end alias get []