Skip to content

Commit

Permalink
Use Hash.to_h to construct a new hash
Browse files Browse the repository at this point in the history
Also declares stringify_keys as a private API method.
  • Loading branch information
ekohl committed Jul 6, 2023
1 parent 8d9370c commit 59fb9bb
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 59fb9bb

Please sign in to comment.