diff options
-rw-r--r-- | lib/chef/mixin/params_validate.rb | 1 | ||||
-rw-r--r-- | spec/unit/property/validation_spec.rb | 3 |
2 files changed, 4 insertions, 0 deletions
diff --git a/lib/chef/mixin/params_validate.rb b/lib/chef/mixin/params_validate.rb index 9cd70eede7..142c582cdd 100644 --- a/lib/chef/mixin/params_validate.rb +++ b/lib/chef/mixin/params_validate.rb @@ -252,6 +252,7 @@ class Chef # Compare the way "case" would (i.e. `===`) def _pv_is(opts, key, to_be, raise_error: true) + return true if !opts.has_key?(key.to_s) && !opts.has_key?(key.to_sym) value = _pv_opts_lookup(opts, key) to_be = [ to_be ].flatten(1) to_be.each do |tb| diff --git a/spec/unit/property/validation_spec.rb b/spec/unit/property/validation_spec.rb index d37d23b437..14be7dc271 100644 --- a/spec/unit/property/validation_spec.rb +++ b/spec/unit/property/validation_spec.rb @@ -74,6 +74,9 @@ describe "Chef::Resource.property validation" do def self.validation_test(validation, success_values, failure_values, getter_values=[], *tags) with_property ":x, #{validation}", *tags do + it "gets nil when retrieving the initial (non-set) value" do + expect(resource.x).to be_nil + end success_values.each do |v| it "value #{v.inspect} is valid" do resource.instance_eval { @x = 'default' } |