summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/chef/deprecated.rb2
-rw-r--r--spec/unit/chef_class_spec.rb27
2 files changed, 28 insertions, 1 deletions
diff --git a/lib/chef/deprecated.rb b/lib/chef/deprecated.rb
index b490556ddc..944cecf61b 100644
--- a/lib/chef/deprecated.rb
+++ b/lib/chef/deprecated.rb
@@ -68,7 +68,7 @@ class Chef
# Just in case someone uses a symbol in the config by mistake.
silence_spec = silence_spec.to_s
# Check for a silence by deprecation name, or by location.
- self.class.deprecation_key == silence_spec || location.include?(silence_spec)
+ self.class.deprecation_key == silence_spec || self.class.deprecation_id.to_s == silence_spec || "chef-#{self.class.deprecation_id}" == silence_spec.downcase || location.include?(silence_spec)
end
# check if this warning has been silenced by inline comment.
return true if location =~ /^(.*?):(\d+):in/ && begin
diff --git a/spec/unit/chef_class_spec.rb b/spec/unit/chef_class_spec.rb
index b6d28e7215..f9ea00090e 100644
--- a/spec/unit/chef_class_spec.rb
+++ b/spec/unit/chef_class_spec.rb
@@ -134,6 +134,33 @@ describe "Chef class" do
Chef.deprecated(:generic, "This is my handle.")
end
+ it "allows silencing specific IDs" do
+ Chef::Config[:silence_deprecation_warnings] = [0]
+ expect(Chef::Log).to receive(:warn).with(/I'm a little teapot/).once
+ expect(Chef::Log).to receive(:warn).with(/This is my handle/).once
+ Chef.deprecated(:generic, "I'm a little teapot.")
+ Chef.deprecated(:internal_api, "Short and stout.")
+ Chef.deprecated(:generic, "This is my handle.")
+ end
+
+ it "allows silencing specific IDs using the CHEF- syntax" do
+ Chef::Config[:silence_deprecation_warnings] = ["CHEF-0"]
+ expect(Chef::Log).to receive(:warn).with(/I'm a little teapot/).once
+ expect(Chef::Log).to receive(:warn).with(/This is my handle/).once
+ Chef.deprecated(:generic, "I'm a little teapot.")
+ Chef.deprecated(:internal_api, "Short and stout.")
+ Chef.deprecated(:generic, "This is my handle.")
+ end
+
+ it "allows silencing specific IDs using the chef- syntax" do
+ Chef::Config[:silence_deprecation_warnings] = ["chef-0"]
+ expect(Chef::Log).to receive(:warn).with(/I'm a little teapot/).once
+ expect(Chef::Log).to receive(:warn).with(/This is my handle/).once
+ Chef.deprecated(:generic, "I'm a little teapot.")
+ Chef.deprecated(:internal_api, "Short and stout.")
+ Chef.deprecated(:generic, "This is my handle.")
+ end
+
it "allows silencing specific lines" do
Chef::Config[:silence_deprecation_warnings] = ["chef_class_spec.rb:#{__LINE__ + 4}"]
expect(Chef::Log).to receive(:warn).with(/I'm a little teapot/).once