mirror of
https://github.com/inspec/inspec
synced 2025-02-17 06:28:40 +00:00
Replace to_hsh method, and add unit test for it
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
This commit is contained in:
parent
f4c979cabd
commit
51812a9e4e
2 changed files with 37 additions and 0 deletions
|
@ -318,6 +318,21 @@ module Inspec
|
|||
!current_value.is_a? NO_VALUE_SET
|
||||
end
|
||||
|
||||
#--------------------------------------------------------------------------#
|
||||
# Marshalling
|
||||
#--------------------------------------------------------------------------#
|
||||
|
||||
def to_hash
|
||||
as_hash = { name: name, options: {} }
|
||||
%i{description title identifier type required value}.each do |field|
|
||||
val = send(field)
|
||||
next if val.nil?
|
||||
|
||||
as_hash[:options][field] = val
|
||||
end
|
||||
as_hash
|
||||
end
|
||||
|
||||
#--------------------------------------------------------------------------#
|
||||
# Value Type Coercion
|
||||
#--------------------------------------------------------------------------#
|
||||
|
|
|
@ -25,6 +25,28 @@ describe Inspec::Input do
|
|||
end
|
||||
end
|
||||
|
||||
describe "marshalling" do
|
||||
it "should be able to represent an Input as a Hash" do
|
||||
input = Inspec::Input.new("test_input",
|
||||
value: 12,
|
||||
title: "Best input ever",
|
||||
description: "important",
|
||||
type: "Numeric",
|
||||
required: true
|
||||
)
|
||||
_(input.to_hash).must_equal({
|
||||
name: "test_input",
|
||||
options: {
|
||||
value: 12,
|
||||
title: "Best input ever",
|
||||
description: "important",
|
||||
type: "Numeric",
|
||||
required: true
|
||||
}
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
#==============================================================#
|
||||
# Setting Value - One Shot
|
||||
# (see events_test.rb for overwrite support)
|
||||
|
|
Loading…
Add table
Reference in a new issue