summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTyler Ball <tyler-ball@users.noreply.github.com>2015-08-21 10:05:41 -0600
committerTyler Ball <tyler-ball@users.noreply.github.com>2015-08-21 10:05:41 -0600
commit88752a692e8a17a44174e7f6411b58790684d141 (patch)
tree7522099e95eb5a74114ea59c61dd6cb33744cfe5
parentc832f38fbf26dce0a8e323318b33937cb4a44243 (diff)
parent82f328a811bf4c8a71277d56bfffa631d5f565f5 (diff)
downloadchef-88752a692e8a17a44174e7f6411b58790684d141.tar.gz
Merge pull request #3663 from docwhat/issue-3614
Fix error message for providers without `provides`
-rw-r--r--lib/chef/platform/provider_mapping.rb11
-rw-r--r--spec/integration/recipes/recipe_dsl_spec.rb2
2 files changed, 6 insertions, 7 deletions
diff --git a/lib/chef/platform/provider_mapping.rb b/lib/chef/platform/provider_mapping.rb
index 38dd0e38af..9b511f0237 100644
--- a/lib/chef/platform/provider_mapping.rb
+++ b/lib/chef/platform/provider_mapping.rb
@@ -200,14 +200,13 @@ class Chef
class_name = resource_type.class.name ? resource_type.class.name.split('::').last :
convert_to_class_name(resource_type.resource_name.to_s)
- begin
- result = Chef::Provider.const_get(class_name)
- Chef::Log.warn("Class Chef::Provider::#{class_name} does not declare 'resource_name #{convert_to_snake_case(class_name).to_sym.inspect}'.")
- Chef::Log.warn("This will no longer work in Chef 13: you must use 'resource_name' to provide DSL.")
- rescue NameError
+ if Chef::Provider.const_defined?(class_name)
+ Chef::Log.warn("Class Chef::Provider::#{class_name} does not declare 'provides #{convert_to_snake_case(class_name).to_sym.inspect}'.")
+ Chef::Log.warn("This will no longer work in Chef 13: you must use 'provides' to use the resource's DSL.")
+ return Chef::Provider.const_get(class_name)
end
end
- result
+ nil
end
end
diff --git a/spec/integration/recipes/recipe_dsl_spec.rb b/spec/integration/recipes/recipe_dsl_spec.rb
index fd40e5b6d8..52bca87c99 100644
--- a/spec/integration/recipes/recipe_dsl_spec.rb
+++ b/spec/integration/recipes/recipe_dsl_spec.rb
@@ -119,7 +119,7 @@ describe "Recipe DSL methods" do
recipe = converge {
backcompat_thingy 'blah' do; end
}
- expect(recipe.logged_warnings).to match(/Class Chef::Provider::BackcompatThingy does not declare 'resource_name :backcompat_thingy'./)
+ expect(recipe.logged_warnings).to match(/Class Chef::Provider::BackcompatThingy does not declare 'provides :backcompat_thingy'./)
expect(BaseThingy.created_resource).not_to be_nil
end
end