Skip to content

Commit 5d7bfa0

Browse files
committed
(CONT-237) Rubocop - fixes for spec_helper
1 parent 24d92da commit 5d7bfa0

File tree

3 files changed

+73
-77
lines changed

3 files changed

+73
-77
lines changed

lib/puppetlabs_spec_helper/module_spec_helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ def verify_contents(subject, title, expected_lines)
5353
end
5454

5555
# Add all spec lib dirs to LOAD_PATH
56-
components = module_path.split(File::PATH_SEPARATOR).collect do |dir|
56+
components = module_path.split(File::PATH_SEPARATOR).map do |dir|
5757
next unless Dir.exist? dir
58-
Dir.entries(dir).reject { |f| f =~ %r{^\.} }.collect { |f| File.join(dir, f, 'spec', 'lib') }
58+
Dir.entries(dir).reject { |f| f =~ %r{^\.} }.map { |f| File.join(dir, f, 'spec', 'lib') }
5959
end
6060
components.flatten.each do |d|
6161
$LOAD_PATH << d if FileTest.directory?(d) && !$LOAD_PATH.include?(d)

lib/puppetlabs_spec_helper/puppet_spec_helper.rb

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -48,62 +48,63 @@
4848
begin
4949
require 'puppet/test/test_helper'
5050
rescue LoadError
51+
# Continue gracefully
5152
end
5253

5354
# This is just a utility class to allow us to isolate the various version-specific
5455
# branches of initialization logic into methods without polluting the global namespace.#
55-
module Puppet
56-
class PuppetSpecInitializer
57-
# This method is for initializing puppet state for testing for older versions
58-
# of puppet that do not support the new TestHelper API. As you can see,
59-
# this involves explicitly modifying global variables, directly manipulating
60-
# Puppet's Settings singleton object, and other fun implementation details
61-
# that code external to puppet should really never know about.
62-
def self.initialize_via_fallback_compatibility(config)
63-
warn('Warning: you appear to be using an older version of puppet; spec_helper will use fallback compatibility mode.')
64-
config.before :all do
65-
# nothing to do for now
66-
end
56+
class Puppet::PuppetSpecInitializer
57+
# This method is for initializing puppet state for testing for older versions
58+
# of puppet that do not support the new TestHelper API. As you can see,
59+
# this involves explicitly modifying global variables, directly manipulating
60+
# Puppet's Settings singleton object, and other fun implementation details
61+
# that code external to puppet should really never know about.
62+
def self.initialize_via_fallback_compatibility(config)
63+
warn('Warning: you appear to be using an older version of puppet; spec_helper will use fallback compatibility mode.')
64+
config.before :all do
65+
# nothing to do for now
66+
end
6767

68-
config.after :all do
69-
# nothing to do for now
70-
end
68+
config.after :all do
69+
# nothing to do for now
70+
end
7171

72-
config.before :each do
73-
# these globals are set by Application
74-
$puppet_application_mode = nil
75-
$puppet_application_name = nil
72+
config.before :each do
73+
# these globals are set by Application
74+
$puppet_application_mode = nil # rubocop:disable Style/GlobalVars
75+
$puppet_application_name = nil # rubocop:disable Style/GlobalVars
7676

77-
# REVISIT: I think this conceals other bad tests, but I don't have time to
78-
# fully diagnose those right now. When you read this, please come tell me
79-
# I suck for letting this float. --daniel 2011-04-21
80-
Signal.stubs(:trap)
77+
# REVISIT: I think this conceals other bad tests, but I don't have time to
78+
# fully diagnose those right now. When you read this, please come tell me
79+
# I suck for letting this float. --daniel 2011-04-21
80+
Signal.stubs(:trap)
8181

82-
# Set the confdir and vardir to gibberish so that tests
83-
# have to be correctly mocked.
84-
Puppet[:confdir] = '/dev/null'
85-
Puppet[:vardir] = '/dev/null'
82+
# Set the confdir and vardir to gibberish so that tests
83+
# have to be correctly mocked.
84+
Puppet[:confdir] = '/dev/null'
85+
Puppet[:vardir] = '/dev/null'
8686

87-
# Avoid opening ports to the outside world
88-
Puppet.settings[:bindaddress] = '127.0.0.1'
89-
end
87+
# Avoid opening ports to the outside world
88+
Puppet.settings[:bindaddress] = '127.0.0.1'
89+
end
9090

91-
config.after :each do
92-
Puppet.settings.clear
91+
config.after :each do
92+
Puppet.settings.clear
9393

94-
Puppet::Node::Environment.clear
95-
Puppet::Util::Storage.clear
96-
Puppet::Util::ExecutionStub.reset if Puppet::Util.constants.include? 'ExecutionStub'
94+
Puppet::Node::Environment.clear
95+
Puppet::Util::Storage.clear
96+
Puppet::Util::ExecutionStub.reset if Puppet::Util.constants.include? 'ExecutionStub'
9797

98-
PuppetlabsSpec::Files.cleanup
99-
end
98+
PuppetlabsSpec::Files.cleanup
10099
end
101100
end
102101
end
103102

