Fix Inspec::Attribute.to_ruby and add unit test

Signed-off-by: James Stocks <jstocks@chef.io>
This commit is contained in:
James Stocks 2019-01-30 17:12:56 +00:00
parent 0fcbf0b155
commit 5868eb52e7
2 changed files with 13 additions and 1 deletions

View file

@ -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")

View file

@ -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