summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2015-06-23 12:04:19 -0700
committerJohn Keiser <john@johnkeiser.com>2015-06-23 12:04:19 -0700
commit35e07bb402a215389eb674045cec78364a64a779 (patch)
tree36e99a8bb2d67720cf3c000769c1649b2fa14ea8
parent87e631c3f0b8c440044e2e85a084b3bfc221cbed (diff)
downloadchef-jk/remove_lwrp_warning.tar.gz
Get rid of warning when defining an LWRPjk/remove_lwrp_warning
-rw-r--r--lib/chef/resource.rb27
-rw-r--r--spec/integration/recipes/lwrp_spec.rb8
2 files changed, 15 insertions, 20 deletions
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb
index 418b0dc1ce..ed0dbb50a7 100644
--- a/lib/chef/resource.rb
+++ b/lib/chef/resource.rb
@@ -1318,23 +1318,22 @@ class Chef
# when Chef::Resource::MyLwrp
# end
#
- resource_subclass = class_eval <<-EOM, __FILE__, __LINE__+1
- class Chef::Resource::#{class_name} < resource_class
- resource_name nil # we do not actually provide anything
- def initialize(*args, &block)
- 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.")
+ resource_subclass = Class.new(resource_class) do
+ resource_name nil # we do not actually provide anything
+ def initialize(*args, &block)
+ Chef::Log.deprecation("Using an LWRP by its name (#{self.class.name}) directly is no longer supported in Chef 13 and will be removed. Use Chef::Resource.resource_for_node(node, name) instead.")
+ super
+ end
+ def self.resource_name(*args)
+ if args.empty?
+ @resource_name ||= superclass.resource_name
+ else
super
end
- def self.resource_name(*args)
- if args.empty?
- @resource_name ||= superclass.resource_name
- else
- super
- end
- end
- self
end
- EOM
+ self
+ end
+ eval("Chef::Resource::#{class_name} = resource_subclass")
# Make case, is_a and kind_of work with the new subclass, for backcompat.
# Any subclass of Chef::Resource::ResourceClass is already a subclass of resource_class
# Any subclass of resource_class is considered a subclass of Chef::Resource::ResourceClass
diff --git a/spec/integration/recipes/lwrp_spec.rb b/spec/integration/recipes/lwrp_spec.rb
index e93763fddc..7ecdfc7c3a 100644
--- a/spec/integration/recipes/lwrp_spec.rb
+++ b/spec/integration/recipes/lwrp_spec.rb
@@ -45,12 +45,8 @@ log_level :warn
EOM
result = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" --no-color -F doc -o 'l-w-r-p::default'", :cwd => chef_dir)
- actual = result.stdout.lines.map { |l| l.chomp }.join("\n")
- expected = <<EOM
- * l_w_r_p_foo[me] action create (up to date)
-EOM
- expected = expected.lines.map { |l| l.chomp }.join("\n")
- expect(actual).to include(expected)
+ expect(result.stdout).to match(/\* l_w_r_p_foo\[me\] action create \(up to date\)/)
+ expect(result.stdout).not_to match(/WARN: You are overriding l_w_r_p_foo/)
result.error!
end
end