From 3d5e23644f0fc557464409d98415872b2e7ba81d Mon Sep 17 00:00:00 2001 From: david22swan Date: Wed, 26 Apr 2023 15:37:01 +0100 Subject: [PATCH] (CONT-773) Rubocop Unsafe Auto Fixes 1-3 - Lint/BooleanSymbol - RSpec/BeEq - Style/CaseLikeIf --- .rubocop_todo.yml | 20 -------------------- lib/puppet/provider/apt_key/apt_key.rb | 7 ++++--- spec/unit/facter/apt_reboot_required_spec.rb | 4 ++-- spec/unit/puppet/type/apt_key_spec.rb | 10 +++++----- 4 files changed, 11 insertions(+), 30 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index bed1ce7..a20672e 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,12 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 1 -# This cop supports unsafe autocorrection (--autocorrect-all). -Lint/BooleanSymbol: - Exclude: - - 'spec/unit/puppet/type/apt_key_spec.rb' - # Offense count: 3 # Configuration parameters: AllowedMethods. # AllowedMethods: enums @@ -53,13 +47,6 @@ Performance/CollectionLiteralInLoop: Exclude: - 'spec/classes/apt_update_spec.rb' -# Offense count: 6 -# This cop supports unsafe autocorrection (--autocorrect-all). -RSpec/BeEq: - Exclude: - - 'spec/unit/facter/apt_reboot_required_spec.rb' - - 'spec/unit/puppet/type/apt_key_spec.rb' - # Offense count: 6 # Configuration parameters: Prefixes, AllowedPatterns. # Prefixes: when, with, without @@ -141,13 +128,6 @@ Security/Open: Exclude: - 'lib/puppet/provider/apt_key/apt_key.rb' -# Offense count: 1 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: MinBranchesCount. -Style/CaseLikeIf: - Exclude: - - 'lib/puppet/provider/apt_key/apt_key.rb' - # Offense count: 1 # This cop supports unsafe autocorrection (--autocorrect-all). Style/GlobalStdStream: diff --git a/lib/puppet/provider/apt_key/apt_key.rb b/lib/puppet/provider/apt_key/apt_key.rb index 8cdf78b..9ad21bc 100644 --- a/lib/puppet/provider/apt_key/apt_key.rb +++ b/lib/puppet/provider/apt_key/apt_key.rb @@ -71,13 +71,14 @@ Puppet::Type.type(:apt_key).provide(:apt_key) do def self.prefetch(resources) apt_keys = instances resources.each_key do |name| - if name.length == 40 + case name.length + when 40 provider = apt_keys.find { |key| key.fingerprint == name } resources[name].provider = provider if provider - elsif name.length == 16 + when 16 provider = apt_keys.find { |key| key.long == name } resources[name].provider = provider if provider - elsif name.length == 8 + when 8 provider = apt_keys.find { |key| key.short == name } resources[name].provider = provider if provider end diff --git a/spec/unit/facter/apt_reboot_required_spec.rb b/spec/unit/facter/apt_reboot_required_spec.rb index f922822..b607245 100644 --- a/spec/unit/facter/apt_reboot_required_spec.rb +++ b/spec/unit/facter/apt_reboot_required_spec.rb @@ -14,7 +14,7 @@ describe 'apt_reboot_required fact' do allow(File).to receive(:file?).once.with('/var/run/reboot-required').and_return(true) end - it { is_expected.to eq true } + it { is_expected.to be true } end describe 'if a reboot is not required' do @@ -24,6 +24,6 @@ describe 'apt_reboot_required fact' do allow(File).to receive(:file?).once.with('/var/run/reboot-required').and_return(false) end - it { is_expected.to eq false } + it { is_expected.to be false } end end diff --git a/spec/unit/puppet/type/apt_key_spec.rb b/spec/unit/puppet/type/apt_key_spec.rb index a23aa90..a146a26 100644 --- a/spec/unit/puppet/type/apt_key_spec.rb +++ b/spec/unit/puppet/type/apt_key_spec.rb @@ -24,19 +24,19 @@ describe Puppet::Type.type(:apt_key) do end it 'source is not set' do - expect(resource[:source]).to eq nil + expect(resource[:source]).to be_nil end it 'content is not set' do - expect(resource[:content]).to eq nil + expect(resource[:content]).to be_nil end it 'refresh is not set' do - expect(resource[:refresh]).to eq nil + expect(resource[:refresh]).to be_nil end it 'weak_ssl is not set' do - expect(resource[:weak_ssl]).to eq nil + expect(resource[:weak_ssl]).to be_nil end end @@ -167,7 +167,7 @@ describe Puppet::Type.type(:apt_key) do Puppet::Type.type(:apt_key).new(id: 'EF8D349F', source: 'http://apt.puppetlabs.com/pubkey.gpg', ensure: :absent, - refresh: :true) + refresh: true) }.to raise_error(%r{ensure => absent and refresh => true are mutually exclusive}) end -- 2.45.2