mirror of
https://github.com/inspec/inspec
synced 2024-11-23 05:03:07 +00:00
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:
parent
6c82d3c56f
commit
2f506b3c70
2 changed files with 12 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue