Skip to content

Commit 453848c

Browse files
committed
rubocop: Fix Layout cops
1 parent 6913f88 commit 453848c

File tree

5 files changed

+52
-48
lines changed

5 files changed

+52
-48
lines changed

.rubocop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ inherit_from: .rubocop_todo.yml
44
inherit_gem:
55
voxpupuli-rubocop: rubocop.yml
66

7-
Layout:
7+
Layout/LineLength:
88
Enabled: false
99

1010
# To match the gem name

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ group :release do
99
gem 'github_changelog_generator', '~> 1.16.4', require: false
1010
end
1111

12-
group :coverage, optional: ENV['COVERAGE']!='yes' do
12+
group :coverage, optional: ENV['COVERAGE'] != 'yes' do
1313
gem 'codecov', require: false
1414
gem 'simplecov-console', require: false
1515
end

Rakefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
PUPPET_VERSIONS_PATH = File.join(__dir__, 'ext', 'puppet_agent_components.json')
22

33
begin
4-
require 'rspec/core/rake_task'
5-
require 'yard'
6-
RSpec::Core::RakeTask.new(:spec)
7-
YARD::Rake::YardocTask.new
4+
require 'rspec/core/rake_task'
5+
require 'yard'
6+
RSpec::Core::RakeTask.new(:spec)
7+
YARD::Rake::YardocTask.new
88
rescue LoadError
99
# yard is optional
1010
end

lib/rspec-puppet-facts.rb

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,14 @@ def on_supported_os(opts = {})
5858
# @api private
5959
def on_supported_os_implementation(opts = {})
6060
unless /\A\d+\.\d+(?:\.\d+)*\z/.match?((facterversion = opts[:facterversion]))
61-
raise ArgumentError, ":facterversion must be in the format 'n.n' or " \
62-
"'n.n.n' (n is numeric), not '#{facterversion}'"
61+
raise ArgumentError, ":facterversion must be in the format 'n.n' or 'n.n.n' (n is numeric), not '#{facterversion}'"
6362
end
6463

6564
filter = []
6665
opts[:supported_os].map do |os_sup|
6766
if os_sup['operatingsystemrelease']
6867
Array(os_sup['operatingsystemrelease']).map do |operatingsystemmajrelease|
6968
opts[:hardwaremodels].each do |hardwaremodel|
70-
7169
os_release_filter = "/^#{Regexp.escape(operatingsystemmajrelease.split(' ')[0])}/"
7270
case os_sup['operatingsystem']
7371
when /BSD/i
@@ -119,7 +117,9 @@ def on_supported_os_implementation(opts = {})
119117
# facter data (see FacterDB 0.5.2 for Facter releases 3.8 and 3.9). In this situation we need to
120118
# cycle through and downgrade Facter versions per platform type until we find matching Facter data.
121119
filter.each do |filter_spec|
122-
versions = FacterDB.get_facts(filter_spec, symbolize_keys: !RSpec.configuration.facterdb_string_keys).to_h { |facts| [Gem::Version.new(facts[:facterversion]), facts] }
120+
versions = FacterDB.get_facts(filter_spec, symbolize_keys: !RSpec.configuration.facterdb_string_keys).to_h do |facts|
121+
[Gem::Version.new(facts[:facterversion]), facts]
122+
end
123123

124124
version, facts = versions.select { |v, _f| strict_requirement =~ v }.max_by { |v, _f| v }
125125

@@ -150,6 +150,7 @@ def on_supported_os_implementation(opts = {})
150150

151151
os = "#{os_fact['name'].downcase}-#{os_fact['release']['major']}-#{os_fact['hardware']}"
152152
next if RspecPuppetFacts.spec_facts_os_filter && !os.start_with?(RspecPuppetFacts.spec_facts_os_filter)
153+
153154
facts.merge! RspecPuppetFacts.common_facts
154155
os_facts_hash[os] = RspecPuppetFacts.with_custom_facts(os, facts)
155156
end
@@ -191,7 +192,7 @@ def add_custom_fact(name, value, options = {})
191192
def self.register_custom_fact(name, value, options)
192193
@custom_facts ||= {}
193194
name = RSpec.configuration.facterdb_string_keys ? name.to_s : name.to_sym
194-
@custom_facts[name] = {options: options, value: value}
195+
@custom_facts[name] = { options: options, value: value }
195196
end
196197

