summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2015-05-27 16:04:47 -0700
committerJohn Keiser <john@johnkeiser.com>2015-06-01 08:02:03 -0700
commita3aba411ccdf1a0a5f236ed3ce2a678a1892e29b (patch)
treec6c5a4da0143b4928e076f57941d72a9c2baa1b0
parent9f8d3fbb943206c27364593b49b875f7254b77be (diff)
downloadchef-a3aba411ccdf1a0a5f236ed3ce2a678a1892e29b.tar.gz
Move resource_name up to Resource, and figure out its value automatically
-rw-r--r--lib/chef/provider/service/macosx.rb2
-rw-r--r--lib/chef/resource.rb93
-rw-r--r--lib/chef/resource/apt_package.rb1
-rw-r--r--lib/chef/resource/bash.rb1
-rw-r--r--lib/chef/resource/batch.rb2
-rw-r--r--lib/chef/resource/bff_package.rb6
-rw-r--r--lib/chef/resource/breakpoint.rb4
-rw-r--r--lib/chef/resource/chef_gem.rb1
-rw-r--r--lib/chef/resource/cookbook_file.rb1
-rw-r--r--lib/chef/resource/cron.rb1
-rw-r--r--lib/chef/resource/csh.rb1
-rw-r--r--lib/chef/resource/deploy.rb1
-rw-r--r--lib/chef/resource/deploy_revision.rb8
-rw-r--r--lib/chef/resource/directory.rb1
-rw-r--r--lib/chef/resource/dpkg_package.rb5
-rw-r--r--lib/chef/resource/dsc_resource.rb1
-rw-r--r--lib/chef/resource/dsc_script.rb1
-rw-r--r--lib/chef/resource/easy_install_package.rb5
-rw-r--r--lib/chef/resource/env.rb1
-rw-r--r--lib/chef/resource/erl_call.rb1
-rw-r--r--lib/chef/resource/execute.rb1
-rw-r--r--lib/chef/resource/file.rb1
-rw-r--r--lib/chef/resource/freebsd_package.rb6
-rw-r--r--lib/chef/resource/gem_package.rb1
-rw-r--r--lib/chef/resource/git.rb1
-rw-r--r--lib/chef/resource/group.rb1
-rw-r--r--lib/chef/resource/homebrew_package.rb1
-rw-r--r--lib/chef/resource/http_request.rb1
-rw-r--r--lib/chef/resource/ifconfig.rb1
-rw-r--r--lib/chef/resource/ips_package.rb1
-rw-r--r--lib/chef/resource/link.rb1
-rw-r--r--lib/chef/resource/log.rb1
-rw-r--r--lib/chef/resource/lwrp_base.rb29
-rw-r--r--lib/chef/resource/macosx_service.rb3
-rw-r--r--lib/chef/resource/macports_package.rb5
-rw-r--r--lib/chef/resource/mdadm.rb1
-rw-r--r--lib/chef/resource/mount.rb1
-rw-r--r--lib/chef/resource/ohai.rb1
-rw-r--r--lib/chef/resource/openbsd_package.rb7
-rw-r--r--lib/chef/resource/package.rb1
-rw-r--r--lib/chef/resource/pacman_package.rb5
-rw-r--r--lib/chef/resource/paludis_package.rb1
-rw-r--r--lib/chef/resource/perl.rb1
-rw-r--r--lib/chef/resource/portage_package.rb1
-rw-r--r--lib/chef/resource/powershell_script.rb2
-rw-r--r--lib/chef/resource/python.rb1
-rw-r--r--lib/chef/resource/reboot.rb1
-rw-r--r--lib/chef/resource/registry_key.rb1
-rw-r--r--lib/chef/resource/remote_directory.rb1
-rw-r--r--lib/chef/resource/remote_file.rb1
-rw-r--r--lib/chef/resource/route.rb1
-rw-r--r--lib/chef/resource/rpm_package.rb1
-rw-r--r--lib/chef/resource/ruby.rb1
-rw-r--r--lib/chef/resource/ruby_block.rb1
-rw-r--r--lib/chef/resource/scm.rb1
-rw-r--r--lib/chef/resource/script.rb1
-rw-r--r--lib/chef/resource/service.rb1
-rw-r--r--lib/chef/resource/smartos_package.rb6
-rw-r--r--lib/chef/resource/solaris_package.rb7
-rw-r--r--lib/chef/resource/subversion.rb1
-rw-r--r--lib/chef/resource/template.rb1
-rw-r--r--lib/chef/resource/user.rb1
-rw-r--r--lib/chef/resource/whyrun_safe_ruby_block.rb5
-rw-r--r--lib/chef/resource/windows_package.rb3
-rw-r--r--lib/chef/resource/windows_script.rb4
-rw-r--r--lib/chef/resource/windows_service.rb3
-rw-r--r--lib/chef/resource/yum_package.rb1
-rw-r--r--spec/integration/recipes/provider_choice.rb1
-rw-r--r--spec/integration/recipes/recipe_dsl_spec.rb5
-rw-r--r--spec/support/lib/chef/resource/cat.rb1
-rw-r--r--spec/support/lib/chef/resource/one_two_three_four.rb5
-rw-r--r--spec/support/lib/chef/resource/with_state.rb11
-rw-r--r--spec/support/lib/chef/resource/zen_follower.rb5
-rw-r--r--spec/support/lib/chef/resource/zen_master.rb1
-rw-r--r--spec/unit/lwrp_spec.rb8
-rw-r--r--spec/unit/resource/timestamped_deploy_spec.rb3
-rw-r--r--spec/unit/resource_spec.rb103
77 files changed, 183 insertions, 216 deletions
diff --git a/lib/chef/provider/service/macosx.rb b/lib/chef/provider/service/macosx.rb
index 7cfe57a92a..7324822eff 100644
--- a/lib/chef/provider/service/macosx.rb
+++ b/lib/chef/provider/service/macosx.rb
@@ -28,8 +28,8 @@ class Chef
class Service
class Macosx < Chef::Provider::Service::Simple
- provides :service, os: "darwin"
provides :macosx_service, os: "darwin"
+ provides :service, os: "darwin"
def self.gather_plist_dirs
locations = %w{/Library/LaunchAgents
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb
index 18759b29f7..6c82b5668c 100644
--- a/lib/chef/resource.rb
+++ b/lib/chef/resource.rb
@@ -57,6 +57,8 @@ class Chef
include Chef::Mixin::ShellOut
include Chef::Mixin::PowershellOut
+ NULL_ARG = Object.new
+
#
# The node the current Chef run is using.
#
@@ -88,7 +90,6 @@ class Chef
run_context.resource_collection.find(*args)
end
-
#
# Resource User Interface (for users)
#
@@ -606,7 +607,7 @@ class Chef
#
def to_s
- "#{@resource_name}[#{@name}]"
+ "#{resource_name}[#{name}]"
end
def to_text
@@ -825,23 +826,15 @@ class Chef
end
#
- # The DSL name of this resource (e.g. `package` or `yum_package`)
- #
- # @return [String] The DSL name of this resource.
- def self.dsl_name
- Chef::Log.deprecation "Resource.dsl_name is deprecated and will be removed in Chef 11. Use resource.resource_name instead."
- if name
- name = self.name.split('::')[-1]
- convert_to_snake_case(name)
- end
- end
-
+ # The display name of this resource type, for printing purposes.
#
- # The name of this resource (e.g. `file`)
+ # Will be used to print out the resource in messages, e.g. resource_name[name]
#
- # @return [String] The name of this resource.
+ # @return [Symbol] The name of this resource type (e.g. `:execute`).
#
- attr_reader :resource_name
+ def resource_name
+ @resource_name || self.class.resource_name
+ end
#
# Sets a list of capabilities of the real resource. For example, `:remount`
@@ -873,23 +866,53 @@ class Chef
nil
end
- #
- # The module where Chef should look for providers for this resource.
- # The provider for `MyResource` will be looked up using
- # `provider_base::MyResource`. Defaults to `Chef::Provider`.
- #
- # @param arg [Module] The module containing providers for this resource
- # @return [Module] The module containing providers for this resource
- #
- # @example
- # class MyResource < Chef::Resource
- # provider_base Chef::Provider::Deploy
- # # ...other stuff
- # end
- #
- def self.provider_base(arg=nil)
- @provider_base ||= arg
- @provider_base ||= Chef::Provider
+ # Provider lookup and naming
+ class<<self
+ #
+ # The DSL name of this resource (e.g. `package` or `yum_package`)
+ #
+ # @return [String] The DSL name of this resource.
+ #
+ # @deprecated Use resource_name instead.
+ #
+ def dsl_name
+ Chef::Log.deprecation "Resource.dsl_name is deprecated and will be removed in Chef 11. Use resource_name instead."
+ if name
+ name = self.name.split('::')[-1]
+ convert_to_snake_case(name)
+ end
+ end
+
+ #
+ # The display name of this resource type, for printing purposes.
+ #
+ # @return [Symbol] The name of this resource type (e.g. `:execute`).
+ #
+ attr_accessor :resource_name
+ def resource_name(value=NULL_ARG)
+ if value != NULL_ARG
+ self.resource_name = value.to_sym
+ end
+ @resource_name
+ end
+
+ #
+ # The module where Chef should look for providers for this resource.
+ # The provider for `MyResource` will be looked up using
+ # `provider_base::MyResource`. Defaults to `Chef::Provider`.
+ #
+ # @param arg [Module] The module containing providers for this resource
+ # @return [Module] The module containing providers for this resource
+ #
+ # @example
+ # class MyResource < Chef::Resource
+ # provider_base Chef::Provider::Deploy
+ # # ...other stuff
+ # end
+ #
+ def provider_base(arg=nil)
+ @provider_base ||= arg || Chef::Provider
+ end
end
@@ -984,6 +1007,8 @@ class Chef
def self.provides(name, *args, &block)
result = super
+ # The first time `provides` is called on the class, it is used for resource_name
+ self.resource_name ||= name
Chef::DSL::Resources.add_resource_dsl(name)
result
end
@@ -1162,7 +1187,7 @@ class Chef
def const_missing(class_name)
if deprecated_constants[class_name.to_sym]
- Chef::Log.deprecation("Using an LWRP by its name (#{class_name}) directly is no longer supported in Chef 12 and will be removed. Use Chef::Resource.resource_for_node(node, name) instead.")
+ Chef::Log.deprecation("Using an LWRP by its name (#{class_name}) directly is no longer supported in Chef 13 and will be removed. Use Chef::Resource.resource_for_node(node, name) instead.")
deprecated_constants[class_name.to_sym]
else
raise NameError, "uninitialized constant Chef::Resource::#{class_name}"
diff --git a/lib/chef/resource/apt_package.rb b/lib/chef/resource/apt_package.rb
index f944825ac3..8326e651e5 100644
--- a/lib/chef/resource/apt_package.rb
+++ b/lib/chef/resource/apt_package.rb
@@ -28,7 +28,6 @@ class Chef
def initialize(name, run_context=nil)
super
- @resource_name = :apt_package
@default_release = nil
end
diff --git a/lib/chef/resource/bash.rb b/lib/chef/resource/bash.rb
index 366d8c7bd6..db8f5888af 100644
--- a/lib/chef/resource/bash.rb
+++ b/lib/chef/resource/bash.rb
@@ -26,7 +26,6 @@ class Chef
def initialize(name, run_context=nil)
super
- @resource_name = :bash
@interpreter = "bash"
end
diff --git a/lib/chef/resource/batch.rb b/lib/chef/resource/batch.rb
index c091ec56b6..efe3f2205f 100644
--- a/lib/chef/resource/batch.rb
+++ b/lib/chef/resource/batch.rb
@@ -25,7 +25,7 @@ class Chef
provides :batch, os: "windows"
def initialize(name, run_context=nil)
- super(name, run_context, :batch, "cmd.exe")
+ super(name, run_context, nil, "cmd.exe")
end
end
diff --git a/lib/chef/resource/bff_package.rb b/lib/chef/resource/bff_package.rb
index d4139e7ffe..072db537f8 100644
--- a/lib/chef/resource/bff_package.rb
+++ b/lib/chef/resource/bff_package.rb
@@ -23,12 +23,6 @@ class Chef
class Resource
class BffPackage < Chef::Resource::Package
provides :bff_package
-
- def initialize(name, run_context=nil)
- super
- @resource_name = :bff_package
- end
-
end
end
end
diff --git a/lib/chef/resource/breakpoint.rb b/lib/chef/resource/breakpoint.rb
index 5a55858f71..177f8bdc39 100644
--- a/lib/chef/resource/breakpoint.rb
+++ b/lib/chef/resource/breakpoint.rb
@@ -25,11 +25,9 @@ class Chef
provides :breakpoint
def initialize(action="break", *args)
- @name = caller.first
- super(@name, *args)
+ super(caller.first, *args)
@action = "break"
@allowed_actions << :break
- @resource_name = :breakpoint
end
end
end
diff --git a/lib/chef/resource/chef_gem.rb b/lib/chef/resource/chef_gem.rb
index 59f575a524..6fb20d7c09 100644
--- a/lib/chef/resource/chef_gem.rb
+++ b/lib/chef/resource/chef_gem.rb
@@ -27,7 +27,6 @@ class Chef
def initialize(name, run_context=nil)
super
- @resource_name = :chef_gem
@compile_time = Chef::Config[:chef_gem_compile_time]
@gem_binary = RbConfig::CONFIG['bindir'] + "/gem"
end
diff --git a/lib/chef/resource/cookbook_file.rb b/lib/chef/resource/cookbook_file.rb
index 7be353b648..7191a3cc39 100644
--- a/lib/chef/resource/cookbook_file.rb
+++ b/lib/chef/resource/cookbook_file.rb
@@ -32,7 +32,6 @@ class Chef
def initialize(name, run_context=nil)
super
@provider = Chef::Provider::CookbookFile
- @resource_name = :cookbook_file
@action = "create"
@source = ::File.basename(name)
@cookbook = nil
diff --git a/lib/chef/resource/cron.rb b/lib/chef/resource/cron.rb
index cb16506012..c57a6b05e3 100644
--- a/lib/chef/resource/cron.rb
+++ b/lib/chef/resource/cron.rb
@@ -31,7 +31,6 @@ class Chef
def initialize(name, run_context=nil)
super
- @resource_name = :cron
@action = :create
@allowed_actions.push(:create, :delete)
@minute = "*"
diff --git a/lib/chef/resource/csh.rb b/lib/chef/resource/csh.rb
index d37f1a8e0c..53921e6906 100644
--- a/lib/chef/resource/csh.rb
+++ b/lib/chef/resource/csh.rb
@@ -26,7 +26,6 @@ class Chef
def initialize(name, run_context=nil)
super
- @resource_name = :csh
@interpreter = "csh"
end
diff --git a/lib/chef/resource/deploy.rb b/lib/chef/resource/deploy.rb
index 55e3547b25..2e930674e4 100644
--- a/lib/chef/resource/deploy.rb
+++ b/lib/chef/resource/deploy.rb
@@ -60,7 +60,6 @@ class Chef
def initialize(name, run_context=nil)
super
- @resource_name = :deploy
@deploy_to = name
@environment = nil
@repository_cache = 'cached-copy'
diff --git a/lib/chef/resource/deploy_revision.rb b/lib/chef/resource/deploy_revision.rb
index e144ce2162..fddbea145b 100644
--- a/lib/chef/resource/deploy_revision.rb
+++ b/lib/chef/resource/deploy_revision.rb
@@ -25,20 +25,12 @@ class Chef
provides :deploy_revision
- def initialize(*args, &block)
- super
- @resource_name = :deploy_revision
- end
end
class DeployBranch < Chef::Resource::DeployRevision
provides :deploy_branch
- def initialize(*args, &block)
- super
- @resource_name = :deploy_branch
- end
end
end
diff --git a/lib/chef/resource/directory.rb b/lib/chef/resource/directory.rb
index 1ab7f0d16d..8183a51f8b 100644
--- a/lib/chef/resource/directory.rb
+++ b/lib/chef/resource/directory.rb
@@ -36,7 +36,6 @@ class Chef
def initialize(name, run_context=nil)
super
- @resource_name = :directory
@path = name
@action = :create
@recursive = false
diff --git a/lib/chef/resource/dpkg_package.rb b/lib/chef/resource/dpkg_package.rb
index 35a47e8a82..38adf24cf6 100644
--- a/lib/chef/resource/dpkg_package.rb
+++ b/lib/chef/resource/dpkg_package.rb
@@ -25,11 +25,6 @@ class Chef
provides :dpkg_package, os: "linux"
- def initialize(name, run_context=nil)
- super
- @resource_name = :dpkg_package
- end
-
end
end
end
diff --git a/lib/chef/resource/dsc_resource.rb b/lib/chef/resource/dsc_resource.rb
index 912b683434..dd3b84b58e 100644
--- a/lib/chef/resource/dsc_resource.rb
+++ b/lib/chef/resource/dsc_resource.rb
@@ -28,7 +28,6 @@ class Chef
def initialize(name, run_context)
super
@properties = {}
- @resource_name = :dsc_resource
@resource = nil
@allowed_actions.push(:run)
@action = :run
diff --git a/lib/chef/resource/dsc_script.rb b/lib/chef/resource/dsc_script.rb
index cf96ef6b7f..22b96104dd 100644
--- a/lib/chef/resource/dsc_script.rb
+++ b/lib/chef/resource/dsc_script.rb
@@ -28,7 +28,6 @@ class Chef
super
@allowed_actions.push(:run)
@action = :run
- @resource_name = :dsc_script
@imports = {}
end
diff --git a/lib/chef/resource/easy_install_package.rb b/lib/chef/resource/easy_install_package.rb
index 5286e9a289..dd205cd505 100644
--- a/lib/chef/resource/easy_install_package.rb
+++ b/lib/chef/resource/easy_install_package.rb
@@ -24,11 +24,6 @@ class Chef
provides :easy_install_package
- def initialize(name, run_context=nil)
- super
- @resource_name = :easy_install_package
- end
-
def easy_install_binary(arg=nil)
set_or_return(
:easy_install_binary,
diff --git a/lib/chef/resource/env.rb b/lib/chef/resource/env.rb
index 2072ae5d80..91cfe2070d 100644
--- a/lib/chef/resource/env.rb
+++ b/lib/chef/resource/env.rb
@@ -29,7 +29,6 @@ class Chef
def initialize(name, run_context=nil)
super
- @resource_name = :env
@key_name = name
@value = nil
@action = :create
diff --git a/lib/chef/resource/erl_call.rb b/lib/chef/resource/erl_call.rb
index 75422c55a1..751e1ca341 100644
--- a/lib/chef/resource/erl_call.rb
+++ b/lib/chef/resource/erl_call.rb
@@ -31,7 +31,6 @@ class Chef
def initialize(name, run_context=nil)
super
- @resource_name = :erl_call
@code = "q()." # your erlang code goes here
@cookie = nil # cookie of the erlang node
diff --git a/lib/chef/resource/execute.rb b/lib/chef/resource/execute.rb
index 8fc97d748f..2cdb38093a 100644
--- a/lib/chef/resource/execute.rb
+++ b/lib/chef/resource/execute.rb
@@ -35,7 +35,6 @@ class Chef
def initialize(name, run_context=nil)
super
- @resource_name = :execute
@command = name
@backup = 5
@action = "run"
diff --git a/lib/chef/resource/file.rb b/lib/chef/resource/file.rb
index b36fcc2135..15bd76156c 100644
--- a/lib/chef/resource/file.rb
+++ b/lib/chef/resource/file.rb
@@ -51,7 +51,6 @@ class Chef
def initialize(name, run_context=nil)
super
- @resource_name = :file
@path = name
@backup = 5
@action = "create"
diff --git a/lib/chef/resource/freebsd_package.rb b/lib/chef/resource/freebsd_package.rb
index 9c8db506f8..21ffdba921 100644
--- a/lib/chef/resource/freebsd_package.rb
+++ b/lib/chef/resource/freebsd_package.rb
@@ -29,13 +29,9 @@ class Chef
class FreebsdPackage < Chef::Resource::Package
include Chef::Mixin::ShellOut
+ provides :freebsd_package
provides :package, platform: "freebsd"
- def initialize(name, run_context=nil)
- super
- @resource_name = :freebsd_package
- end
-
def after_created
assign_provider
end
diff --git a/lib/chef/resource/gem_package.rb b/lib/chef/resource/gem_package.rb
index 0e838ca040..b4064a9439 100644
--- a/lib/chef/resource/gem_package.rb
+++ b/lib/chef/resource/gem_package.rb
@@ -26,7 +26,6 @@ class Chef
def initialize(name, run_context=nil)
super
- @resource_name = :gem_package
@clear_sources = false
end
diff --git a/lib/chef/resource/git.rb b/lib/chef/resource/git.rb
index 7156873315..dd757e6eaf 100644
--- a/lib/chef/resource/git.rb
+++ b/lib/chef/resource/git.rb
@@ -26,7 +26,6 @@ class Chef
def initialize(name, run_context=nil)
super
- @resource_name = :git
@additional_remotes = Hash[]
end
diff --git a/lib/chef/resource/group.rb b/lib/chef/resource/group.rb
index 9e8f1309b0..97026ebe74 100644
--- a/lib/chef/resource/group.rb
+++ b/lib/chef/resource/group.rb
@@ -29,7 +29,6 @@ class Chef
def initialize(name, run_context=nil)
super
- @resource_name = :group
@group_name = name
@gid = nil
@members = []
diff --git a/lib/chef/resource/homebrew_package.rb b/lib/chef/resource/homebrew_package.rb
index 73409b13ac..cda9a90cf2 100644
--- a/lib/chef/resource/homebrew_package.rb
+++ b/lib/chef/resource/homebrew_package.rb
@@ -30,7 +30,6 @@ class Chef
def initialize(name, run_context=nil)
super
- @resource_name = :homebrew_package
@homebrew_user = nil
end
diff --git a/lib/chef/resource/http_request.rb b/lib/chef/resource/http_request.rb
index 5986ebd4a0..211b368500 100644
--- a/lib/chef/resource/http_request.rb
+++ b/lib/chef/resource/http_request.rb
@@ -29,7 +29,6 @@ class Chef
def initialize(name, run_context=nil)
super
- @resource_name = :http_request
@message = name
@url = nil
@action = :get
diff --git a/lib/chef/resource/ifconfig.rb b/lib/chef/resource/ifconfig.rb
index 60feba1704..a774992e76 100644
--- a/lib/chef/resource/ifconfig.rb
+++ b/lib/chef/resource/ifconfig.rb
@@ -30,7 +30,6 @@ class Chef
def initialize(name, run_context=nil)
super
- @resource_name = :ifconfig
@target = name
@action = :add
@allowed_actions.push(:add, :delete, :enable, :disable)
diff --git a/lib/chef/resource/ips_package.rb b/lib/chef/resource/ips_package.rb
index c0e699e31a..6b04129a84 100644
--- a/lib/chef/resource/ips_package.rb
+++ b/lib/chef/resource/ips_package.rb
@@ -27,7 +27,6 @@ class Chef
def initialize(name, run_context = nil)
super(name, run_context)
- @resource_name = :ips_package
@allowed_actions.push(:install, :remove, :upgrade)
@accept_license = false
end
diff --git a/lib/chef/resource/link.rb b/lib/chef/resource/link.rb
index 30f8ec86d1..77bc207c49 100644
--- a/lib/chef/resource/link.rb
+++ b/lib/chef/resource/link.rb
@@ -34,7 +34,6 @@ class Chef
def initialize(name, run_context=nil)
verify_links_supported!
super
- @resource_name = :link
@to = nil
@action = :create
@link_type = :symbolic
diff --git a/lib/chef/resource/log.rb b/lib/chef/resource/log.rb
index 87be01aaa9..2233d0129d 100644
--- a/lib/chef/resource/log.rb
+++ b/lib/chef/resource/log.rb
@@ -49,7 +49,6 @@ class Chef
# node<Chef::Node>:: Node where resource will be used
def initialize(name, run_context=nil)
super
- @resource_name = :log
@level = :info
@action = :write
@allowed_actions.push(:write)
diff --git a/lib/chef/resource/lwrp_base.rb b/lib/chef/resource/lwrp_base.rb
index a42261cfc4..dbb14a1a02 100644
--- a/lib/chef/resource/lwrp_base.rb
+++ b/lib/chef/resource/lwrp_base.rb
@@ -35,8 +35,6 @@ class Chef
# so attributes, default action, etc. can be defined with pleasing syntax.
class LWRPBase < Resource
- NULL_ARG = Object.new
-
# Class methods
class <<self
@@ -55,12 +53,11 @@ class Chef
# We load the class first to give it a chance to set its own name
resource_class = Class.new(self)
- resource_class.resource_name = resource_name
- resource_class.run_context = run_context
resource_class.provides resource_name.to_sym
+ resource_class.run_context = run_context
resource_class.class_from_file(filename)
- # Respect resource_name set inside the LWRP
+ # Make a useful string for the class (rather than <Class:312894723894>)
resource_class.instance_eval do
define_singleton_method(:to_s) do
"LWRP resource #{resource_name} from cookbook #{cookbook_name}"
@@ -77,16 +74,6 @@ class Chef
resource_class
end
- def resource_name(arg = NULL_ARG)
- if arg.equal?(NULL_ARG)
- @resource_name
- else
- @resource_name = arg
- end
- end
-
- alias_method :resource_name=, :resource_name
-
# Define an attribute on this resource, including optional validation
# parameters.
def attribute(attr_name, validation_opts={})
@@ -166,16 +153,8 @@ class Chef
private
# Default initializer. Sets the default action and allowed actions.
- def initialize(name, run_context=nil)
- super(name, run_context)
-
- # Raise an exception if the resource_name was not defined
- if self.class.resource_name.nil?
- raise Chef::Exceptions::InvalidResourceSpecification,
- "You must specify `resource_name'!"
- end
-
- @resource_name = self.class.resource_name.to_sym
+ def initialize(*args, &block)
+ super
@action = self.class.default_action
allowed_actions.push(self.class.actions).flatten!
end
diff --git a/lib/chef/resource/macosx_service.rb b/lib/chef/resource/macosx_service.rb
index 879ea99cf8..f1ed4051cb 100644
--- a/lib/chef/resource/macosx_service.rb
+++ b/lib/chef/resource/macosx_service.rb
@@ -22,8 +22,8 @@ class Chef
class Resource
class MacosxService < Chef::Resource::Service
- provides :service, os: "darwin"
provides :macosx_service, os: "darwin"
+ provides :service, os: "darwin"
identity_attr :service_name
@@ -31,7 +31,6 @@ class Chef
def initialize(name, run_context=nil)
super
- @resource_name = :macosx_service
@plist = nil
@session_type = nil
end
diff --git a/lib/chef/resource/macports_package.rb b/lib/chef/resource/macports_package.rb
index 0d4e5dec65..b41c53033c 100644
--- a/lib/chef/resource/macports_package.rb
+++ b/lib/chef/resource/macports_package.rb
@@ -22,11 +22,6 @@ class Chef
provides :macports_package
provides :package, os: "darwin"
-
- def initialize(name, run_context=nil)
- super
- @resource_name = :macports_package
- end
end
end
end
diff --git a/lib/chef/resource/mdadm.rb b/lib/chef/resource/mdadm.rb
index 971b6c51b4..232ca8b2ac 100644
--- a/lib/chef/resource/mdadm.rb
+++ b/lib/chef/resource/mdadm.rb
@@ -31,7 +31,6 @@ class Chef
def initialize(name, run_context=nil)
super
- @resource_name = :mdadm
@chunk = 16
@devices = []
diff --git a/lib/chef/resource/mount.rb b/lib/chef/resource/mount.rb
index 142dec87f7..ff5421a648 100644
--- a/lib/chef/resource/mount.rb
+++ b/lib/chef/resource/mount.rb
@@ -31,7 +31,6 @@ class Chef
def initialize(name, run_context=nil)
super
- @resource_name = :mount
@mount_point = name
@device = nil
@device_type = :device
diff --git a/lib/chef/resource/ohai.rb b/lib/chef/resource/ohai.rb
index e2d12ce395..314fa6526f 100644
--- a/lib/chef/resource/ohai.rb
+++ b/lib/chef/resource/ohai.rb
@@ -28,7 +28,6 @@ class Chef
def initialize(name, run_context=nil)
super
- @resource_name = :ohai
@name = name
@allowed_actions.push(:reload)
@action = :reload
diff --git a/lib/chef/resource/openbsd_package.rb b/lib/chef/resource/openbsd_package.rb
index 20a2523e3a..2544faca28 100644
--- a/lib/chef/resource/openbsd_package.rb
+++ b/lib/chef/resource/openbsd_package.rb
@@ -28,13 +28,9 @@ class Chef
class OpenbsdPackage < Chef::Resource::Package
include Chef::Mixin::ShellOut
+ provides :openbsd_package
provides :package, os: "openbsd"
- def initialize(name, run_context=nil)
- super
- @resource_name = :openbsd_package
- end
-
def after_created
assign_provider
end
@@ -48,4 +44,3 @@ class Chef
end
end
end
-
diff --git a/lib/chef/resource/package.rb b/lib/chef/resource/package.rb
index 5bea894a02..4d9055f659 100644
--- a/lib/chef/resource/package.rb
+++ b/lib/chef/resource/package.rb
@@ -35,7 +35,6 @@ class Chef
@candidate_version = nil
@options = nil
@package_name = name
- @resource_name = :package
@response_file = nil
@response_file_variables = Hash.new
@source = nil
diff --git a/lib/chef/resource/pacman_package.rb b/lib/chef/resource/pacman_package.rb
index 4c45dd004f..d5d3bd76ae 100644
--- a/lib/chef/resource/pacman_package.rb
+++ b/lib/chef/resource/pacman_package.rb
@@ -24,11 +24,6 @@ class Chef
provides :pacman_package, os: "linux"
- def initialize(name, run_context=nil)
- super
- @resource_name = :pacman_package
- end
-
end
end
end
diff --git a/lib/chef/resource/paludis_package.rb b/lib/chef/resource/paludis_package.rb
index 552c96857a..47026373c7 100644
--- a/lib/chef/resource/paludis_package.rb
+++ b/lib/chef/resource/paludis_package.rb
@@ -27,7 +27,6 @@ class Chef
def initialize(name, run_context=nil)
super(name, run_context)
- @resource_name = :paludis_package
@allowed_actions.push(:install, :remove, :upgrade)
@timeout = 3600
end
diff --git a/lib/chef/resource/perl.rb b/lib/chef/resource/perl.rb
index cb741d145a..d99b409901 100644
--- a/lib/chef/resource/perl.rb
+++ b/lib/chef/resource/perl.rb
@@ -26,7 +26,6 @@ class Chef
def initialize(name, run_context=nil)
super
- @resource_name = :perl
@interpreter = "perl"
end
diff --git a/lib/chef/resource/portage_package.rb b/lib/chef/resource/portage_package.rb
index b03b69796a..f835e33c89 100644
--- a/lib/chef/resource/portage_package.rb
+++ b/lib/chef/resource/portage_package.rb
@@ -25,7 +25,6 @@ class Chef
def initialize(name, run_context=nil)
super
- @resource_name = :portage_package
@provider = Chef::Provider::Package::Portage
end
diff --git a/lib/chef/resource/powershell_script.rb b/lib/chef/resource/powershell_script.rb
index 43aafe4df2..065121abe3 100644
--- a/lib/chef/resource/powershell_script.rb
+++ b/lib/chef/resource/powershell_script.rb
@@ -24,7 +24,7 @@ class Chef
provides :powershell_script, os: "windows"
def initialize(name, run_context=nil)
- super(name, run_context, :powershell_script, "powershell.exe")
+ super(name, run_context, nil, "powershell.exe")
@convert_boolean_return = false
end
diff --git a/lib/chef/resource/python.rb b/lib/chef/resource/python.rb
index fffd4d75f6..2eae2562ba 100644
--- a/lib/chef/resource/python.rb
+++ b/lib/chef/resource/python.rb
@@ -25,7 +25,6 @@ class Chef
def initialize(name, run_context=nil)
super
- @resource_name = :python
@interpreter = "python"
end
diff --git a/lib/chef/resource/reboot.rb b/lib/chef/resource/reboot.rb
index 7cd53450ed..3c940ccd27 100644
--- a/lib/chef/resource/reboot.rb
+++ b/lib/chef/resource/reboot.rb
@@ -28,7 +28,6 @@ class Chef
def initialize(name, run_context=nil)
super
- @resource_name = :reboot
@provider = Chef::Provider::Reboot
@allowed_actions.push(:request_reboot, :reboot_now, :cancel)
diff --git a/lib/chef/resource/registry_key.rb b/lib/chef/resource/registry_key.rb
index cc8d05dd53..524ee6c034 100644
--- a/lib/chef/resource/registry_key.rb
+++ b/lib/chef/resource/registry_key.rb
@@ -60,7 +60,6 @@ class Chef
def initialize(name, run_context=nil)
super
- @resource_name = :registry_key
@action = :create
@architecture = :machine
@recursive = false
diff --git a/lib/chef/resource/remote_directory.rb b/lib/chef/resource/remote_directory.rb
index d4108da47a..d0ad6366b6 100644
--- a/lib/chef/resource/remote_directory.rb
+++ b/lib/chef/resource/remote_directory.rb
@@ -34,7 +34,6 @@ class Chef
def initialize(name, run_context=nil)
super
- @resource_name = :remote_directory
@path = name
@source = ::File.basename(name)
@delete = false
diff --git a/lib/chef/resource/remote_file.rb b/lib/chef/resource/remote_file.rb
index df9fb7ad76..0910862142 100644
--- a/lib/chef/resource/remote_file.rb
+++ b/lib/chef/resource/remote_file.rb
@@ -32,7 +32,6 @@ class Chef
def initialize(name, run_context=nil)
super
- @resource_name = :remote_file
@action = "create"
@source = []
@use_etag = true
diff --git a/lib/chef/resource/route.rb b/lib/chef/resource/route.rb
index 8f9172060b..4baa95b4dd 100644
--- a/lib/chef/resource/route.rb
+++ b/lib/chef/resource/route.rb
@@ -30,7 +30,6 @@ class Chef
def initialize(name, run_context=nil)
super
- @resource_name = :route
@target = name
@action = [:add]
@allowed_actions.push(:add, :delete)
diff --git a/lib/chef/resource/rpm_package.rb b/lib/chef/resource/rpm_package.rb
index f00121dd69..85a71fd91b 100644
--- a/lib/chef/resource/rpm_package.rb
+++ b/lib/chef/resource/rpm_package.rb
@@ -27,7 +27,6 @@ class Chef
def initialize(name, run_context=nil)
super
- @resource_name = :rpm_package
@allow_downgrade = false
end
diff --git a/lib/chef/resource/ruby.rb b/lib/chef/resource/ruby.rb
index 2b7644562a..ec7ab0f580 100644
--- a/lib/chef/resource/ruby.rb
+++ b/lib/chef/resource/ruby.rb
@@ -26,7 +26,6 @@ class Chef
def initialize(name, run_context=nil)
super
- @resource_name = :ruby
@interpreter = "ruby"
end
diff --git a/lib/chef/resource/ruby_block.rb b/lib/chef/resource/ruby_block.rb
index 07eec5599d..dce981c8cf 100644
--- a/lib/chef/resource/ruby_block.rb
+++ b/lib/chef/resource/ruby_block.rb
@@ -29,7 +29,6 @@ class Chef
def initialize(name, run_context=nil)
super
- @resource_name = :ruby_block
@action = "run"
@allowed_actions << :create << :run
@block_name = name
diff --git a/lib/chef/resource/scm.rb b/lib/chef/resource/scm.rb
index d41764d595..059532a0a4 100644
--- a/lib/chef/resource/scm.rb
+++ b/lib/chef/resource/scm.rb
@@ -31,7 +31,6 @@ class Chef
def initialize(name, run_context=nil)
super
@destination = name
- @resource_name = :scm
@enable_submodules = false
@enable_checkout = true
@revision = "HEAD"
diff --git a/lib/chef/resource/script.rb b/lib/chef/resource/script.rb
index e2fbb29d0f..c968610271 100644
--- a/lib/chef/resource/script.rb
+++ b/lib/chef/resource/script.rb
@@ -30,7 +30,6 @@ class Chef
def initialize(name, run_context=nil)
super
- @resource_name = :script
# Chef-13: the command variable should be initialized to nil
@command = name
@code = nil
diff --git a/lib/chef/resource/service.rb b/lib/chef/resource/service.rb
index 47d2ab9e12..d515958d21 100644
--- a/lib/chef/resource/service.rb
+++ b/lib/chef/resource/service.rb
@@ -30,7 +30,6 @@ class Chef
def initialize(name, run_context=nil)
super
- @resource_name = :service
@service_name = name
@enabled = nil
@running = nil
diff --git a/lib/chef/resource/smartos_package.rb b/lib/chef/resource/smartos_package.rb
index 99b3b953b0..5bef54076f 100644
--- a/lib/chef/resource/smartos_package.rb
+++ b/lib/chef/resource/smartos_package.rb
@@ -26,12 +26,6 @@ class Chef
provides :smartos_package
provides :package, os: "solaris2", platform_family: "smartos"
- def initialize(name, run_context=nil)
- super
- @resource_name = :smartos_package
- end
-
end
end
end
-
diff --git a/lib/chef/resource/solaris_package.rb b/lib/chef/resource/solaris_package.rb
index 94be4693b6..b7ddd3e77a 100644
--- a/lib/chef/resource/solaris_package.rb
+++ b/lib/chef/resource/solaris_package.rb
@@ -31,13 +31,6 @@ class Chef
node[:platform_version].to_f <= 5.10
end
- def initialize(name, run_context=nil)
- super
- @resource_name = :solaris_package
- end
-
end
end
end
-
-
diff --git a/lib/chef/resource/subversion.rb b/lib/chef/resource/subversion.rb
index e5a2e9d1a5..a66f7c913d 100644
--- a/lib/chef/resource/subversion.rb
+++ b/lib/chef/resource/subversion.rb
@@ -28,7 +28,6 @@ class Chef
super
@svn_arguments = '--no-auth-cache'
@svn_info_args = '--no-auth-cache'
- @resource_name = :subversion
allowed_actions << :force_export
end
diff --git a/lib/chef/resource/template.rb b/lib/chef/resource/template.rb
index 67a9e6a418..0c4f9c6257 100644
--- a/lib/chef/resource/template.rb
+++ b/lib/chef/resource/template.rb
@@ -34,7 +34,6 @@ class Chef
def initialize(name, run_context=nil)
super
- @resource_name = :template
@action = "create"
@source = "#{::File.basename(name)}.erb"
@cookbook = nil
diff --git a/lib/chef/resource/user.rb b/lib/chef/resource/user.rb
index 7d2ec25596..3e78503dbe 100644
--- a/lib/chef/resource/user.rb
+++ b/lib/chef/resource/user.rb
@@ -30,7 +30,6 @@ class Chef
def initialize(name, run_context=nil)
super
- @resource_name = :user
@username = name
@comment = nil
@uid = nil
diff --git a/lib/chef/resource/whyrun_safe_ruby_block.rb b/lib/chef/resource/whyrun_safe_ruby_block.rb
index f512dc67fc..3e76a63147 100644
--- a/lib/chef/resource/whyrun_safe_ruby_block.rb
+++ b/lib/chef/resource/whyrun_safe_ruby_block.rb
@@ -21,11 +21,6 @@ class Chef
class WhyrunSafeRubyBlock < Chef::Resource::RubyBlock
provides :whyrun_safe_ruby_block
- def initialize(name, run_context=nil)
- super
- @resource_name = :whyrun_safe_ruby_block
- end
-
end
end
end
diff --git a/lib/chef/resource/windows_package.rb b/lib/chef/resource/windows_package.rb
index d4f8ae0603..2e1dda4c5a 100644
--- a/lib/chef/resource/windows_package.rb
+++ b/lib/chef/resource/windows_package.rb
@@ -26,13 +26,12 @@ class Chef
class WindowsPackage < Chef::Resource::Package
include Chef::Mixin::Uris
- provides :package, os: "windows"
provides :windows_package, os: "windows"
+ provides :package, os: "windows"
def initialize(name, run_context=nil)
super
@allowed_actions.push(:install, :remove)
- @resource_name = :windows_package
@source ||= source(@package_name)
# Unique to this resource
diff --git a/lib/chef/resource/windows_script.rb b/lib/chef/resource/windows_script.rb
index 1af7a48fe4..48e2b535a8 100644
--- a/lib/chef/resource/windows_script.rb
+++ b/lib/chef/resource/windows_script.rb
@@ -31,8 +31,8 @@ class Chef
def initialize(name, run_context, resource_name, interpreter_command)
super(name, run_context)
@interpreter = interpreter_command
- @resource_name = resource_name
- @default_guard_interpreter = resource_name
+ @resource_name = resource_name if resource_name
+ @default_guard_interpreter = self.resource_name
end
include Chef::Mixin::WindowsArchitectureHelper
diff --git a/lib/chef/resource/windows_service.rb b/lib/chef/resource/windows_service.rb
index 8090adceb0..93949772f7 100644
--- a/lib/chef/resource/windows_service.rb
+++ b/lib/chef/resource/windows_service.rb
@@ -25,8 +25,8 @@ class Chef
# Until #1773 is resolved, you need to manually specify the windows_service resource
# to use action :configure_startup and attribute startup_type
- provides :service, os: "windows"
provides :windows_service, os: "windows"
+ provides :service, os: "windows"
identity_attr :service_name
@@ -34,7 +34,6 @@ class Chef
def initialize(name, run_context=nil)
super
- @resource_name = :windows_service
@allowed_actions.push(:configure_startup)
@startup_type = :automatic
@run_as_user = ""
diff --git a/lib/chef/resource/yum_package.rb b/lib/chef/resource/yum_package.rb
index d8be8c9748..cdf3cc456d 100644
--- a/lib/chef/resource/yum_package.rb
+++ b/lib/chef/resource/yum_package.rb
@@ -28,7 +28,6 @@ class Chef
def initialize(name, run_context=nil)
super
- @resource_name = :yum_package
@flush_cache = { :before => false, :after => false }
@allow_downgrade = false
end
diff --git a/spec/integration/recipes/provider_choice.rb b/spec/integration/recipes/provider_choice.rb
index 999765a1de..ca8ca16e7a 100644
--- a/spec/integration/recipes/provider_choice.rb
+++ b/spec/integration/recipes/provider_choice.rb
@@ -10,7 +10,6 @@ describe "Recipe DSL methods" do
super
@action = :create
@allowed_actions = [ :create ]
- @resource_name = 'provider_thingy'
end
provides :provider_thingy
def to_s
diff --git a/spec/integration/recipes/recipe_dsl_spec.rb b/spec/integration/recipes/recipe_dsl_spec.rb
index 079baaa162..b491f343c5 100644
--- a/spec/integration/recipes/recipe_dsl_spec.rb
+++ b/spec/integration/recipes/recipe_dsl_spec.rb
@@ -9,11 +9,12 @@ describe "Recipe DSL methods" do
class BaseThingy < Chef::Resource
def initialize(*args, &block)
super
- @resource_name = 'base_thingy'
@allowed_actions = [ :create ]
@action = :create
end
+ resource_name 'base_thingy'
+
class<<self
attr_accessor :created_resource
attr_accessor :created_provider
@@ -54,10 +55,10 @@ describe "Recipe DSL methods" do
class Chef::Resource::BackcompatThingy < Chef::Resource
def initialize(*args, &block)
super
- @resource_name = 'backcompat_thingy'
@allowed_actions = [ :create ]
@action = :create
end
+ resource_name 'backcompat_thingy'
end
class Chef::Provider::BackcompatThingy < Chef::Provider
def load_current_resource
diff --git a/spec/support/lib/chef/resource/cat.rb b/spec/support/lib/chef/resource/cat.rb
index 641ce28795..01dbe4a272 100644
--- a/spec/support/lib/chef/resource/cat.rb
+++ b/spec/support/lib/chef/resource/cat.rb
@@ -24,7 +24,6 @@ class Chef
attr_accessor :action
def initialize(name, run_context=nil)
- @resource_name = :cat
super
@action = "sell"
end
diff --git a/spec/support/lib/chef/resource/one_two_three_four.rb b/spec/support/lib/chef/resource/one_two_three_four.rb
index d7e5ea095e..9199b0e247 100644
--- a/spec/support/lib/chef/resource/one_two_three_four.rb
+++ b/spec/support/lib/chef/resource/one_two_three_four.rb
@@ -23,11 +23,6 @@ class Chef
attr_reader :i_can_count
- def initialize(name, run_context)
- @resource_name = :one_two_three_four
- super
- end
-
def i_can_count(tf)
@i_can_count = tf
end
diff --git a/spec/support/lib/chef/resource/with_state.rb b/spec/support/lib/chef/resource/with_state.rb
index 226de0a6d2..91051cca58 100644
--- a/spec/support/lib/chef/resource/with_state.rb
+++ b/spec/support/lib/chef/resource/with_state.rb
@@ -22,16 +22,9 @@ require 'chef/json_compat'
class Chef
class Resource
class WithState < Chef::Resource
- attr_accessor :state
-
- def initialize(name, run_context=nil)
- @resource_name = :with_state
- super
- end
+ resource_name :with_state
- def state
- @state
- end
+ attr_accessor :state
end
end
end
diff --git a/spec/support/lib/chef/resource/zen_follower.rb b/spec/support/lib/chef/resource/zen_follower.rb
index 590aa0827b..c4f3f44d88 100644
--- a/spec/support/lib/chef/resource/zen_follower.rb
+++ b/spec/support/lib/chef/resource/zen_follower.rb
@@ -25,11 +25,6 @@ class Chef
provides :follower, platform: "zen"
- def initialize(name, run_context=nil)
- @resource_name = :zen_follower
- super
- end
-
def master(arg=nil)
if !arg.nil?
@master = arg
diff --git a/spec/support/lib/chef/resource/zen_master.rb b/spec/support/lib/chef/resource/zen_master.rb
index 145dd70e64..18661dc05c 100644
--- a/spec/support/lib/chef/resource/zen_master.rb
+++ b/spec/support/lib/chef/resource/zen_master.rb
@@ -27,7 +27,6 @@ class Chef
attr_reader :peace
def initialize(name, run_context=nil)
- @resource_name = :zen_master
super
allowed_actions << :win << :score
end
diff --git a/spec/unit/lwrp_spec.rb b/spec/unit/lwrp_spec.rb
index 659696fd28..8cac70e800 100644
--- a/spec/unit/lwrp_spec.rb
+++ b/spec/unit/lwrp_spec.rb
@@ -229,14 +229,6 @@ describe "LWRP" do
expect(klass.resource_name).to eq(:foo)
end
- context "when creating a new instance" do
- it "raises an exception if resource_name is nil" do
- expect {
- klass.new('blah')
- }.to raise_error(Chef::Exceptions::InvalidResourceSpecification)
- end
- end
-
context "lazy default values" do
let(:klass) do
Class.new(Chef::Resource::LWRPBase) do
diff --git a/spec/unit/resource/timestamped_deploy_spec.rb b/spec/unit/resource/timestamped_deploy_spec.rb
index eca6c570d4..4ebfdaf059 100644
--- a/spec/unit/resource/timestamped_deploy_spec.rb
+++ b/spec/unit/resource/timestamped_deploy_spec.rb
@@ -23,11 +23,10 @@ describe Chef::Resource::TimestampedDeploy, "initialize" do
static_provider_resolution(
resource: Chef::Resource::TimestampedDeploy,
provider: Chef::Provider::Deploy::Timestamped,
- name: :deploy,
+ name: :timestamped_deploy,
action: :deploy,
os: 'linux',
platform_family: 'rhel',
)
end
-
diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb
index 3bfd63f5ab..accf52ba26 100644
--- a/spec/unit/resource_spec.rb
+++ b/spec/unit/resource_spec.rb
@@ -336,6 +336,109 @@ describe Chef::Resource do
end
end
+ describe "self.resource_name" do
+ context "When resource_name is not set" do
+ it "and there is a provides line, it is used for resource_name" do
+ c = Class.new(Chef::Resource) do
+ provides :self_resource_name_test_1
+ end
+
+ r = c.new('hi')
+ r.declared_type = :d
+ expect(c.resource_name).to eq :self_resource_name_test_1
+ expect(r.resource_name).to eq :self_resource_name_test_1
+ expect(r.declared_type).to eq :d
+ end
+ it "and multiple provides lines, the first line is used for resource_name" do
+ c = Class.new(Chef::Resource) do
+ provides :self_resource_name_test_2
+ provides :self_resource_name_test_3
+ end
+
+ r = c.new('hi')
+ r.declared_type = :d
+ expect(c.resource_name).to eq :self_resource_name_test_2
+ expect(r.resource_name).to eq :self_resource_name_test_2
+ expect(r.declared_type).to eq :d
+ end
+ it "and there are no provides lines, resource_name is nil" do
+ c = Class.new(Chef::Resource) do
+ end
+
+ r = c.new('hi')
+ r.declared_type = :d
+ expect(c.resource_name).to be_nil
+ expect(r.resource_name).to be_nil
+ expect(r.declared_type).to eq :d
+ end
+ it "and there are no provides lines, @resource_name is used" do
+ c = Class.new(Chef::Resource) do
+ def initialize(*args, &block)
+ @resource_name = :blah
+ super
+ end
+ end
+
+ r = c.new('hi')
+ r.declared_type = :d
+ expect(c.resource_name).to be_nil
+ expect(r.resource_name).to eq :blah
+ expect(r.declared_type).to eq :d
+ end
+ end
+
+ it "resource_name without provides is honored" do
+ c = Class.new(Chef::Resource) do
+ resource_name 'blah'
+ end
+
+ r = c.new('hi')
+ r.declared_type = :d
+ expect(c.resource_name).to eq :blah
+ expect(r.resource_name).to eq :blah
+ expect(r.declared_type).to eq :d
+ end
+ it "setting class.resource_name with 'resource_name = blah' overrides and declared_type" do
+ c = Class.new(Chef::Resource) do
+ provides :self_resource_name_test_2
+ end
+ c.resource_name = :blah
+
+ r = c.new('hi')
+ r.declared_type = :d
+ expect(c.resource_name).to eq :blah
+ expect(r.resource_name).to eq :blah
+ expect(r.declared_type).to eq :d
+ end
+ it "setting class.resource_name with 'resource_name blah' overrides provides and declared_type" do
+ c = Class.new(Chef::Resource) do
+ resource_name :blah
+ provides :self_resource_name_test_3
+ end
+
+ r = c.new('hi')
+ r.declared_type = :d
+ expect(c.resource_name).to eq :blah
+ expect(r.resource_name).to eq :blah
+ expect(r.declared_type).to eq :d
+ end
+ it "setting @resource_name overrides provides and declared_type" do
+ c = Class.new(Chef::Resource) do
+ provides :self_resource_name_test_4
+ def initialize(*args, &block)
+ @resource_name = :blah
+ super
+ end
+ end
+
+ r = c.new('hi')
+ r.declared_type = :d
+ expect(c.resource_name).to eq :self_resource_name_test_4
+ expect(r.resource_name).to eq :blah
+ expect(r.declared_type).to eq :d
+ end
+ end
+
describe "is" do
it "should return the arguments passed with 'is'" do
zm = Chef::Resource::ZenMaster.new("coffee")