104103
# JJM Hack to make the stdlib tests run in Puppet 2.6 (See puppet commit cf183534)
105104
unless Puppet.constants.include? 'Test'
106105
module Puppet::Test
106+
# This is a stub class to allow the stdlib tests to run in Puppet 2.6
107+
# This class will be removed in another commit.
107108
class LogCollector
108109
def initialize(logs)
109110
@logs = logs

lib/puppetlabs_spec_helper/rake_tasks.rb

Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,11 @@
7979

8080
desc 'Run spec tests and clean the fixtures directory if successful'
8181
task :spec do |_t, args|
82-
begin
83-
Rake::Task[:spec_prep].invoke
84-
Rake::Task[:spec_standalone].invoke(*args.extras)
85-
Rake::Task[:spec_clean].invoke
86-
ensure
87-
Rake::Task[:spec_clean_symlinks].invoke
88-
end
82+
Rake::Task[:spec_prep].invoke
83+
Rake::Task[:spec_standalone].invoke(*args.extras)
84+
Rake::Task[:spec_clean].invoke
85+
ensure
86+
Rake::Task[:spec_clean_symlinks].invoke
8987
end
9088

9189
desc 'Run spec tests with ruby simplecov code coverage'
@@ -98,13 +96,11 @@
9896

9997
desc 'Run spec tests in parallel and clean the fixtures directory if successful'
10098
task :parallel_spec do |_t, args|
101-
begin
102-
Rake::Task[:spec_prep].invoke
103-
Rake::Task[:parallel_spec_standalone].invoke(*args.extras)
104-
Rake::Task[:spec_clean].invoke
105-
ensure
106-
Rake::Task[:spec_clean_symlinks].invoke
107-
end
99+
Rake::Task[:spec_prep].invoke
100+
Rake::Task[:parallel_spec_standalone].invoke(*args.extras)
101+
Rake::Task[:spec_clean].invoke
102+
ensure
103+
Rake::Task[:spec_clean_symlinks].invoke
108104
end
109105

110106
desc 'Parallel spec tests'
@@ -144,21 +140,19 @@
144140

145141
desc 'Build Puppet module with PDK'
146142
task :pdk do
147-
begin
148-
require 'pdk/util'
149-
require 'pdk/module/build'
150-
151-
path = PDK::Module::Build.invoke(force: true, 'target-dir': File.join(Dir.pwd, 'pkg'))
152-
puts "Module built: #{path}"
153-
rescue LoadError
154-
_ = `pdk --version`
155-
unless $CHILD_STATUS.success?
156-
warn 'Unable to build module. Please install PDK or add the `pdk` gem to your Gemfile.'
157-
abort
158-
end
159-
160-
system('pdk build --force')
143+
require 'pdk/util'
144+
require 'pdk/module/build'
145+
146+
path = PDK::Module::Build.invoke(force: true, 'target-dir': File.join(Dir.pwd, 'pkg'))
147+
puts "Module built: #{path}"
148+
rescue LoadError
149+
_ = `pdk --version`
150+
unless $CHILD_STATUS.success?
151+
warn 'Unable to build module. Please install PDK or add the `pdk` gem to your Gemfile.'
152+
abort
161153
end
154+
155+
system('pdk build --force')
162156
end
163157
end
164158

@@ -183,15 +177,16 @@
183177
PuppetLint.configuration.ignore_paths << 'tests/**/*.pp'
184178
PuppetLint.configuration.ignore_paths << 'types/**/*.pp'
185179
PuppetLint.configuration.ignore_paths << 'vendor/**/*.pp'
186-
puppet_lint_disable_checks = %w[
187-
80chars
188-
140chars
189-
class_inherits_from_params_class
190-
class_parameter_defaults
191-
disable_autoloader_layout
192-
documentation
193-
single_quote_string_with_variables
180+
puppet_lint_disable_checks = [
181+
'80chars',
182+
'140chars',
183+
'class_inherits_from_params_class',
184+
'class_parameter_defaults',
185+
'disable_autoloader_layout',
186+
'documentation',
187+
'single_quote_string_with_variables',
194188
]
189+
195190
puppet_lint_disable_checks.each do |check|
196191
PuppetLint.configuration.send("disable_#{check}")
197192
end
@@ -268,7 +263,7 @@
268263
# If the branch is a release branch we append an 'r' into the new_version,
269264
# this is due to the release branch buildID conflicting with main branch when trying to push to the staging forge.
270265
# More info can be found at https://tickets.puppetlabs.com/browse/FM-6170
271-
new_version = if build = (ENV['BUILD_NUMBER'] || ENV['TRAVIS_BUILD_NUMBER'])
266+
new_version = if (build = (ENV['BUILD_NUMBER'] || ENV['TRAVIS_BUILD_NUMBER']))
272267
if branch.eql? 'release'
273268
'%s-%s%04d-%s' % [version, 'r', build, sha] # legacy support code # rubocop:disable Style/FormatStringToken
274269
else
@@ -416,7 +411,7 @@ def changelog_future_release
416411
},
417412
'Added' => {
418413
'prefix' => '### Added',
419-
'labels' => %w[feature enhancement],
414+
'labels' => ['feature', 'enhancement'],
420415
},
421416
'Fixed' => {
422417
'prefix' => '### Fixed',

0 commit comments

Comments
 (0)