Skip to content

Commit

Permalink
Merge pull request #150 from ekohl/use-to_h
Browse files Browse the repository at this point in the history
Use Hash.to_h to construct a new hash
  • Loading branch information
ekohl authored Jul 6, 2023
2 parents 555fd29 + 59fb9bb commit ca28a6a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/rspec-puppet-facts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,9 @@ def on_supported_os_implementation(opts = {})
os_facts_hash
end

# @api private
def stringify_keys(hash)
Hash[hash.collect { |k,v| [k.to_s, v.is_a?(Hash) ? stringify_keys(v) : v] }]
hash.to_h { |k, v| [k.to_s, v.is_a?(Hash) ? stringify_keys(v) : v] }
end

# Register a custom fact that will be included in the facts hash.
Expand Down
4 changes: 4 additions & 0 deletions spec/rspec_puppet_facts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
'spec/fixtures/metadata.json'
end

describe '.stringify_keys' do
it { expect(described_class.stringify_keys({ os: { family: 'RedHat' } })).to eq({ 'os' => { 'family' => 'RedHat' } }) }
end

describe '.facter_version_for_puppet_version' do
subject(:facter_version) do
described_class.facter_version_for_puppet_version(puppet_version)
Expand Down

0 comments on commit ca28a6a

Please sign in to comment.