Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Hash.to_h to construct a new hash #150

Merged
merged 1 commit into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you know if that's used somewhere? should we mark it as breaking change? (I want to drop old rubies anyways)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should only be internal. And marking it with a comment doesn't mean it can't be called anymore, it's only a signal people consuming the API.

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