bugfix: default attributes for nil and false (#2410)

Traditionally those would translated DEFAULT_ATTRIBUTE. but that was wrong, it should have been nil or false or whatever the user supplied.

Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
This commit is contained in:
Dominik Richter 2017-12-21 14:20:59 +01:00 committed by Christoph Hartmann
parent 6c82d3c56f
commit 2f506b3c70
2 changed files with 12 additions and 3 deletions

View file

@ -27,7 +27,7 @@ module Inspec
end
def default
@opts[:default] || DEFAULT_ATTRIBUTE.new
@opts.key?(:default) ? @opts[:default] : DEFAULT_ATTRIBUTE.new
end
def title

View file

@ -29,10 +29,19 @@ describe Inspec::Attribute do
end
describe 'attribute with a default value set' do
let(:attribute) { Inspec::Attribute.new('test_attribute', default: 'default_value') }
it 'returns the user-configured default value if no value is assigned' do
attribute = Inspec::Attribute.new('test_attribute', default: 'default_value')
attribute.value.must_equal 'default_value'
end
it 'returns the user-configured default value if no value is assigned (nil)' do
attribute = Inspec::Attribute.new('test_attribute', default: nil)
attribute.value.must_equal nil
end
it 'returns the user-configured default value if no value is assigned (false)' do
attribute = Inspec::Attribute.new('test_attribute', default: false)
attribute.value.must_equal false
end
end
end