197198
# Adds any custom facts according to the rules defined for the operating
@@ -210,7 +211,7 @@ def self.with_custom_facts(os, facts)
210211
value = fact[:value].respond_to?(:call) ? fact[:value].call(os, facts) : fact[:value]
211212
# if merge_facts passed, merge supplied facts into facts hash
212213
if fact[:options][:merge_facts]
213-
facts.deep_merge!({name => value})
214+
facts.deep_merge!({ name => value })
214215
else
215216
facts[name] = value
216217
end
@@ -249,6 +250,7 @@ def self.spec_facts_strict?
249250
# @return [Hash <Symbol => String>]
250251
def self.common_facts
251252
return @common_facts if @common_facts
253+
252254
@common_facts = {
253255
puppetversion: Puppet.version,
254256
rubysitedir: RbConfig::CONFIG['sitelibdir'],
@@ -295,6 +297,7 @@ def self.mcollective?
295297
# @api private
296298
def self.meta_supported_os
297299
raise StandardError, 'Unknown operatingsystem support in the metadata file!' unless metadata['operatingsystem_support'].is_a? Array
300+
298301
metadata['operatingsystem_support']
299302
end
300303

@@ -306,6 +309,7 @@ def self.meta_supported_os
306309
def self.metadata
307310
return @metadata if @metadata
308311
raise StandardError, "Can't find metadata.json... dunno why" unless File.file? metadata_file
312+
309313
content = File.read metadata_file
310314
@metadata = JSON.parse content
311315
end
@@ -411,8 +415,6 @@ def self.facter_version_for_puppet_version(puppet_version)
411415
end
412416

413417
RSpec.configure do |c|
414-
c.add_setting :default_facter_version,
415-
default: RspecPuppetFacts.facter_version_for_puppet_version(Puppet.version)
416-
c.add_setting :facterdb_string_keys,
417-
default: false
418+
c.add_setting :default_facter_version, default: RspecPuppetFacts.facter_version_for_puppet_version(Puppet.version)
419+
c.add_setting :facterdb_string_keys, default: false
418420
end

spec/rspec_puppet_facts_spec.rb

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
end
99

1010
describe '.stringify_keys' do
11-
it { expect(described_class.stringify_keys({ os: { family: 'RedHat' } })).to eq({ 'os' => { 'family' => 'RedHat' } }) }
11+
it {
12+
expect(described_class.stringify_keys({ os: { family: 'RedHat' } })).to eq({ 'os' => { 'family' => 'RedHat' } })
13+
}
1214
end
1315

1416
describe '.facter_version_for_puppet_version' do
@@ -139,7 +141,7 @@
139141
{
140142
supported_os: [
141143
{
142-
'operatingsystem' => 'Debian',
144+
'operatingsystem' => 'Debian',
143145
'operatingsystemrelease' => ['12'],
144146
},
145147
],
@@ -148,7 +150,7 @@
148150
end
149151

150152
let(:get_keys) do
151-
proc { |r| r.keys + r.select { |_,v| v.is_a?(Hash) }.map { |_,v| get_keys.call(v) }.flatten }
153+
proc { |r| r.keys + r.select { |_, v| v.is_a?(Hash) }.map { |_, v| get_keys.call(v) }.flatten }
152154
end
153155

154156
context 'set to true' do
@@ -245,14 +247,13 @@
245247
context 'With a wrong operatingsystem_support section' do
246248
let(:metadata) do
247249
{
248-
'operatingsystem_support' => 'Ubuntu',
250+
'operatingsystem_support' => 'Ubuntu',
249251
}
250252
end
251253

252254
it { expect { subject }.to raise_error(StandardError, /Unknown operatingsystem support/) }
253255
end
254256
end
255-
256257
end
257258
end
258259

@@ -441,17 +442,17 @@
441442
context 'When testing AIX 7.1' do
442443
subject do
443444
on_supported_os(
444-
{
445-
supported_os: [
446-
{
447-
'operatingsystem' => 'AIX',
448-
'operatingsystemrelease' => [
449-
'7.1', '7100',
450-
],
451-
},
445+
{
446+
supported_os: [
447+
{
448+
'operatingsystem' => 'AIX',
449+
'operatingsystemrelease' => [
450+
'7.1', '7100',
452451
],
453-
facterversion: '3.9',
454-
},
452+
},
453+
],
454+
facterversion: '3.9',
455+
},
455456
)
456457
end
457458

@@ -475,7 +476,7 @@
475476
{
476477
supported_os: [
477478
{
478-
'operatingsystem' => 'Windows',
479+
'operatingsystem' => 'Windows',
479480
'operatingsystemrelease' => release,
480481
},
481482
],
@@ -598,7 +599,7 @@
598599
{
599600
supported_os: [
600601
{
601-
'operatingsystem' => 'IOS',
602+
'operatingsystem' => 'IOS',
602603
'operatingsystemrelease' => ['12.2(25)EWA9'],
603604
},
604605
],
@@ -612,9 +613,9 @@
612613

613614
it 'escapes the parens in the filter' do
614615
filter = {
615-
'os.name' => 'IOS',
616+
'os.name' => 'IOS',
616617
'os.release.full' => '/^12\\.2\\(25\\)EWA9/',
617-
'os.hardware' => 'x86_64',
618+
'os.hardware' => 'x86_64',
618619
}
619620

620621
expect(FacterDB).to receive(:get_facts).with(filter, symbolize_keys: true).once
@@ -643,7 +644,6 @@
643644
RSpec.configuration.default_facter_version = Facter.version
644645
end
645646

646-
647647
it 'returns facts from the specified default Facter version' do
648648
is_expected.to match(
649649
'centos-9-x86_64' => include(
@@ -667,7 +667,6 @@
667667
allow(Facter).to receive(:version).and_return('4.6')
668668
end
669669

670-
671670
it 'returns facts from a facter version matching version and below' do
672671
is_expected.to match(
673672
'centos-9-x86_64' => include(
@@ -747,7 +746,7 @@
747746
before do
748747
allow(FacterDB).to receive(:get_facts).and_call_original
749748
allow(FacterDB).to receive(:get_facts).with(
750-
{'os.name'=>'CentOS', 'os.release.full'=>'/^9/', 'os.hardware'=>'x86_64'}, symbolize_keys: true
749+
{ 'os.name' => 'CentOS', 'os.release.full' => '/^9/', 'os.hardware' => 'x86_64' }, symbolize_keys: true
751750
).and_wrap_original do |m, *args|
752751
m.call(*args).reject { |facts| facts[:facterversion].start_with?('4.6.') }
753752
end
@@ -792,21 +791,23 @@
792791
it 'merges a fact value into fact when merge_facts passed' do
793792
add_custom_fact :identity, { 'user' => 'test_user' }, merge_facts: true
794793
expect(subject['redhat-9-x86_64'][:identity]).to eq(
795-
{
796-
'gid'=>0,
797-
'group'=>'root',
798-
'privileged'=>true,
799-
'uid'=>0,
800-
'user'=>'test_user',
801-
})
794+
{
795+
'gid' => 0,
796+
'group' => 'root',
797+
'privileged' => true,
798+
'uid' => 0,
799+
'user' => 'test_user',
800+
},
801+
)
802802
end
803803

804804
it 'overwrites fact' do
805805
add_custom_fact :identity, { 'user' => 'other_user' }
806806
expect(subject['redhat-9-x86_64'][:identity]).to eq(
807-
{
808-
'user'=>'other_user',
809-
})
807+
{
808+
'user' => 'other_user',
809+
},
810+
)
810811
end
811812

812813
it 'confines a fact to a particular operating system' do
@@ -851,6 +852,7 @@ module AugeasStub # rubocop:todo Lint/ConstantDefinitionInBlock
851852
def self.open(*_args)
852853
self
853854
end
855+
854856
def self.get(*_args)
855857
'my_version'
856858
end

0 commit comments

Comments
 (0)