diff options
-rw-r--r-- | lib/chef/dsl/recipe.rb | 12 | ||||
-rw-r--r-- | spec/unit/recipe_spec.rb | 13 |
2 files changed, 20 insertions, 5 deletions
diff --git a/lib/chef/dsl/recipe.rb b/lib/chef/dsl/recipe.rb index d8d0b158b3..a3b6a8cef0 100644 --- a/lib/chef/dsl/recipe.rb +++ b/lib/chef/dsl/recipe.rb @@ -55,12 +55,14 @@ class Chef # Otherwise, we're rocking the regular resource call route. declare_resource(method_symbol, args[0], caller[0], &block) else - super + begin + super + rescue NoMethodError + raise NoMethodError, "No resource or method named `#{method_symbol}' for #{describe_self_for_error}" + rescue NameError + raise NameError, "No resource, method, or local variable named `#{method_symbol}' for #{describe_self_for_error}" + end end - rescue NoMethodError - raise NoMethodError, "No resource or method named `#{method_symbol}' for #{describe_self_for_error}" - rescue NameError - raise NameError, "No resource, method, or local variable named `#{method_symbol}' for #{describe_self_for_error}" end def has_resource_definition?(name) diff --git a/spec/unit/recipe_spec.rb b/spec/unit/recipe_spec.rb index 612eae2b8e..6bea1457f9 100644 --- a/spec/unit/recipe_spec.rb +++ b/spec/unit/recipe_spec.rb @@ -202,6 +202,19 @@ describe Chef::Recipe do end + describe "when creating a resource that contains an error in the attributes block" do + + it "does not obfuscate the error source" do + lambda do + @recipe.zen_master("klopp") do + this_method_doesnt_exist + end + end.should raise_error(NoMethodError, "undefined method `this_method_doesnt_exist' for Chef::Resource::ZenMaster") + + end + + end + describe "resource definitions" do it "should execute defined resources" do crow_define = Chef::ResourceDefinition.new |