diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 077696b..2a3b54e 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2024-06-09 13:06:43 UTC using RuboCop version 1.63.5. +# on 2024-06-09 13:09:14 UTC using RuboCop version 1.63.5. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new diff --git a/lib/rspec-puppet-facts.rb b/lib/rspec-puppet-facts.rb index de1ec93..6577fb6 100644 --- a/lib/rspec-puppet-facts.rb +++ b/lib/rspec-puppet-facts.rb @@ -119,7 +119,7 @@ def on_supported_os_implementation(opts = {}) # facter data (see FacterDB 0.5.2 for Facter releases 3.8 and 3.9). In this situation we need to # cycle through and downgrade Facter versions per platform type until we find matching Facter data. filter.each do |filter_spec| - versions = FacterDB.get_facts(filter_spec).to_h { |facts| [Gem::Version.new(facts[:facterversion]), facts] } + versions = FacterDB.get_facts(filter_spec, symbolize_keys: !RSpec.configuration.facterdb_string_keys).to_h { |facts| [Gem::Version.new(facts[:facterversion]), facts] } version, facts = versions.select { |v, _f| strict_requirement =~ v }.max_by { |v, _f| v } @@ -144,7 +144,7 @@ def on_supported_os_implementation(opts = {}) os_facts_hash = {} received_facts.map do |facts| - os_fact = facts[:os] + os_fact = RSpec.configuration.facterdb_string_keys ? facts['os'] : facts[:os] unless os_fact RspecPuppetFacts.warning "No os fact was found in FacterDB for: #{facts}" next @@ -156,8 +156,6 @@ def on_supported_os_implementation(opts = {}) os_facts_hash[os] = RspecPuppetFacts.with_custom_facts(os, facts) end - return stringify_keys(os_facts_hash) if RSpec.configuration.facterdb_string_keys - os_facts_hash end @@ -264,6 +262,7 @@ def self.common_facts if augeas? @common_facts[:augeasversion] = Augeas.open(nil, nil, Augeas::NO_MODL_AUTOLOAD).get('/augeas/version') end + @common_facts = stringify_keys(@common_facts) if RSpec.configuration.facterdb_string_keys @common_facts end @@ -424,6 +423,7 @@ def self.facter_version_for_puppet_version(puppet_version) RSpec.configure do |c| c.add_setting :default_facter_version, - :default => RspecPuppetFacts.facter_version_for_puppet_version(Puppet.version) - c.add_setting :facterdb_string_keys, :default => false + default: RspecPuppetFacts.facter_version_for_puppet_version(Puppet.version) + c.add_setting :facterdb_string_keys, + default: false end diff --git a/spec/rspec_puppet_facts_spec.rb b/spec/rspec_puppet_facts_spec.rb index 3984f1d..c40a349 100644 --- a/spec/rspec_puppet_facts_spec.rb +++ b/spec/rspec_puppet_facts_spec.rb @@ -662,7 +662,7 @@ 'os.hardware' => "x86_64", } - expect(FacterDB).to receive(:get_facts).with(filter).once + expect(FacterDB).to receive(:get_facts).with(filter, symbolize_keys: true).once subject end @@ -715,7 +715,9 @@ it 'returns facts from a facter version matching version and below' do is_expected.to match( - 'centos-9-x86_64' => include(:facterversion => /\A4\.[0-7]\./,), + 'centos-9-x86_64' => include( + :facterversion => /\A4\.[0-7]\./, + ), ) end @@ -790,18 +792,18 @@ before do allow(FacterDB).to receive(:get_facts).and_call_original allow(FacterDB).to receive(:get_facts).with( - {'os.name'=>"CentOS", 'os.release.full'=>"/^9/", 'os.hardware'=>"x86_64"}, + {'os.name'=>"CentOS", 'os.release.full'=>"/^9/", 'os.hardware'=>"x86_64"}, symbolize_keys: true, ).and_wrap_original do |m, *args| m.call(*args).reject { |facts| facts[:facterversion].start_with?('4.6.') } end end it 'returns CentOS facts from a facter version matching 4.5' do - is_expected.to include('centos-9-x86_64' => include(:facterversion => '4.5.2')) + is_expected.to include('centos-9-x86_64' => include(facterversion: '4.5.2')) end it 'returns Debian facts from a facter version matching 4.6.1' do - is_expected.to include('debian-12-x86_64' => include(:facterversion => '4.6.1'),) + is_expected.to include('debian-12-x86_64' => include(facterversion: '4.6.1'),) end end end @@ -815,7 +817,7 @@ "operatingsystem" => "RedHat", "operatingsystemrelease" => [ "8", - "9" + "9", ], }, ],