summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2015-06-17 17:09:07 -0700
committerJohn Keiser <john@johnkeiser.com>2015-06-18 14:16:13 -0700
commit59717769a12768c62aa18270a51b91c820b67010 (patch)
treeb96afb99f8b7a79f65863d9b5872dcba5305888e
parentde9b1c0d7a0b7eb53c5e66c2dacfb92ccfbf161c (diff)
downloadchef-59717769a12768c62aa18270a51b91c820b67010.tar.gz
Do not set resource_name outside of Chef::Resourcejk/chef-resource-name-only
-rw-r--r--lib/chef/resource.rb4
-rw-r--r--spec/integration/recipes/recipe_dsl_spec.rb34
-rw-r--r--spec/unit/runner_spec.rb4
3 files changed, 20 insertions, 22 deletions
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb
index a85d07df2d..10ad184506 100644
--- a/lib/chef/resource.rb
+++ b/lib/chef/resource.rb
@@ -1108,7 +1108,9 @@ class Chef
@sorted_descendants = nil
# set resource_name automatically if it's not set
if child.name && !child.resource_name
- child.resource_name(convert_to_snake_case(child.name.split('::')[-1]))
+ if child.name =~ /^Chef::Resource::(\w+)$/
+ child.resource_name(convert_to_snake_case($1))
+ end
end
end
diff --git a/spec/integration/recipes/recipe_dsl_spec.rb b/spec/integration/recipes/recipe_dsl_spec.rb
index 05ae72e688..03df3e7bb3 100644
--- a/spec/integration/recipes/recipe_dsl_spec.rb
+++ b/spec/integration/recipes/recipe_dsl_spec.rb
@@ -15,13 +15,8 @@ describe "Recipe DSL methods" do
before(:context) {
class BaseThingy < Chef::Resource
- def initialize(*args, &block)
- super
- @allowed_actions = [ :create ]
- @action = :create
- end
-
resource_name 'base_thingy'
+ default_action :create
class<<self
attr_accessor :created_resource
@@ -61,11 +56,7 @@ describe "Recipe DSL methods" do
before(:context) {
class Chef::Resource::BackcompatThingy < Chef::Resource
- def initialize(*args, &block)
- super
- @allowed_actions = [ :create ]
- @action = :create
- end
+ default_action :create
end
class Chef::Provider::BackcompatThingy < Chef::Provider
def load_current_resource
@@ -114,19 +105,17 @@ describe "Recipe DSL methods" do
}
- it "bar_thingy works" do
- recipe = converge {
+ it "bar_thingy does not work" do
+ expect_converge {
bar_thingy 'blah' do; end
- }
- expect(recipe.logged_warnings).to eq ''
- expect(BaseThingy.created_resource).to eq(RecipeDSLSpecNamespace::Bar::BarThingy)
+ }.to raise_error(NoMethodError)
end
end
- context "With a resource named NoNameThingy with resource_name nil" do
+ context "With a resource named Chef::Resource::NoNameThingy with resource_name nil" do
before(:context) {
- class NoNameThingy < BaseThingy
+ class Chef::Resource::NoNameThingy < BaseThingy
resource_name nil
end
@@ -134,7 +123,7 @@ describe "Recipe DSL methods" do
it "no_name_thingy does not work" do
expect_converge {
- thingy 'blah' do; end
+ no_name_thingy 'blah' do; end
}.to raise_error(NoMethodError)
end
end
@@ -199,6 +188,7 @@ describe "Recipe DSL methods" do
before(:context) {
class AnotherNoNameThingy3 < BaseThingy
+ resource_name :another_no_name_thingy_3
provides :another_no_name_thingy3, os: 'blarghle'
end
@@ -227,6 +217,7 @@ describe "Recipe DSL methods" do
before(:context) {
class AnotherNoNameThingy4 < BaseThingy
+ resource_name :another_no_name_thingy_4
provides :another_no_name_thingy4, os: 'blarghle'
provides :another_no_name_thingy4, platform_family: 'foo'
end
@@ -418,6 +409,7 @@ describe "Recipe DSL methods" do
before {
eval <<-EOM, nil, __FILE__, __LINE__+1
class #{class_name} < BaseThingy
+ resource_name #{dsl_method.inspect}
end
EOM
}
@@ -426,6 +418,7 @@ describe "Recipe DSL methods" do
eval <<-EOM, nil, __FILE__, __LINE__+1
module BlahModule
class #{class_name} < BaseThingy
+ resource_name #{dsl_method.inspect}
end
end
EOM
@@ -491,6 +484,7 @@ describe "Recipe DSL methods" do
eval <<-EOM, nil, __FILE__, __LINE__+1
module BlahModule
class BlahModule::#{class_name} < BaseThingy
+ resource_name #{dsl_method.inspect}
provides #{dsl_method.inspect}, os: 'blarghle'
end
end
@@ -611,6 +605,7 @@ describe "Recipe DSL methods" do
before(:context) {
class RecipeDSLSpecNamespace::Thingy6 < BaseThingy
+ resource_name :thingy6
provides :thingy5
end
@@ -640,6 +635,7 @@ describe "Recipe DSL methods" do
before(:context) {
class RecipeDSLSpecNamespace::Thingy7 < BaseThingy
+ resource_name :thingy7
provides :thingy8
end
diff --git a/spec/unit/runner_spec.rb b/spec/unit/runner_spec.rb
index 82e57e068c..b30f818da1 100644
--- a/spec/unit/runner_spec.rb
+++ b/spec/unit/runner_spec.rb
@@ -273,8 +273,8 @@ describe Chef::Runner do
expected_message =<<-E
Multiple failures occurred:
-* FailureProvider::ChefClientFail occurred in delayed notification: failure_resource[explode] (dynamically defined) had an error: FailureProvider::ChefClientFail: chef had an error of some sort
-* FailureProvider::ChefClientFail occurred in delayed notification: failure_resource[explode again] (dynamically defined) had an error: FailureProvider::ChefClientFail: chef had an error of some sort
+* FailureProvider::ChefClientFail occurred in delayed notification: [explode] (dynamically defined) had an error: FailureProvider::ChefClientFail: chef had an error of some sort
+* FailureProvider::ChefClientFail occurred in delayed notification: [explode again] (dynamically defined) had an error: FailureProvider::ChefClientFail: chef had an error of some sort
E
expect(exception.message).to eq(expected_message)