diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2015-09-02 18:01:09 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2015-09-14 15:56:00 -0700 |
commit | 72cb4af6451f67791469456899df5bd09db94d7b (patch) | |
tree | 1ccdbe25220634512e9eef58e43c50a9a4ff4907 | |
parent | a300e22d486df119b5588ca28d13f21e5cdb7353 (diff) | |
download | chef-72cb4af6451f67791469456899df5bd09db94d7b.tar.gz |
Remove the warning about hashes and arrays as default values
- This isn't a bug to declare an LWRP default hash or array, its a
bug to use the hash or array in such a way as to mutate it. A lot
of LWRP authors will get this triggered on their code when none of
their users are actually triggering the bug.
- It would be better handled by freezing default values in Chef 13.
- We could also just not try to solve this problem in code and treat
it fundamentally as a documentation/education problem.
-rw-r--r-- | lib/chef/resource.rb | 4 | ||||
-rw-r--r-- | spec/unit/property_spec.rb | 6 |
2 files changed, 0 insertions, 10 deletions
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb index ee75dec3b9..aec78b4f6d 100644 --- a/lib/chef/resource.rb +++ b/lib/chef/resource.rb @@ -808,10 +808,6 @@ class Chef property = property_type(**options) end - if !options[:default].frozen? && (options[:default].is_a?(Array) || options[:default].is_a?(Hash)) - Chef.log_deprecation("Property #{self}.#{name} has an array or hash default (#{options[:default]}). This means that if one resource modifies or appends to it, all other resources of the same type will also see the changes. Either freeze the constant with `.freeze` to prevent appending, or use lazy { #{options[:default].inspect} }.") - end - local_properties = properties(false) local_properties[name] = property diff --git a/spec/unit/property_spec.rb b/spec/unit/property_spec.rb index 50764aa7a2..f758b5f403 100644 --- a/spec/unit/property_spec.rb +++ b/spec/unit/property_spec.rb @@ -480,12 +480,6 @@ describe "Chef::Resource.property" do end end - it "when a property is declared with default: {}, a warning is issued" do - expect(Chef::Log).to receive(:deprecation).with( /^Property .+\.x has an array or hash default \(\{\}\)\. This means that if one resource modifies or appends to it, all other resources of the same type will also see the changes\. Either freeze the constant with \`\.freeze\` to prevent appending, or use lazy \{ \{\} \}\.$/, /property_spec\.rb/ ) - resource_class.class_eval("property :x, default: {}", __FILE__, __LINE__) - expect(resource.x).to eq({}) - end - with_property ':x, default: lazy { {} }' do it "when x is not set, it returns {}" do expect(resource.x).to eq({}) |