From 90386a8709cc12cdba9eae498d0a0ce45f7ebc09 Mon Sep 17 00:00:00 2001 From: Joshua Hoblitt Date: Thu, 9 Feb 2023 11:06:36 -0700 Subject: [PATCH] fix rubocop errors --- Gemfile | 10 +++++--- Rakefile | 10 +++++--- lib/voxpupuli/test/facts.rb | 9 ++++--- lib/voxpupuli/test/rake.rb | 5 +++- lib/voxpupuli/test/spec_helper.rb | 6 ++--- spec/facts_spec.rb | 42 ++++++++++++++++++------------- spec/spec_helper.rb | 4 ++- voxpupuli-test.gemspec | 4 +-- 8 files changed, 54 insertions(+), 36 deletions(-) diff --git a/Gemfile b/Gemfile index f7b3415..96e5e53 100644 --- a/Gemfile +++ b/Gemfile @@ -1,14 +1,16 @@ +# frozen_string_literal: true + source 'https://rubygems.org' gemspec group :release do - gem 'github_changelog_generator', :require => false + gem 'github_changelog_generator', require: false end -group :coverage, optional: ENV['COVERAGE']!='yes' do - gem 'simplecov-console', :require => false - gem 'codecov', :require => false +group :coverage, optional: ENV['COVERAGE'] != 'yes' do + gem 'codecov', require: false + gem 'simplecov-console', require: false end # Override gemspec for CI matrix builds. diff --git a/Rakefile b/Rakefile index da4f491..f654361 100644 --- a/Rakefile +++ b/Rakefile @@ -1,12 +1,14 @@ +# frozen_string_literal: true + require 'rspec/core/rake_task' require 'rubocop/rake_task' RSpec::Core::RakeTask.new(:spec) RuboCop::RakeTask.new -task :default => [ - :spec, - :rubocop, +task default: %i[ + spec + rubocop ] begin @@ -14,7 +16,7 @@ begin GitHubChangelogGenerator::RakeTask.new :changelog do |config| config.header = "# Changelog\n\nAll notable changes to this project will be documented in this file." - config.exclude_labels = %w{duplicate question invalid wontfix wont-fix skip-changelog} + config.exclude_labels = %w[duplicate question invalid wontfix wont-fix skip-changelog] config.user = 'voxpupuli' config.project = 'voxpupuli-test' config.future_release = "v#{Gem::Specification.load("#{config.project}.gemspec").version}" diff --git a/lib/voxpupuli/test/facts.rb b/lib/voxpupuli/test/facts.rb index 4c5bd92..480651c 100644 --- a/lib/voxpupuli/test/facts.rb +++ b/lib/voxpupuli/test/facts.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rspec-puppet-facts' include RspecPuppetFacts @@ -51,7 +53,7 @@ def add_facts_for_metadata(metadata) metadata['dependencies'].each do |dependency| case normalize_module_name(dependency['name']) when 'camptocamp/systemd', 'puppet/systemd' - add_custom_fact :systemd, ->(os, facts) { facts['service_provider'] == 'systemd' } + add_custom_fact :systemd, ->(_os, facts) { facts['service_provider'] == 'systemd' } when 'puppetlabs/stdlib' add_stdlib_facts end @@ -60,6 +62,7 @@ def add_facts_for_metadata(metadata) def normalize_module_name(name) return unless name + name.sub('-', '/') end @@ -70,7 +73,7 @@ def add_stdlib_facts # Rough conversion of grepping in the puppet source: # grep defaultfor lib/puppet/provider/service/*.rb - add_custom_fact :service_provider, ->(os, facts) do + add_custom_fact :service_provider, lambda { |_os, facts| case facts[:osfamily].downcase when 'archlinux' 'systemd' @@ -93,5 +96,5 @@ def add_stdlib_facts else 'init' end - end + } end diff --git a/lib/voxpupuli/test/rake.rb b/lib/voxpupuli/test/rake.rb index fd2c101..2221804 100644 --- a/lib/voxpupuli/test/rake.rb +++ b/lib/voxpupuli/test/rake.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppetlabs_spec_helper/rake_tasks' PuppetLint.configuration.log_format = '%{path}:%{line}:%{check}:%{KIND}:%{message}' @@ -14,8 +16,9 @@ task :trailing_whitespace do Dir.glob('**/*.md', File::FNM_DOTMATCH).sort.each do |filename| next if filename =~ %r{^((modules|acceptance|\.?vendor|spec/fixtures|pkg)/|REFERENCE.md)} + File.foreach(filename).each_with_index do |line, index| - if line =~ %r{\s\n$} + if line =~ /\s\n$/ puts "#{filename} has trailing whitespace on line #{index + 1}" exit 1 end diff --git a/lib/voxpupuli/test/spec_helper.rb b/lib/voxpupuli/test/spec_helper.rb index 6022b13..2e7d3ff 100644 --- a/lib/voxpupuli/test/spec_helper.rb +++ b/lib/voxpupuli/test/spec_helper.rb @@ -1,10 +1,10 @@ +# frozen_string_literal: true + RSpec.configure do |config| # puppetlabs_spec_helper defaults to mocha but emits a deprecation warning # Vox Pupuli prefers rspec to avoid the deprecation warning unless explicitly # set - if config.instance_variable_get(:@mock_framework).nil? - config.mock_with :rspec - end + config.mock_with :rspec if config.instance_variable_get(:@mock_framework).nil? end require 'voxpupuli/test/facts' diff --git a/spec/facts_spec.rb b/spec/facts_spec.rb index 2bb230e..62cd059 100644 --- a/spec/facts_spec.rb +++ b/spec/facts_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'voxpupuli/test/facts' @@ -11,7 +13,7 @@ 'full' => '7.7.1908', 'major' => '7', 'minor' => '7' - }, + } } } end @@ -26,7 +28,7 @@ 'full' => '7.7.1908', 'major' => '7', 'minor' => '7' - }, + } } } end @@ -44,15 +46,15 @@ 'full' => '7.7.1908', 'major' => '7', 'minor' => '7' - }, + } }, ruby: { - 'sitedir' => '/usr/local/share/ruby/site_ruby', + 'sitedir' => '/usr/local/share/ruby/site_ruby' } } end - it { expect(override_facts(base_facts, ruby: {sitedir: '/usr/local/share/ruby/site_ruby'})).to eq(expected) } + it { expect(override_facts(base_facts, ruby: { sitedir: '/usr/local/share/ruby/site_ruby' })).to eq(expected) } end describe 'with deep merging' do @@ -65,12 +67,12 @@ 'full' => '7.7.1908', 'major' => '7', 'minor' => '8' - }, + } } } end - it { expect(override_facts(base_facts, os: {release: {minor: '8'}})).to eq(expected) } + it { expect(override_facts(base_facts, os: { release: { minor: '8' } })).to eq(expected) } end describe 'with strings' do @@ -83,12 +85,12 @@ 'full' => '7.7.1908', 'major' => '7', 'minor' => '8' - }, + } } } end - it { expect(override_facts(base_facts, os: {'release' => {minor: '8'}})).to eq(expected) } + it { expect(override_facts(base_facts, os: { 'release' => { minor: '8' } })).to eq(expected) } end end @@ -112,7 +114,7 @@ context 'with systemd' do let(:dependencies) do [ - {'name' => 'puppet/systemd'}, + { 'name' => 'puppet/systemd' } ] end @@ -124,26 +126,28 @@ context 'and stdlib' do let(:dependencies) do [ - {'name' => 'puppetlabs/stdlib'}, - {'name' => 'puppet/systemd'}, + { 'name' => 'puppetlabs/stdlib' }, + { 'name' => 'puppet/systemd' } ] end it 'has systemd on Red Hat 7' do add_facts_for_metadata(metadata) - facts = RspecPuppetFacts.with_custom_facts('redhat-7-x86_64', {osfamily: 'RedHat', operatingsystemmajrelease: '7'}) + facts = RspecPuppetFacts.with_custom_facts('redhat-7-x86_64', + { osfamily: 'RedHat', operatingsystemmajrelease: '7' }) expect(facts['systemd']).to be true end it 'has no systemd on Red Hat 6' do add_facts_for_metadata(metadata) - facts = RspecPuppetFacts.with_custom_facts('redhat-6-x86_64', {osfamily: 'RedHat', operatingsystemmajrelease: '6'}) + facts = RspecPuppetFacts.with_custom_facts('redhat-6-x86_64', + { osfamily: 'RedHat', operatingsystemmajrelease: '6' }) expect(facts['systemd']).to be false end it 'has no systemd on openbsd' do add_facts_for_metadata(metadata) - facts = RspecPuppetFacts.with_custom_facts('openbsd-6.4-x86_64', {osfamily: 'OpenBSD'}) + facts = RspecPuppetFacts.with_custom_facts('openbsd-6.4-x86_64', { osfamily: 'OpenBSD' }) expect(facts['systemd']).to be false end end @@ -152,13 +156,15 @@ context 'with stdlib' do let(:dependencies) do [ - {'name' => 'puppetlabs/stdlib'}, + { 'name' => 'puppetlabs/stdlib' } ] end it 'adds the systemd fact' do - expect(RspecPuppetFacts).to receive(:register_custom_fact).with(:puppet_environmentpath, '/etc/puppetlabs/code/environments', {}) - expect(RspecPuppetFacts).to receive(:register_custom_fact).with(:puppet_vardir, '/opt/puppetlabs/puppet/cache', {}) + expect(RspecPuppetFacts).to receive(:register_custom_fact).with(:puppet_environmentpath, + '/etc/puppetlabs/code/environments', {}) + expect(RspecPuppetFacts).to receive(:register_custom_fact).with(:puppet_vardir, '/opt/puppetlabs/puppet/cache', + {}) expect(RspecPuppetFacts).to receive(:register_custom_fact).with(:root_home, '/root', {}) expect(RspecPuppetFacts).to receive(:register_custom_fact).with(:service_provider, instance_of(Proc), {}) add_facts_for_metadata(metadata) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 73fb578..ae3a767 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + begin require 'simplecov' require 'simplecov-console' @@ -18,7 +20,7 @@ SimpleCov.formatters = [ SimpleCov::Formatter::Console, - SimpleCov::Formatter::Codecov, + SimpleCov::Formatter::Codecov ] end diff --git a/voxpupuli-test.gemspec b/voxpupuli-test.gemspec index e562c71..f482c7c 100644 --- a/voxpupuli-test.gemspec +++ b/voxpupuli-test.gemspec @@ -1,4 +1,4 @@ -# -*- encoding: utf-8 -*- +# frozen_string_literal: true Gem::Specification.new do |s| s.name = 'voxpupuli-test' @@ -28,8 +28,8 @@ Gem::Specification.new do |s| # Rubocop s.add_runtime_dependency 'rubocop', '~> 1.22.3' - s.add_runtime_dependency 'rubocop-rspec', '~> 2.5' s.add_runtime_dependency 'rubocop-rake', '~> 0.6.0' + s.add_runtime_dependency 'rubocop-rspec', '~> 2.5' # Linting # meta gem to pull in all puppet-lint plugins + puppet-lint itself