summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@may.lt>2017-03-07 18:40:14 +0000
committerGitHub <noreply@github.com>2017-03-07 18:40:14 +0000
commita6365d07857c31ae7242bf60fffdb74617b1e4e8 (patch)
tree97b659f873be3686f44c0d246a8c3cbf104ea071
parent7e6d76482bce9384130170839118657d46d7e1e9 (diff)
parent5ddebc5768dd28f98dc3c646784ca91d3046eab3 (diff)
downloadchef-a6365d07857c31ae7242bf60fffdb74617b1e4e8.tar.gz
Merge pull request #5867 from chef/tm/demagic_properties_2
Be a bit less keen to help properties
-rw-r--r--lib/chef/property.rb13
-rw-r--r--spec/unit/property_spec.rb75
2 files changed, 14 insertions, 74 deletions
diff --git a/lib/chef/property.rb b/lib/chef/property.rb
index 8fa290251a..ac226bc815 100644
--- a/lib/chef/property.rb
+++ b/lib/chef/property.rb
@@ -106,17 +106,8 @@ class Chef
@options = options
end
- # Only pick the first of :default, :name_property and :name_attribute if
- # more than one is specified.
- if options.has_key?(:default) && options[:name_property]
- if options[:default].nil? || options.keys.index(:name_property) < options.keys.index(:default)
- options.delete(:default)
- preferred_default = :name_property
- else
- options.delete(:name_property)
- preferred_default = :default
- end
- Chef.deprecated(:custom_resource, "Cannot specify both default and name_property together on property #{self}. Only one (#{preferred_default}) will be obeyed. In Chef 13, this will become an error. Please remove one or the other from the property.")
+ if options.has_key?(:default) && options.has_key?(:name_property)
+ raise ArgumentError, "Cannot specify both default and name_property/name_attribute together on property #{self}"
end
# Validate the default early, so the user gets a good error message, and
diff --git a/spec/unit/property_spec.rb b/spec/unit/property_spec.rb
index 50ff3434f6..0e7bf53ec5 100644
--- a/spec/unit/property_spec.rb
+++ b/spec/unit/property_spec.rb
@@ -1019,74 +1019,23 @@ describe "Chef::Resource.property" do
end
context "default ordering deprecation warnings" do
- it "emits a deprecation warning for property :x, default: 10, #{name}: true" do
- expect { resource_class.property :x, :default => 10, name.to_sym => true }.to raise_error Chef::Exceptions::DeprecatedFeatureError,
- /Cannot specify both default and name_property together on property x of resource chef_resource_property_spec_(\d+). Only one \(default\) will be obeyed./
+ it "emits an error for property :x, default: 10, #{name}: true" do
+ expect { resource_class.property :x, :default => 10, name.to_sym => true }.to raise_error Chef::Exceptions::ArgumentError,
+ /Cannot specify both default and name_property\/name_attribute together on property x of resource chef_resource_property_spec_(\d+)/
end
- it "emits a deprecation warning for property :x, default: nil, #{name}: true" do
- expect { resource_class.property :x, :default => nil, name.to_sym => true }.to raise_error Chef::Exceptions::DeprecatedFeatureError,
- /Cannot specify both default and name_property together on property x of resource chef_resource_property_spec_(\d+). Only one \(name_property\) will be obeyed./
+ it "emits an error for property :x, default: nil, #{name}: true" do
+ expect { resource_class.property :x, :default => nil, name.to_sym => true }.to raise_error Chef::Exceptions::ArgumentError,
+ /Cannot specify both default and name_property\/name_attribute together on property x of resource chef_resource_property_spec_(\d+)/
end
- it "emits a deprecation warning for property :x, #{name}: true, default: 10" do
- expect { resource_class.property :x, name.to_sym => true, :default => 10 }.to raise_error Chef::Exceptions::DeprecatedFeatureError,
- /Cannot specify both default and name_property together on property x of resource chef_resource_property_spec_(\d+). Only one \(name_property\) will be obeyed./
+ it "emits an error for property :x, #{name}: true, default: 10" do
+ expect { resource_class.property :x, name.to_sym => true, :default => 10 }.to raise_error Chef::Exceptions::ArgumentError,
+ /Cannot specify both default and name_property\/name_attribute together on property x of resource chef_resource_property_spec_(\d+)/
end
- it "emits a deprecation warning for property :x, #{name}: true, default: nil" do
- expect { resource_class.property :x, name.to_sym => true, :default => nil }.to raise_error Chef::Exceptions::DeprecatedFeatureError,
- /Cannot specify both default and name_property together on property x of resource chef_resource_property_spec_(\d+). Only one \(name_property\) will be obeyed./
+ it "emits an error for property :x, #{name}: true, default: nil" do
+ expect { resource_class.property :x, name.to_sym => true, :default => nil }.to raise_error Chef::Exceptions::ArgumentError,
+ /Cannot specify both default and name_property\/name_attribute together on property x of resource chef_resource_property_spec_(\d+)/
end
end
-
- context "default ordering" do
- before { Chef::Config[:treat_deprecation_warnings_as_errors] = false }
- with_property ":x, default: 10, #{name}: true" do
- it "chooses default over #{name}" do
- expect(resource.x).to eq 10
- end
- end
- with_property ":x, default: nil, #{name}: true" do
- it "chooses #{name} over default" do
- expect(resource.x).to eq "blah"
- end
- end
- with_property ":x, #{name}: true, default: 10" do
- it "chooses #{name} over default" do
- expect(resource.x).to eq "blah"
- end
- end
- with_property ":x, #{name}: true, default: nil" do
- it "chooses #{name} over default" do
- expect(resource.x).to eq "blah"
- end
- end
- end
-
- context "default ordering when #{name} is nil" do
- with_property ":x, #{name}: nil, default: 10" do
- it "chooses default" do
- expect(resource.x).to eq 10
- end
- end
- with_property ":x, default: 10, #{name}: nil" do
- it "chooses default" do
- expect(resource.x).to eq 10
- end
- end
- end
-
- context "default ordering when #{name} is false" do
- with_property ":x, #{name}: false, default: 10" do
- it "chooses default" do
- expect(resource.x).to eq 10
- end
- end
- with_property ":x, default: 10, #{name}: nil" do
- it "chooses default" do
- expect(resource.x).to eq 10
- end
- end
- end
-
end
end