mirror of
https://github.com/inspec/inspec
synced 2024-11-22 20:53:11 +00:00
Fix Inspec::Attribute.to_ruby and add unit test
Signed-off-by: James Stocks <jstocks@chef.io>
This commit is contained in:
parent
0fcbf0b155
commit
5868eb52e7
2 changed files with 13 additions and 1 deletions
|
@ -93,7 +93,7 @@ module Inspec
|
|||
def to_ruby
|
||||
res = ["#{ruby_var_identifier} = attribute('#{@name}',{"]
|
||||
res.push " title: '#{title}'," unless title.to_s.empty?
|
||||
res.push " default: #{default.inspect}," unless default.to_s.empty?
|
||||
res.push " value: #{value.inspect}," unless value.to_s.empty?
|
||||
res.push " description: '#{description}'," unless description.to_s.empty?
|
||||
res.push '})'
|
||||
res.join("\n")
|
||||
|
|
|
@ -225,4 +225,16 @@ describe Inspec::Attribute do
|
|||
attribute.send(:valid_numeric?, '1/2').must_equal false
|
||||
end
|
||||
end
|
||||
|
||||
describe 'to_ruby method' do
|
||||
it 'generates the code for the attribute' do
|
||||
attribute = Inspec::Attribute.new('application_port', description: 'The port my application uses', value: 80)
|
||||
attribute.to_ruby.must_equal <<-RUBY.chomp
|
||||
attr_application_port = attribute('application_port',{
|
||||
value: 80,
|
||||
description: 'The port my application uses',
|
||||
})
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue