diff --git a/.rubocop.yml b/.rubocop.yml index 5c97ed62..131c57b2 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,10 +4,7 @@ inherit_from: .rubocop_todo.yml inherit_gem: voxpupuli-rubocop: rubocop.yml -Style: - Enabled: false - -Layout: +Layout/LineLength: Enabled: false # To match the gem name diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 2a3b54e7..3044e57f 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:09:14 UTC using RuboCop version 1.63.5. +# on 2024-06-09 17:48:43 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 @@ -52,7 +52,7 @@ RSpec/MessageSpies: RSpec/MultipleExpectations: Max: 2 -# Offense count: 49 +# Offense count: 40 # Configuration parameters: EnforcedStyle, IgnoreSharedExamples. # SupportedStyles: always, named_only RSpec/NamedSubject: @@ -74,3 +74,60 @@ RSpec/StubbedMock: Rake/Desc: Exclude: - 'Rakefile' + +# Offense count: 6 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: always, always_true, never +Style/FrozenStringLiteralComment: + Exclude: + - 'Gemfile' + - 'Rakefile' + - 'lib/rspec-puppet-facts.rb' + - 'lib/rspec-puppet-facts/version.rb' + - 'spec/rspec_puppet_facts_spec.rb' + - 'spec/spec_helper.rb' + +# Offense count: 1 +Style/MixinUsage: + Exclude: + - 'spec/spec_helper.rb' + +# Offense count: 3 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: literals, strict +Style/MutableConstant: + Exclude: + - 'lib/rspec-puppet-facts.rb' + - 'lib/rspec-puppet-facts/version.rb' + - 'spec/rspec_puppet_facts_spec.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: Methods. +Style/RedundantArgument: + Exclude: + - 'lib/rspec-puppet-facts.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +Style/RedundantSort: + Exclude: + - 'lib/rspec-puppet-facts.rb' + +# Offense count: 2 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods, MaxChainLength. +# AllowedMethods: present?, blank?, presence, try, try! +Style/SafeNavigation: + Exclude: + - 'lib/rspec-puppet-facts.rb' + +# Offense count: 2 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: RequireEnglish, EnforcedStyle. +# SupportedStyles: use_perl_names, use_english_names, use_builtin_english_names +Style/SpecialGlobalVars: + Exclude: + - 'lib/rspec-puppet-facts.rb' diff --git a/Gemfile b/Gemfile index 11a624c2..f494abb0 100644 --- a/Gemfile +++ b/Gemfile @@ -2,14 +2,14 @@ source ENV['GEM_SOURCE'] || 'https://rubygems.org' gemspec -gem 'facter', ENV['FACTER_GEM_VERSION'], :require => false +gem 'facter', ENV.fetch('FACTER_GEM_VERSION', nil), require: false group :release do gem 'faraday-retry', '~> 2.1', require: false gem 'github_changelog_generator', '~> 1.16.4', require: false end -group :coverage, optional: ENV['COVERAGE']!='yes' do - gem 'codecov', :require => false - gem 'simplecov-console', :require => false +group :coverage, optional: ENV['COVERAGE'] != 'yes' do + gem 'codecov', require: false + gem 'simplecov-console', require: false end diff --git a/Rakefile b/Rakefile index 25611ac3..7b037913 100644 --- a/Rakefile +++ b/Rakefile @@ -1,10 +1,10 @@ PUPPET_VERSIONS_PATH = File.join(__dir__, 'ext', 'puppet_agent_components.json') begin - require 'rspec/core/rake_task' - require 'yard' - RSpec::Core::RakeTask.new(:spec) - YARD::Rake::YardocTask.new + require 'rspec/core/rake_task' + require 'yard' + RSpec::Core::RakeTask.new(:spec) + YARD::Rake::YardocTask.new rescue LoadError # yard is optional end @@ -40,8 +40,8 @@ namespace :puppet_versions do output = `git status --porcelain #{PUPPET_VERSIONS_PATH}` unless output.strip.empty? - $stderr.puts "#{PUPPET_VERSIONS_PATH} is out of date." - $stderr.puts 'Run the puppet_versions:update task to update it and commit the changes.' + warn "#{PUPPET_VERSIONS_PATH} is out of date." + warn 'Run the puppet_versions:update task to update it and commit the changes.' raise end end @@ -54,7 +54,7 @@ rescue LoadError else require 'rubygems' GitHubChangelogGenerator::RakeTask.new :changelog do |config| - config.exclude_labels = %w{duplicate question invalid wontfix wont-fix skip-changelog github_actions} + config.exclude_labels = %w[duplicate question invalid wontfix wont-fix skip-changelog github_actions] config.user = 'voxpupuli' config.project = 'rspec-puppet-facts' gem_version = Gem::Specification.load("#{config.project}.gemspec").version diff --git a/lib/rspec-puppet-facts.rb b/lib/rspec-puppet-facts.rb index 6577fb63..f702148d 100644 --- a/lib/rspec-puppet-facts.rb +++ b/lib/rspec-puppet-facts.rb @@ -58,8 +58,7 @@ def on_supported_os(opts = {}) # @api private def on_supported_os_implementation(opts = {}) unless /\A\d+\.\d+(?:\.\d+)*\z/.match?((facterversion = opts[:facterversion])) - raise ArgumentError, ":facterversion must be in the format 'n.n' or " \ - "'n.n.n' (n is numeric), not '#{facterversion}'" + raise ArgumentError, ":facterversion must be in the format 'n.n' or 'n.n.n' (n is numeric), not '#{facterversion}'" end filter = [] @@ -67,7 +66,6 @@ def on_supported_os_implementation(opts = {}) if os_sup['operatingsystemrelease'] Array(os_sup['operatingsystemrelease']).map do |operatingsystemmajrelease| opts[:hardwaremodels].each do |hardwaremodel| - os_release_filter = "/^#{Regexp.escape(operatingsystemmajrelease.split(' ')[0])}/" case os_sup['operatingsystem'] when /BSD/i @@ -90,7 +88,7 @@ def on_supported_os_implementation(opts = {}) os_release_filter = "\"#{operatingsystemmajrelease}\"" when /Amazon/i # Tighten the regex for Amazon Linux 2 so that we don't pick up Amazon Linux 2016 or 2017 facts - os_release_filter = "/^2$/" if operatingsystemmajrelease == '2' + os_release_filter = '/^2$/' if operatingsystemmajrelease == '2' end filter << { @@ -110,16 +108,18 @@ def on_supported_os_implementation(opts = {}) end end - strict_requirement = RspecPuppetFacts::facter_version_to_strict_requirement(facterversion) + strict_requirement = RspecPuppetFacts.facter_version_to_strict_requirement(facterversion) - loose_requirement = RspecPuppetFacts::facter_version_to_loose_requirement(facterversion) + loose_requirement = RspecPuppetFacts.facter_version_to_loose_requirement(facterversion) received_facts = [] # FacterDB may have newer versions of facter data for which it contains a subset of all possible # 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, symbolize_keys: !RSpec.configuration.facterdb_string_keys).to_h { |facts| [Gem::Version.new(facts[:facterversion]), facts] } + versions = FacterDB.get_facts(filter_spec, symbolize_keys: !RSpec.configuration.facterdb_string_keys).to_h do |facts| + [Gem::Version.new(facts[:facterversion]), facts] + end version, facts = versions.select { |v, _f| strict_requirement =~ v }.max_by { |v, _f| v } @@ -127,9 +127,7 @@ def on_supported_os_implementation(opts = {}) version, facts = versions.select { |v, _f| loose_requirement =~ v }.max_by { |v, _f| v } if loose_requirement next unless version - if RspecPuppetFacts.spec_facts_strict? - raise ArgumentError, "No facts were found in the FacterDB for Facter v#{facterversion} on #{filter_spec}, aborting" - end + raise ArgumentError, "No facts were found in the FacterDB for Facter v#{facterversion} on #{filter_spec}, aborting" if RspecPuppetFacts.spec_facts_strict? RspecPuppetFacts.warning "No facts were found in the FacterDB for Facter v#{facterversion} on #{filter_spec}, using v#{version} instead" end @@ -152,6 +150,7 @@ def on_supported_os_implementation(opts = {}) os = "#{os_fact['name'].downcase}-#{os_fact['release']['major']}-#{os_fact['hardware']}" next if RspecPuppetFacts.spec_facts_os_filter && !os.start_with?(RspecPuppetFacts.spec_facts_os_filter) + facts.merge! RspecPuppetFacts.common_facts os_facts_hash[os] = RspecPuppetFacts.with_custom_facts(os, facts) end @@ -193,7 +192,7 @@ def add_custom_fact(name, value, options = {}) def self.register_custom_fact(name, value, options) @custom_facts ||= {} name = RSpec.configuration.facterdb_string_keys ? name.to_s : name.to_sym - @custom_facts[name] = {:options => options, :value => value} + @custom_facts[name] = { options: options, value: value } end # Adds any custom facts according to the rules defined for the operating @@ -212,7 +211,7 @@ def self.with_custom_facts(os, facts) value = fact[:value].respond_to?(:call) ? fact[:value].call(os, facts) : fact[:value] # if merge_facts passed, merge supplied facts into facts hash if fact[:options][:merge_facts] - facts.deep_merge!({name => value}) + facts.deep_merge!({ name => value }) else facts[name] = value end @@ -235,7 +234,7 @@ def self.custom_facts # @return [nil,String] # @api private def self.spec_facts_os_filter - ENV['SPEC_FACTS_OS'] + ENV.fetch('SPEC_FACTS_OS', nil) end # If SPEC_FACTS_STRICT is set to `yes`, RspecPuppetFacts will error on missing FacterDB entries, instead of warning & skipping the tests, or using an older facter version. @@ -251,17 +250,16 @@ def self.spec_facts_strict? # @return [Hash String>] def self.common_facts return @common_facts if @common_facts + @common_facts = { - :puppetversion => Puppet.version, - :rubysitedir => RbConfig::CONFIG['sitelibdir'], - :rubyversion => RUBY_VERSION, + puppetversion: Puppet.version, + rubysitedir: RbConfig::CONFIG['sitelibdir'], + rubyversion: RUBY_VERSION, } @common_facts[:mco_version] = MCollective::VERSION if mcollective? - if augeas? - @common_facts[:augeasversion] = Augeas.open(nil, nil, Augeas::NO_MODL_AUTOLOAD).get('/augeas/version') - end + @common_facts[:augeasversion] = Augeas.open(nil, nil, Augeas::NO_MODL_AUTOLOAD).get('/augeas/version') if augeas? @common_facts = stringify_keys(@common_facts) if RSpec.configuration.facterdb_string_keys @common_facts @@ -298,9 +296,8 @@ def self.mcollective? # @return [Array] # @api private def self.meta_supported_os - unless metadata['operatingsystem_support'].is_a? Array - fail StandardError, 'Unknown operatingsystem support in the metadata file!' - end + raise StandardError, 'Unknown operatingsystem support in the metadata file!' unless metadata['operatingsystem_support'].is_a? Array + metadata['operatingsystem_support'] end @@ -311,9 +308,8 @@ def self.meta_supported_os # @api private def self.metadata return @metadata if @metadata - unless File.file? metadata_file - fail StandardError, "Can't find metadata.json... dunno why" - end + raise StandardError, "Can't find metadata.json... dunno why" unless File.file? metadata_file + content = File.read metadata_file @metadata = JSON.parse content end @@ -329,7 +325,7 @@ def self.metadata_file # @param message [String] # @api private def self.warning(message) - STDERR.puts message + warn message end # Reset the memoization @@ -379,9 +375,6 @@ def self.facter_version_to_loose_requirement_string(version) elsif /\A[0-9]+\Z/.match?(version) # Interpret 3 as < 4 "< #{version.to_i + 1}" - else - # This would be the same as the strict requirement - nil end end @@ -397,13 +390,13 @@ def self.facter_version_for_puppet_version(puppet_version) fd = File.open(json_path, 'rb:UTF-8') data = JSON.parse(fd.read) - version_map = data.map { |_, versions| + version_map = data.map do |_, versions| if versions['puppet'].nil? || versions['facter'].nil? nil else [Gem::Version.new(versions['puppet']), versions['facter']] end - }.compact + end.compact puppet_gem_version = Gem::Version.new(puppet_version) applicable_versions = version_map.select { |p, _| puppet_gem_version >= p } @@ -422,8 +415,6 @@ def self.facter_version_for_puppet_version(puppet_version) end 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 + c.add_setting :default_facter_version, 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 bf10188d..f982ea7a 100644 --- a/spec/rspec_puppet_facts_spec.rb +++ b/spec/rspec_puppet_facts_spec.rb @@ -8,7 +8,9 @@ end describe '.stringify_keys' do - it { expect(described_class.stringify_keys({ os: { family: 'RedHat' } })).to eq({ 'os' => { 'family' => 'RedHat' } }) } + it { + expect(described_class.stringify_keys({ os: { family: 'RedHat' } })).to eq({ 'os' => { 'family' => 'RedHat' } }) + } end describe '.facter_version_for_puppet_version' do @@ -137,10 +139,10 @@ subject(:result) do on_supported_os( { - :supported_os => [ + supported_os: [ { - "operatingsystem" => "Debian", - "operatingsystemrelease" => ['12'], + 'operatingsystem' => 'Debian', + 'operatingsystemrelease' => ['12'], }, ], }, @@ -148,7 +150,7 @@ end let(:get_keys) do - proc { |r| r.keys + r.select { |_,v| v.is_a?(Hash) }.map { |_,v| get_keys.call(v) }.flatten } + proc { |r| r.keys + r.select { |_, v| v.is_a?(Hash) }.map { |_, v| get_keys.call(v) }.flatten } end context 'set to true' do @@ -245,40 +247,39 @@ context 'With a wrong operatingsystem_support section' do let(:metadata) do { - 'operatingsystem_support' => 'Ubuntu', + 'operatingsystem_support' => 'Ubuntu', } end it { expect { subject }.to raise_error(StandardError, /Unknown operatingsystem support/) } end end - end end context 'When specifying supported_os' do - subject { + subject do on_supported_os( { - :supported_os => [ + supported_os: [ { - "operatingsystem" => "Debian", - "operatingsystemrelease" => [ - "11", - "12", + 'operatingsystem' => 'Debian', + 'operatingsystemrelease' => %w[ + 11 + 12 ], }, { - "operatingsystem" => "RedHat", - "operatingsystemrelease" => [ - "8", - "9", + 'operatingsystem' => 'RedHat', + 'operatingsystemrelease' => %w[ + 8 + 9 ], }, ], }, ) - } + end it 'returns a hash' do is_expected.to be_a Hash @@ -306,7 +307,7 @@ subject(:factsets) do on_supported_os( { - :supported_os => [ + supported_os: [ { 'operatingsystem' => 'RedHat', 'operatingsystemrelease' => '9' }, ], }, @@ -318,27 +319,27 @@ end it 'returns a fact set for the specified release' do - expect(factsets).to match('redhat-9-x86_64' => include(:operatingsystemmajrelease => '9')) + expect(factsets).to match('redhat-9-x86_64' => include(operatingsystemmajrelease: '9')) end end context 'When testing Ubuntu' do - subject { + subject do on_supported_os( { - :supported_os => [ + supported_os: [ { - "operatingsystem" => "Ubuntu", - "operatingsystemrelease" => [ - "18.04", - "20.04", - "22.04", + 'operatingsystem' => 'Ubuntu', + 'operatingsystemrelease' => [ + '18.04', + '20.04', + '22.04', ], }, ], }, ) - } + end it 'returns a hash' do expect(subject).to be_a Hash @@ -354,21 +355,21 @@ end context 'When testing FreeBSD 10' do - subject { + subject do on_supported_os( { - :supported_os => [ + supported_os: [ { - "operatingsystem" => "FreeBSD", - "operatingsystemrelease" => [ - "13", + 'operatingsystem' => 'FreeBSD', + 'operatingsystemrelease' => [ + '13', ], }, ], - :facterversion => '4.5', + facterversion: '4.5', }, ) - } + end it 'returns a hash' do expect(subject).to be_a Hash @@ -382,21 +383,21 @@ end context 'When testing OpenBSD' do - subject { + subject do on_supported_os( { - :supported_os => [ + supported_os: [ { - "operatingsystem" => "OpenBSD", - "operatingsystemrelease" => [ - "7.5", + 'operatingsystem' => 'OpenBSD', + 'operatingsystemrelease' => [ + '7.5', ], }, ], - :facterversion => '4.7', + facterversion: '4.7', }, ) - } + end it 'returns a hash' do expect(subject).to be_a Hash @@ -410,21 +411,21 @@ end context 'When testing Solaris 11' do - subject { + subject do on_supported_os( { - :supported_os => [ + supported_os: [ { - "operatingsystem" => "Solaris", - "operatingsystemrelease" => [ - "11", + 'operatingsystem' => 'Solaris', + 'operatingsystemrelease' => [ + '11', ], }, ], facterversion: '4.0', }, ) - } + end it 'returns a hash' do expect(subject).to be_a Hash @@ -439,21 +440,21 @@ end context 'When testing AIX 7.1' do - subject { + subject do on_supported_os( - { - :supported_os => [ - { - "operatingsystem" => "AIX", - "operatingsystemrelease" => [ - "7.1", "7100", - ], - }, + { + supported_os: [ + { + 'operatingsystem' => 'AIX', + 'operatingsystemrelease' => [ + '7.1', '7100', ], - :facterversion => '3.9', - }, + }, + ], + facterversion: '3.9', + }, ) - } + end it 'returns a hash' do expect(subject).to be_a Hash @@ -473,13 +474,13 @@ subject do on_supported_os( { - :supported_os => [ + supported_os: [ { - 'operatingsystem' => 'Windows', + 'operatingsystem' => 'Windows', 'operatingsystemrelease' => release, }, ], - :facterversion => facterversion, + facterversion: facterversion, }, ) end @@ -516,20 +517,20 @@ end context 'When operatingsystemrelease has space' do - subject { + subject do on_supported_os( { - :supported_os => [ + supported_os: [ { - "operatingsystem" => "SLES", - "operatingsystemrelease" => [ - "11 SP1", + 'operatingsystem' => 'SLES', + 'operatingsystemrelease' => [ + '11 SP1', ], }, ], }, ) - } + end it 'returns a hash' do expect(subject).to be_a Hash @@ -542,20 +543,20 @@ end context 'When specifying wrong supported_os' do - subject { + subject do on_supported_os( { - :supported_os => [ + supported_os: [ { - "operatingsystem" => "Debian", - "operatingsystemrelease" => [ - "4", + 'operatingsystem' => 'Debian', + 'operatingsystemrelease' => [ + '4', ], }, ], }, ) - } + end it 'outputs warning message' do expect(described_class).to receive(:warning).with(/No facts were found in the FacterDB/) @@ -564,31 +565,31 @@ end context 'When specifying rolling release operating system' do - subject { + subject do on_supported_os( { - :supported_os => [ + supported_os: [ { - "operatingsystem" => "Debian", - "operatingsystemrelease" => [ - "12", + 'operatingsystem' => 'Debian', + 'operatingsystemrelease' => [ + '12', ], }, { - "operatingsystem" => "Gentoo", + 'operatingsystem' => 'Gentoo', }, ], facterversion: '4.6', }, ) - } + end it 'returns a hash' do expect(subject).to be_a Hash end it 'returns supported OS' do - expect(subject.keys).to contain_exactly(a_string_matching(/\gentoo-\d+-x86_64/), 'debian-12-x86_64') + expect(subject.keys).to contain_exactly(a_string_matching(/gentoo-\d+-x86_64/), 'debian-12-x86_64') end end @@ -596,9 +597,9 @@ subject do on_supported_os( { - :supported_os => [ + supported_os: [ { - 'operatingsystem' => 'IOS', + 'operatingsystem' => 'IOS', 'operatingsystemrelease' => ['12.2(25)EWA9'], }, ], @@ -612,9 +613,9 @@ it 'escapes the parens in the filter' do filter = { - 'os.name' => "IOS", - 'os.release.full' => "/^12\\.2\\(25\\)EWA9/", - 'os.hardware' => "x86_64", + 'os.name' => 'IOS', + 'os.release.full' => '/^12\\.2\\(25\\)EWA9/', + 'os.hardware' => 'x86_64', } expect(FacterDB).to receive(:get_facts).with(filter, symbolize_keys: true).once @@ -643,11 +644,10 @@ RSpec.configuration.default_facter_version = Facter.version end - it 'returns facts from the specified default Facter version' do is_expected.to match( 'centos-9-x86_64' => include( - :facterversion => /\A4\.6\./, + facterversion: /\A4\.6\./, ), ) end @@ -659,7 +659,7 @@ supported_os: [ { 'operatingsystem' => 'CentOS', 'operatingsystemrelease' => %w[9] }, ], - facterversion: "4.7.99", + facterversion: '4.7.99', ) end @@ -667,11 +667,10 @@ allow(Facter).to receive(:version).and_return('4.6') end - 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]\./, + facterversion: /\A4\.[0-7]\./, ), ) end @@ -698,7 +697,7 @@ end it 'returns facts from a facter version matching 4.6' do - is_expected.to match('centos-9-x86_64' => include(:facterversion => '4.6.1')) + is_expected.to match('centos-9-x86_64' => include(facterversion: '4.6.1')) end end @@ -713,7 +712,7 @@ end it 'returns facts from a facter version matching 4.6.1' do - is_expected.to match('centos-9-x86_64' => include(:facterversion => '4.6.1')) + is_expected.to match('centos-9-x86_64' => include(facterversion: '4.6.1')) end end @@ -747,7 +746,7 @@ 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"}, symbolize_keys: true, + { '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 @@ -758,27 +757,27 @@ 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 describe '#add_custom_fact' do - subject { + subject do on_supported_os( { - :supported_os => [ + supported_os: [ { - "operatingsystem" => "RedHat", - "operatingsystemrelease" => [ - "8", - "9", + 'operatingsystem' => 'RedHat', + 'operatingsystemrelease' => %w[ + 8 + 9 ], }, ], }, ) - } + end before do described_class.reset @@ -792,31 +791,33 @@ it 'merges a fact value into fact when merge_facts passed' do add_custom_fact :identity, { 'user' => 'test_user' }, merge_facts: true expect(subject['redhat-9-x86_64'][:identity]).to eq( - { - "gid"=>0, - "group"=>"root", - "privileged"=>true, - "uid"=>0, - "user"=>"test_user" - }) + { + 'gid' => 0, + 'group' => 'root', + 'privileged' => true, + 'uid' => 0, + 'user' => 'test_user', + }, + ) end it 'overwrites fact' do add_custom_fact :identity, { 'user' => 'other_user' } expect(subject['redhat-9-x86_64'][:identity]).to eq( - { - "user"=>"other_user" - }) + { + 'user' => 'other_user', + }, + ) end it 'confines a fact to a particular operating system' do - add_custom_fact 'root_home', '/root', :confine => 'redhat-9-x86_64' + add_custom_fact 'root_home', '/root', confine: 'redhat-9-x86_64' expect(subject['redhat-9-x86_64'][:root_home]).to eq '/root' expect(subject['redhat-8-x86_64'][:root_home]).to be_nil end it 'excludes a fact from a particular operating system' do - add_custom_fact 'root_home', '/root', :exclude => 'redhat-9-x86_64' + add_custom_fact 'root_home', '/root', exclude: 'redhat-9-x86_64' expect(subject['redhat-9-x86_64'][:root_home]).to be_nil expect(subject['redhat-8-x86_64'][:root_home]).to eq '/root' end @@ -851,6 +852,7 @@ module AugeasStub # rubocop:todo Lint/ConstantDefinitionInBlock def self.open(*_args) self end + def self.get(*_args) 'my_version' end @@ -874,7 +876,7 @@ module MCollectiveStub # rubocop:todo Lint/ConstantDefinitionInBlock end it 'includes an "mco_version" fact' do - expect(subject.common_facts).to include(:mco_version => 'my_version') + expect(subject.common_facts).to include(mco_version: 'my_version') end end