From 59fb9bbe740985ddd244fcf6077d4b5abea4dc94 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Wed, 5 Jul 2023 11:39:22 +0200 Subject: [PATCH] Use Hash.to_h to construct a new hash Also declares stringify_keys as a private API method. --- lib/rspec-puppet-facts.rb | 3 ++- spec/rspec_puppet_facts_spec.rb | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/rspec-puppet-facts.rb b/lib/rspec-puppet-facts.rb index 2a37e1e1..99e11332 100644 --- a/lib/rspec-puppet-facts.rb +++ b/lib/rspec-puppet-facts.rb @@ -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. diff --git a/spec/rspec_puppet_facts_spec.rb b/spec/rspec_puppet_facts_spec.rb index 5a29a752..b5a12a49 100644 --- a/spec/rspec_puppet_facts_spec.rb +++ b/spec/rspec_puppet_facts_spec.rb @@ -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)