diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2016-04-14 11:30:40 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2016-04-14 11:30:40 -0700 |
commit | 03503d7352ccad45107b055fc711e86c7c5d2918 (patch) | |
tree | 22b44530ad934d4846167021b2485abf45fb8110 /spec/unit/property/validation_spec.rb | |
parent | 95c13caaf4c8a20ba6d1f49680cd23de60cdb231 (diff) | |
download | chef-03503d7352ccad45107b055fc711e86c7c5d2918.tar.gz |
add nillable apt_repository and nillable properties
in Chef-13 nillable will become 'true' by default and we'll have
to deprecate and remove all nillable properties, but for now
this lets us opt-in, which was can't currently do in Chef-12.
Diffstat (limited to 'spec/unit/property/validation_spec.rb')
-rw-r--r-- | spec/unit/property/validation_spec.rb | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/spec/unit/property/validation_spec.rb b/spec/unit/property/validation_spec.rb index db3c9fe4f6..4e1b252863 100644 --- a/spec/unit/property/validation_spec.rb +++ b/spec/unit/property/validation_spec.rb @@ -99,13 +99,15 @@ describe "Chef::Resource.property validation" do expect(resource.x nil).to be_nil expect(resource.x).to be_nil end - it "changing x to nil warns that the get will change to a set in Chef 13 and does not change the value" do - resource.instance_eval { @x = "default" } - expect { resource.x nil }.to raise_error Chef::Exceptions::DeprecatedFeatureError, - /An attempt was made to change x from "default" to nil by calling x\(nil\). In Chef 12, this does a get rather than a set. In Chef 13, this will change to set the value to nil./ - Chef::Config[:treat_deprecation_warnings_as_errors] = false - expect(resource.x nil).to eq "default" - expect(resource.x).to eq "default" + unless tags.include?(:nillable) + it "changing x to nil warns that the get will change to a set in Chef 13 and does not change the value" do + resource.instance_eval { @x = "default" } + expect { resource.x nil }.to raise_error Chef::Exceptions::DeprecatedFeatureError, + /An attempt was made to change x from "default" to nil by calling x\(nil\). In Chef 12, this does a get rather than a set. In Chef 13, this will change to set the value to nil./ + Chef::Config[:treat_deprecation_warnings_as_errors] = false + expect(resource.x nil).to eq "default" + expect(resource.x).to eq "default" + end end end if tags.include?(:nil_is_valid) @@ -123,6 +125,15 @@ describe "Chef::Resource.property validation" do expect(resource.x).to eq "default" end end + elsif tags.include?(:nillable) + with_property ":x, #{validation}, nillable: true" do + it "changing x to nil with nillable true overwrites defaults and just works" do + resource.instance_eval { @x = "default" } + expect { resource.x nil }.not_to raise_error + expect(resource.x nil).to eq nil + expect(resource.x).to eq nil + end + end else it "property :x, #{validation}, default: nil warns that the default is invalid" do expect { resource_class.class_eval("property :x, #{validation}, default: nil", __FILE__, __LINE__) }.to raise_error Chef::Exceptions::DeprecatedFeatureError, @@ -268,6 +279,11 @@ describe "Chef::Resource.property validation" do validation_test "[]", [], [ :a ] + + validation_test "[ String, nil ], nillable: true", + [ nil, "thing" ], + [ :nope, false ], + :nillable end # is |