summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2015-04-25 09:54:23 -0700
committerJohn Keiser <john@johnkeiser.com>2015-05-13 13:42:33 -0700
commita2e600d2fbd0233603a5ac43b5b953ba095362da (patch)
tree9c66c61f14c36b5165da35a542e3d4dfeb2c01a2
parentf605a8676c01e0b9b793a7645b814fe177fbd45e (diff)
downloadchef-a2e600d2fbd0233603a5ac43b5b953ba095362da.tar.gz
Remove automatic `provides`
-rw-r--r--lib/chef/resource.rb26
-rw-r--r--lib/chef/resource_resolver.rb8
-rw-r--r--spec/integration/recipes/recipe_dsl_spec.rb29
3 files changed, 15 insertions, 48 deletions
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb
index 194a82b61b..c7d9f9549d 100644
--- a/lib/chef/resource.rb
+++ b/lib/chef/resource.rb
@@ -973,38 +973,12 @@ class Chef
end
end
- # Cause each subclass to register itself with the DSL
- def self.inherited(subclass)
- super
- if subclass.dsl_name
- subclass.provides subclass.dsl_name.to_sym
- subclass.using_automatic_dsl = true
- end
- end
-
- def self.using_automatic_dsl?
- @using_automatic_dsl
- end
-
- def self.using_automatic_dsl=(value)
- @using_automatic_dsl = value
- end
-
def self.provides(name, *args, &block)
- # If the user specifies provides, then we get rid of the auto-provided DSL
- # and let them specify what they want
- if using_automatic_dsl?
- provides_nothing
- end
-
super
-
Chef::DSL::Resources.add_resource_dsl(name)
end
def self.provides_nothing
- @using_automatic_dsl = false
-
unprovided_names = super
unprovided_names.each do |name|
diff --git a/lib/chef/resource_resolver.rb b/lib/chef/resource_resolver.rb
index e9aec11f62..c9bf2e189a 100644
--- a/lib/chef/resource_resolver.rb
+++ b/lib/chef/resource_resolver.rb
@@ -106,11 +106,9 @@ class Chef
resource_class = Chef::Resource.const_get(class_name)
if resource_class <= Chef::Resource && !enabled_handlers.include?(resource_class)
enabled_handlers << resource_class
- if resource_class.using_automatic_dsl?
- Chef::Log.warn("Class #{resource_class} was created with Class.new and assigned directly to a constant (#{resource_class.name} = <class>) rather than being created directly (class #{resource_class.name} < <superclass>).")
- Chef::Log.warn("This will no longer work in Chef 13: you can either declare your class directly (in any namespace), or specify 'provides #{resource.to_sym.inspect}' in the class definition.")
- resource_class.provides resource.to_sym
- end
+ Chef::Log.warn("Class Chef::Resource::#{class_name} does not declare `provides #{resource.inspect}`.")
+ Chef::Log.warn("This will no longer work in Chef 13: you must use `provides` to provide DSL.")
+ resource_class.provides resource.to_sym
end
end
end
diff --git a/spec/integration/recipes/recipe_dsl_spec.rb b/spec/integration/recipes/recipe_dsl_spec.rb
index 5442aeffc0..0b4ea80112 100644
--- a/spec/integration/recipes/recipe_dsl_spec.rb
+++ b/spec/integration/recipes/recipe_dsl_spec.rb
@@ -43,7 +43,7 @@ describe "Recipe DSL methods" do
BaseThingy.created_provider = nil
end
- context "Automatic resource DSL" do
+ context "Deprecated automatic resource DSL" do
context "With a resource 'backcompat_thingy' declared in Chef::Resource and Chef::Provider" do
before(:context) {
@@ -67,9 +67,10 @@ describe "Recipe DSL methods" do
}
it "backcompat_thingy creates a Chef::Resource::BackcompatThingy" do
- expect_recipe {
+ recipe = converge {
backcompat_thingy 'blah' do; end
- }.to emit_no_warnings_or_errors
+ }
+ expect(recipe.logged_warnings).to match /Chef::Resource/i
expect(BaseThingy.created_resource).to eq Chef::Resource::BackcompatThingy
expect(BaseThingy.created_provider).to eq Chef::Provider::BackcompatThingy
end
@@ -77,7 +78,9 @@ describe "Recipe DSL methods" do
context "And another resource 'backcompat_thingy' in BackcompatThingy with 'provides'" do
before(:context) {
- class Foo::BackcompatThingy < BaseThingy; end
+ class Foo::BackcompatThingy < BaseThingy
+ provides :backcompat_thingy
+ end
}
@@ -85,34 +88,26 @@ describe "Recipe DSL methods" do
recipe = converge {
backcompat_thingy 'blah' do; end
}
+ expect(recipe.logged_warnings).to match /Chef::Resource/i
expect(recipe.logged_warnings).to match /ambiguous resource precedence/i
expect(BaseThingy.created_resource).not_to be_nil
end
end
end
- context "With a resource 'thingy' declared in Foo::Bar::Thingy2" do
+ context "With a resource named Foo::Bar::Thingy" do
before(:context) {
class Foo::Bar::Thingy < BaseThingy; end
}
- it "thingy creates a Foo::Bar::Thingy" do
- expect_recipe {
+ it "thingy does not work" do
+ expect_converge {
thingy 'blah' do; end
- }.to emit_no_warnings_or_errors
- expect(BaseThingy.created_resource).to eq Foo::Bar::Thingy
+ }.to raise_error(NoMethodError)
end
end
-
- it "When resource 'thingy2' does not exist and is created during the recipe, it still works" do
- expect_recipe {
- class Foo::Thingy2 < BaseThingy; end
- thingy2 'blah' do; end
- }.to emit_no_warnings_or_errors
- expect(BaseThingy.created_resource).to eq Foo::Thingy2
- end
end
context "provides" do