summaryrefslogtreecommitdiff
path: root/spec/unit/property_spec.rb
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2015-09-25 12:21:50 -0700
committerJohn Keiser <john@johnkeiser.com>2015-09-25 12:22:19 -0700
commitff54a6dd7ef781f242f1ab5b513f90a76902f5b8 (patch)
tree2ecd802b1c4fb535c6a5eb3d1808959baf6266fe /spec/unit/property_spec.rb
parentaf422456552b8a64cb3ea90167a0f80f401790cf (diff)
downloadchef-ff54a6dd7ef781f242f1ab5b513f90a76902f5b8.tar.gz
Don't treat name_property/attribute as defaults if they are false
Diffstat (limited to 'spec/unit/property_spec.rb')
-rw-r--r--spec/unit/property_spec.rb41
1 files changed, 41 insertions, 0 deletions
diff --git a/spec/unit/property_spec.rb b/spec/unit/property_spec.rb
index 6415286397..de8d493026 100644
--- a/spec/unit/property_spec.rb
+++ b/spec/unit/property_spec.rb
@@ -946,6 +946,19 @@ describe "Chef::Resource.property" do
expect(resource.x).to eq 'blah'
end
end
+
+ with_property ":x, #{name}: false" do
+ it "defaults to nil" do
+ expect(resource.x).to be_nil
+ end
+ end
+
+ with_property ":x, #{name}: nil" do
+ it "defaults to nil" do
+ expect(resource.x).to be_nil
+ end
+ 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,
@@ -964,6 +977,7 @@ describe "Chef::Resource.property" do
/Cannot specify keys #{name}, default together on property x. Only one \(#{name}\) will be obeyed./
end
end
+
context "default ordering" do
before { Chef::Config[:treat_deprecation_warnings_as_errors] = false }
with_property ":x, default: 10, #{name}: true" do
@@ -987,6 +1001,33 @@ describe "Chef::Resource.property" do
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
+
with_property ":x, #{name}: true, required: true" do
it "defaults x to resource.name" do
expect(resource.x).to eq 'blah'