From 5868eb52e7e460fd104559dceefefde12ebc439f Mon Sep 17 00:00:00 2001 From: James Stocks Date: Wed, 30 Jan 2019 17:12:56 +0000 Subject: [PATCH] Fix Inspec::Attribute.to_ruby and add unit test Signed-off-by: James Stocks --- lib/inspec/objects/attribute.rb | 2 +- test/unit/attributes/attribute_test.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/inspec/objects/attribute.rb b/lib/inspec/objects/attribute.rb index d3d980fbf..9f6580139 100644 --- a/lib/inspec/objects/attribute.rb +++ b/lib/inspec/objects/attribute.rb @@ -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") diff --git a/test/unit/attributes/attribute_test.rb b/test/unit/attributes/attribute_test.rb index 197ee593f..c2bf73f92 100644 --- a/test/unit/attributes/attribute_test.rb +++ b/test/unit/attributes/attribute_test.rb @@ -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