puppetlabs_spec_helper 4.0.1 → 5.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +481 -116
  3. data/README.md +5 -19
  4. data/lib/puppetlabs_spec_helper/module_spec_helper.rb +8 -10
  5. data/lib/puppetlabs_spec_helper/puppet_spec_helper.rb +2 -86
  6. data/lib/puppetlabs_spec_helper/puppetlabs_spec/files.rb +3 -1
  7. data/lib/puppetlabs_spec_helper/puppetlabs_spec/fixtures.rb +3 -3
  8. data/lib/puppetlabs_spec_helper/puppetlabs_spec/matchers.rb +0 -17
  9. data/lib/puppetlabs_spec_helper/puppetlabs_spec/puppet_internals.rb +35 -68
  10. data/lib/puppetlabs_spec_helper/rake_tasks.rb +44 -63
  11. data/lib/puppetlabs_spec_helper/tasks/check_symlinks.rb +1 -3
  12. data/lib/puppetlabs_spec_helper/tasks/fixtures.rb +14 -12
  13. data/lib/puppetlabs_spec_helper/version.rb +1 -6
  14. data/spec/acceptance/fixtures/Rakefile +3 -0
  15. data/spec/acceptance/smoke_spec.rb +14 -0
  16. data/spec/spec_helper.rb +53 -0
  17. data/spec/unit/puppetlabs_spec_helper/puppetlabs_spec/puppet_internals_spec.rb +71 -0
  18. data/spec/unit/puppetlabs_spec_helper/tasks/check_symlinks_spec.rb +162 -0
  19. data/spec/unit/puppetlabs_spec_helper/tasks/check_test_file_spec.rb +45 -0
  20. data/spec/unit/puppetlabs_spec_helper/tasks/fixtures_spec.rb +262 -0
  21. data/spec/watchr.rb +81 -0
  22. metadata +32 -146
  23. data/.github/dependabot.yml +0 -15
  24. data/.gitignore +0 -9
  25. data/.noexec.yaml +0 -4
  26. data/.rspec +0 -2
  27. data/.rubocop_todo.yml +0 -119
  28. data/.travis.yml +0 -23
  29. data/CHANGELOG.md +0 -727
  30. data/CODEOWNERS +0 -2
  31. data/CONTRIBUTING.md +0 -14
  32. data/Gemfile +0 -42
  33. data/HISTORY.md +0 -498
  34. data/Rakefile +0 -45
  35. data/puppet_spec_helper.rb +0 -7
  36. data/puppetlabs_spec_helper.gemspec +0 -38
  37. data/puppetlabs_spec_helper.rb +0 -7
@@ -53,19 +53,22 @@ if ENV['SIMPLECOV'] == 'yes'
53
53
  end
54
54
 
55
55
  # 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|
57
57
  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') }
59
59
  end
60
60
  components.flatten.each do |d|
61
61
  $LOAD_PATH << d if FileTest.directory?(d) && !$LOAD_PATH.include?(d)
62
62
  end
63
63
 
64
64
  RSpec.configure do |c|
65
- c.environmentpath = spec_path if Puppet.version.to_f >= 4.0
65
+ if ENV['GITHUB_ACTIONS'] == 'true'
66
+ c.formatter = 'RSpec::Github::Formatter'
67
+ end
68
+
69
+ c.environmentpath = spec_path
66
70
  c.module_path = module_path
67
71
  c.manifest_dir = File.join(fixture_path, 'manifests')
68
- c.parser = 'future' if ENV['FUTURE_PARSER'] == 'yes'
69
72
 
70
73
  c.before :each do
71
74
  if c.mock_framework.framework_name == :rspec
@@ -74,12 +77,7 @@ RSpec.configure do |c|
74
77
  Puppet.features.stubs(:root?).returns(true)
75
78
  end
76
79
 
77
- # stringify_facts and trusted_node_data were removed in puppet4
78
- if Puppet.version.to_f < 4.0
79
- Puppet.settings[:stringify_facts] = false if ENV['STRINGIFY_FACTS'] == 'no'
80
- Puppet.settings[:trusted_node_data] = true if ENV['TRUSTED_NODE_DATA'] == 'yes'
81
- end
82
- Puppet.settings[:strict_variables] = true if ENV['STRICT_VARIABLES'] == 'yes' || (Puppet.version.to_f >= 4.0 && ENV['STRICT_VARIABLES'] != 'no')
80
+ Puppet.settings[:strict_variables] = true if ENV['STRICT_VARIABLES'] == 'yes' || ENV['STRICT_VARIABLES'] != 'no'
83
81
  Puppet.settings[:ordering] = ENV['ORDERING'] if ENV['ORDERING']
84
82
  end
85
83
  end
@@ -48,83 +48,7 @@ require 'puppetlabs_spec_helper/puppetlabs_spec/files'
48
48
  begin
49
49
  require 'puppet/test/test_helper'
50
50
  rescue LoadError
51
- end
52
-
53
- # This is just a utility class to allow us to isolate the various version-specific
54
- # 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
67
-
68
- config.after :all do
69
- # nothing to do for now
70
- end
71
-
72
- config.before :each do
73
- # these globals are set by Application
74
- $puppet_application_mode = nil
75
- $puppet_application_name = nil
76
-
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)
81
-
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'
86
-
87
- # Avoid opening ports to the outside world
88
- Puppet.settings[:bindaddress] = '127.0.0.1'
89
- end
90
-
91
- config.after :each do
92
- Puppet.settings.clear
93
-
94
- Puppet::Node::Environment.clear
95
- Puppet::Util::Storage.clear
96
- Puppet::Util::ExecutionStub.reset if Puppet::Util.constants.include? 'ExecutionStub'
97
-
98
- PuppetlabsSpec::Files.cleanup
99
- end
100
- end
101
- end
102
- end
103
-
104
- # JJM Hack to make the stdlib tests run in Puppet 2.6 (See puppet commit cf183534)
105
- unless Puppet.constants.include? 'Test'
106
- module Puppet::Test
107
- class LogCollector
108
- def initialize(logs)
109
- @logs = logs
110
- end
111
-
112
- def <<(value)
113
- @logs << value
114
- end
115
- end
116
- end
117
- Puppet::Util::Log.newdesttype :log_collector do
118
- match 'Puppet::Test::LogCollector'
119
-
120
- def initialize(messages)
121
- @messages = messages
122
- end
123
-
124
- def handle(msg)
125
- @messages << msg
126
- end
127
- end
51
+ # Continue gracefully
128
52
  end
129
53
 
130
54
  # And here is where we do the main rspec configuration / setup.
@@ -134,15 +58,7 @@ RSpec.configure do |config|
134
58
  # `mock_framework`'s autoloading to distinguish between the default, and
135
59
  # the module's choice.
136
60
  if config.instance_variable_get(:@mock_framework).nil?
137
- RSpec.warn_deprecation('puppetlabs_spec_helper: defaults `mock_with` to `:mocha`. See https://github.com/puppetlabs/puppetlabs_spec_helper#mock_with to choose a sensible value for you')
138
- config.mock_with :mocha
139
- end
140
-
141
- # determine whether we can use the new API or not, and call the appropriate initializer method.
142
- if defined?(Puppet::Test::TestHelper)
143
- # This case is handled by rspec-puppet since v1.0.0 (via 41257b33cb1f9ade4426b044f70be511b0c89112)
144
- else
145
- Puppet::PuppetSpecInitializer.initialize_via_fallback_compatibility(config)
61
+ config.mock_with :rspec
146
62
  end
147
63
 
148
64
  # Here we do some general setup that is relevant to all initialization modes, regardless
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # rubocop:disable Style/GlobalVars # TODO: investigate the use of instance variables
4
+
3
5
  require 'fileutils'
4
6
  require 'tempfile'
5
7
  require 'pathname'
@@ -20,7 +22,7 @@ module PuppetlabsSpec::Files
20
22
 
21
23
  def self.cleanup
22
24
  $global_tempfiles ||= []
23
- while path = $global_tempfiles.pop
25
+ while (path = $global_tempfiles.pop)
24
26
  raise "Not deleting tmpfile #{path} outside regular tmpdir" unless in_tmp(path)
25
27
 
26
28
  begin
@@ -14,8 +14,8 @@ module PuppetlabsSpec::Fixtures
14
14
  # <project>/spec/fixture/unit/facter/foo
15
15
  def my_fixture_dir
16
16
  callers = caller
17
- while line = callers.shift
18
- next unless found = line.match(%r{/spec/(.*)_spec\.rb:})
17
+ while (line = callers.shift)
18
+ next unless (found = line.match(%r{/spec/(.*)_spec\.rb:}))
19
19
 
20
20
  return fixtures(found[1])
21
21
  end
@@ -47,7 +47,7 @@ module PuppetlabsSpec::Fixtures
47
47
  raise "fixture '#{glob}' for #{my_fixture_dir} had no files!"
48
48
  end
49
49
 
50
- block_given? && files.each(&block)
50
+ block && files.each(&block)
51
51
  files
52
52
  end
53
53
  end
@@ -3,23 +3,6 @@
3
3
  require 'stringio'
4
4
  require 'rspec/expectations'
5
5
 
6
- ########################################################################
7
- # Backward compatibility for Jenkins outdated environment.
8
- module RSpec
9
- module Matchers
10
- module BlockAliases
11
- if method_defined?(:should) && !method_defined?(:to)
12
- alias to should
13
- end
14
- if method_defined? :should_not
15
- alias to_not should_not unless method_defined? :to_not
16
- alias not_to should_not unless method_defined? :not_to
17
- end
18
- end
19
- end
20
- end
21
-
22
- ########################################################################
23
6
  # Custom matchers...
24
7
  RSpec::Matchers.define :have_matching_element do |expected|
25
8
  match do |actual|
@@ -4,74 +4,41 @@
4
4
  # 'puppetlabs_spec_helper/puppet_spec_helper' library
5
5
  require 'puppetlabs_spec_helper/puppet_spec_helper'
6
6
 
7
- module PuppetlabsSpec
8
- module PuppetInternals
9
- # parser_scope is intended to return a Puppet::Parser::Scope
10
- # instance suitable for placing in a test harness with the intent of
11
- # testing parser functions from modules.
12
- def scope(parts = {})
13
- RSpec.deprecate('scope', replacement: 'rspec-puppet 2.2.0 provides a scope property')
14
-
15
- if %r{^2\.[67]}.match?(Puppet.version)
16
- # loadall should only be necessary prior to 3.x
17
- # Please note, loadall needs to happen first when creating a scope, otherwise
18
- # you might receive undefined method `function_*' errors
19
- Puppet::Parser::Functions.autoloader.loadall
20
- end
21
-
22
- scope_compiler = parts[:compiler] || compiler
23
- scope_parent = parts[:parent] || scope_compiler.topscope
24
- scope_resource = parts[:resource] || resource(type: :node, title: scope_compiler.node.name)
25
-
26
- scope = if %r{^2\.[67]}.match?(Puppet.version)
27
- Puppet::Parser::Scope.new(compiler: scope_compiler)
28
- else
29
- Puppet::Parser::Scope.new(scope_compiler)
30
- end
31
-
32
- scope.source = Puppet::Resource::Type.new(:node, 'foo')
33
- scope.parent = scope_parent
34
- scope
35
- end
36
- module_function :scope
37
-
38
- def resource(parts = {})
39
- resource_type = parts[:type] || :hostclass
40
- resource_name = parts[:name] || 'testing'
41
- Puppet::Resource::Type.new(resource_type, resource_name)
42
- end
43
- module_function :resource
44
-
45
- def compiler(parts = {})
46
- compiler_node = parts[:node] || node
47
- Puppet::Parser::Compiler.new(compiler_node)
48
- end
49
- module_function :compiler
50
-
51
- def node(parts = {})
52
- node_name = parts[:name] || 'testinghost'
53
- options = parts[:options] || {}
54
- node_environment = if Puppet.version.to_f >= 4.0
55
- Puppet::Node::Environment.create(parts[:environment] || 'test', [])
56
- else
57
- Puppet::Node::Environment.new(parts[:environment] || 'test')
58
- end
59
- options[:environment] = node_environment
60
- Puppet::Node.new(node_name, options)
61
- end
62
- module_function :node
63
-
64
- # Return a method instance for a given function. This is primarily useful
65
- # for rspec-puppet
66
- def function_method(name, parts = {})
67
- scope = parts[:scope] || scope()
68
- # Ensure the method instance is defined by side-effect of checking if it
69
- # exists. This is a hack, but at least it's a hidden hack and not an
70
- # exposed hack.
71
- return nil unless Puppet::Parser::Functions.function(name)
7
+ # PuppetInternals provides a set of methods that interface
8
+ # with internal puppet implementations.
9
+ module PuppetlabsSpec::PuppetInternals
10
+ def resource(parts = {})
11
+ resource_type = parts[:type] || :hostclass
12
+ resource_name = parts[:name] || 'testing'
13
+ Puppet::Resource::Type.new(resource_type, resource_name)
14
+ end
15
+ module_function :resource
72
16
 
73
- scope.method("function_#{name}".intern)
74
- end
75
- module_function :function_method
17
+ def compiler(parts = {})
18
+ compiler_node = parts[:node] || node
19
+ Puppet::Parser::Compiler.new(compiler_node)
20
+ end
21
+ module_function :compiler
22
+
23
+ def node(parts = {})
24
+ node_name = parts[:name] || 'testinghost'
25
+ options = parts[:options] || {}
26
+ node_environment = Puppet::Node::Environment.create(parts[:environment] || 'test', [])
27
+ options[:environment] = node_environment
28
+ Puppet::Node.new(node_name, options)
29
+ end
30
+ module_function :node
31
+
32
+ # Return a method instance for a given function. This is primarily useful
33
+ # for rspec-puppet
34
+ def function_method(name, parts = {})
35
+ scope = parts[:scope] || scope()
36
+ # Ensure the method instance is defined by side-effect of checking if it
37
+ # exists. This is a hack, but at least it's a hidden hack and not an
38
+ # exposed hack.
39
+ return nil unless Puppet::Parser::Functions.function(name)
40
+
41
+ scope.method("function_#{name}".to_sym)
76
42
  end
43
+ module_function :function_method
77
44
  end
@@ -79,13 +79,11 @@ end
79
79
 
80
80
  desc 'Run spec tests and clean the fixtures directory if successful'
81
81
  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
89
87
  end
90
88
 
91
89
  desc 'Run spec tests with ruby simplecov code coverage'
@@ -98,13 +96,11 @@ end
98
96
 
99
97
  desc 'Run spec tests in parallel and clean the fixtures directory if successful'
100
98
  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
108
104
  end
109
105
 
110
106
  desc 'Parallel spec tests'
@@ -126,39 +122,25 @@ end
126
122
 
127
123
  desc 'Build puppet module package'
128
124
  task :build do
129
- if Gem::Specification.find_by_name('puppet').version < Gem::Version.new('6.0.0')
130
- Rake::Task['build:pmt'].invoke
131
- else
132
- Rake::Task['build:pdk'].invoke
133
- end
125
+ Rake::Task['build:pdk'].invoke
134
126
  end
135
127
 
136
128
  namespace :build do
137
- desc 'Build Puppet module package with PMT (Puppet < 6.0.0 only)'
138
- task :pmt do
139
- require 'puppet/face'
140
-
141
- pmod = Puppet::Face['module', :current]
142
- pmod.build('./')
143
- end
144
-
145
129
  desc 'Build Puppet module with PDK'
146
130
  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')
131
+ require 'pdk/util'
132
+ require 'pdk/module/build'
133
+
134
+ path = PDK::Module::Build.invoke(force: true, 'target-dir': File.join(Dir.pwd, 'pkg'))
135
+ puts "Module built: #{path}"
136
+ rescue LoadError
137
+ _ = `pdk --version`
138
+ unless $CHILD_STATUS.success?
139
+ warn 'Unable to build module. Please install PDK or add the `pdk` gem to your Gemfile.'
140
+ abort
161
141
  end
142
+
143
+ system('pdk build --force')
162
144
  end
163
145
  end
164
146
 
@@ -171,6 +153,7 @@ require 'puppet-lint/tasks/puppet-lint'
171
153
  # Must clear as it will not override the existing puppet-lint rake task since we require to import for
172
154
  # the PuppetLint::RakeTask
173
155
  Rake::Task[:lint].clear
156
+ PuppetLint.configuration.fail_on_warnings = true
174
157
  # Utilize PuppetLint global configuration so that these settings can be tweaked by
175
158
  # spec_helper.rb in an individual module
176
159
  PuppetLint.configuration.relative = true
@@ -182,15 +165,16 @@ PuppetLint.configuration.ignore_paths << 'spec/**/*.pp'
182
165
  PuppetLint.configuration.ignore_paths << 'tests/**/*.pp'
183
166
  PuppetLint.configuration.ignore_paths << 'types/**/*.pp'
184
167
  PuppetLint.configuration.ignore_paths << 'vendor/**/*.pp'
185
- puppet_lint_disable_checks = %w[
186
- 80chars
187
- 140chars
188
- class_inherits_from_params_class
189
- class_parameter_defaults
190
- disable_autoloader_layout
191
- documentation
192
- single_quote_string_with_variables
168
+ puppet_lint_disable_checks = [
169
+ '80chars',
170
+ '140chars',
171
+ 'class_inherits_from_params_class',
172
+ 'class_parameter_defaults',
173
+ 'disable_autoloader_layout',
174
+ 'documentation',
175
+ 'single_quote_string_with_variables',
193
176
  ]
177
+
194
178
  puppet_lint_disable_checks.each do |check|
195
179
  PuppetLint.configuration.send("disable_#{check}")
196
180
  end
@@ -208,10 +192,6 @@ PuppetSyntax.exclude_paths << 'pkg/**/*'
208
192
  PuppetSyntax.exclude_paths << 'vendor/**/*'
209
193
  PuppetSyntax.exclude_paths << '.vendor/**/*'
210
194
  PuppetSyntax.exclude_paths << 'plans/**/*'
211
- if Puppet.version.to_f < 4.0
212
- PuppetSyntax.exclude_paths << 'types/**/*'
213
- end
214
- PuppetSyntax.future_parser = true if ENV['FUTURE_PARSER'] == 'yes'
215
195
 
216
196
  desc 'Check syntax of Ruby files and call :syntax and :metadata_lint'
217
197
  task :validate do
@@ -227,14 +207,13 @@ task :validate do
227
207
  warn 'Skipping metadata validation; the metadata-json-lint gem was not found'
228
208
  end
229
209
  end
230
- end
231
210
 
232
- task :metadata do
233
- warn "The 'metadata' task is deprecated. Please use 'metadata_lint' instead."
234
- if Rake::Task.task_defined?(:metadata_lint)
235
- Rake::Task[:metadata_lint].invoke
236
- else
237
- warn 'Skipping metadata validation; the metadata-json-lint gem was not found'
211
+ if File.exist?('REFERENCE.md')
212
+ if Rake::Task.task_defined?('strings:validate:reference')
213
+ Rake::Task['strings:validate:reference'].invoke
214
+ else
215
+ warn 'Skipping reference documentation validation; the puppet-strings gem was not found'
216
+ end
238
217
  end
239
218
  end
240
219
 
@@ -260,7 +239,7 @@ task :compute_dev_version do
260
239
  # If the branch is a release branch we append an 'r' into the new_version,
261
240
  # this is due to the release branch buildID conflicting with main branch when trying to push to the staging forge.
262
241
  # More info can be found at https://tickets.puppetlabs.com/browse/FM-6170
263
- new_version = if build = (ENV['BUILD_NUMBER'] || ENV['TRAVIS_BUILD_NUMBER'])
242
+ new_version = if (build = ENV['BUILD_NUMBER'])
264
243
  if branch.eql? 'release'
265
244
  '%s-%s%04d-%s' % [version, 'r', build, sha] # legacy support code # rubocop:disable Style/FormatStringToken
266
245
  else
@@ -315,7 +294,9 @@ namespace :check do
315
294
 
316
295
  desc 'Fails if directories contain the files specified in .gitignore'
317
296
  task :git_ignore do
318
- matched = `git ls-files --ignored --exclude-standard`
297
+ matched = `git ls-files --ignored --exclude-standard --cached`
298
+ raise 'git ls-files failed' unless $CHILD_STATUS.success?
299
+
319
300
  unless matched == ''
320
301
  puts matched
321
302
  raise 'File specified in .gitignore has been committed'
@@ -406,7 +387,7 @@ def create_gch_task(changelog_user = nil, changelog_project = nil, changelog_sin
406
387
  },
407
388
  'Added' => {
408
389
  'prefix' => '### Added',
409
- 'labels' => %w[feature enhancement],
390
+ 'labels' => ['feature', 'enhancement'],
410
391
  },
411
392
  'Fixed' => {
412
393
  'prefix' => '### Fixed',
@@ -2,9 +2,7 @@
2
2
 
3
3
  require 'pathspec'
4
4
 
5
- module PuppetlabsSpecHelper; end
6
- module PuppetlabsSpecHelper::Tasks; end
7
-
5
+ # Helpers for validating symlinks.
8
6
  class PuppetlabsSpecHelper::Tasks::CheckSymlinks
9
7
  DEFAULT_IGNORED = [
10
8
  '/.git/',
@@ -4,9 +4,10 @@ require 'yaml'
4
4
  require 'open3'
5
5
  require 'json'
6
6
 
7
- module PuppetlabsSpecHelper; end
8
- module PuppetlabsSpecHelper::Tasks; end
7
+ # Top level namespace for spec helper tasks.
8
+ module PuppetlabsSpecHelper::Tasks end
9
9
 
10
+ # Helpers for workfing with fixtures.
10
11
  module PuppetlabsSpecHelper::Tasks::FixtureHelpers
11
12
  # This is a helper for the self-symlink entry of fixtures.yml
12
13
  def source_dir
@@ -136,6 +137,8 @@ module PuppetlabsSpecHelper::Tasks::FixtureHelpers
136
137
 
137
138
  next unless include_repo?(opts['puppet_version'])
138
139
 
140
+ # rubocop:disable Security/Eval
141
+ # TODO: Remove eval
139
142
  real_target = eval("\"#{opts['target']}\"", binding, __FILE__, __LINE__) # evaluating target reference in this context (see auto_symlink)
140
143
  real_source = eval("\"#{opts['repo']}\"", binding, __FILE__, __LINE__) # evaluating repo reference in this context (see auto_symlink)
141
144
 
@@ -157,7 +160,7 @@ module PuppetlabsSpecHelper::Tasks::FixtureHelpers
157
160
  return hash unless hash['scm'] == 'git'
158
161
 
159
162
  # Forward slashes in the ref aren't allowed. And is probably a branch name.
160
- raise ArgumentError, "The ref for #{hash['target']} is invalid (Contains a forward slash). If this is a branch name, please use the 'branch' setting instead." if hash['ref'] =~ %r{/}
163
+ raise ArgumentError, "The ref for #{hash['target']} is invalid (Contains a forward slash). If this is a branch name, please use the 'branch' setting instead." if hash['ref'].include?('/')
161
164
 
162
165
  hash
163
166
  end
@@ -248,12 +251,11 @@ module PuppetlabsSpecHelper::Tasks::FixtureHelpers
248
251
  end
249
252
 
250
253
  def remove_subdirectory(target, subdir)
251
- unless subdir.nil?
252
- Dir.mktmpdir do |tmpdir|
253
- FileUtils.mv(Dir.glob("#{target}/#{subdir}/{.[^\.]*,*}"), tmpdir)
254
- FileUtils.rm_rf("#{target}/#{subdir}")
255
- FileUtils.mv(Dir.glob("#{tmpdir}/{.[^\.]*,*}"), target.to_s)
256
- end
254
+ return if subdir.nil?
255
+ Dir.mktmpdir do |tmpdir|
256
+ FileUtils.mv(Dir.glob("#{target}/#{subdir}/{.[^\.]*,*}"), tmpdir)
257
+ FileUtils.rm_rf("#{target}/#{subdir}")
258
+ FileUtils.mv(Dir.glob("#{tmpdir}/{.[^\.]*,*}"), target.to_s)
257
259
  end
258
260
  end
259
261
 
@@ -284,7 +286,7 @@ module PuppetlabsSpecHelper::Tasks::FixtureHelpers
284
286
  # so when anything else we count that as a active thread
285
287
  # @return [Integer] - current thread count
286
288
  def current_thread_count(items)
287
- active_threads = items.find_all do |_item, opts|
289
+ active_threads = items.select do |_item, opts|
288
290
  if opts[:thread]
289
291
  opts[:thread].status
290
292
  else
@@ -316,7 +318,7 @@ module PuppetlabsSpecHelper::Tasks::FixtureHelpers
316
318
  end
317
319
  else
318
320
  # the last thread started should be the longest wait
319
- item, item_opts = items.find_all { |_i, o| o.key?(:thread) }.last
321
+ item, item_opts = items.reverse.find { |_i, o| o.key?(:thread) }
320
322
  logger.debug "Waiting on #{item}"
321
323
  item_opts[:thread].join # wait for the thread to finish
322
324
  # now that we waited lets try again
@@ -405,7 +407,7 @@ module PuppetlabsSpecHelper::Tasks::FixtureHelpers
405
407
  end
406
408
  end
407
409
 
408
- include PuppetlabsSpecHelper::Tasks::FixtureHelpers # DSL include # rubocop:disable Style/MixinUsage
410
+ include PuppetlabsSpecHelper::Tasks::FixtureHelpers # DSL include
409
411
 
410
412
  desc 'Create the fixtures directory'
411
413
  task :spec_prep do
@@ -1,10 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PuppetlabsSpecHelper
4
- VERSION = '4.0.1'
5
-
6
- # compat for pre-1.2.0 users; deprecated
7
- module Version
8
- STRING = PuppetlabsSpecHelper::VERSION
9
- end
4
+ VERSION = '5.0.1'
10
5
  end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'puppetlabs_spec_helper/rake_tasks'
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'open3'
5
+
6
+ # some smoke tests to verify overall sanity
7
+ RSpec.describe 'rake' do
8
+ let(:output) do
9
+ Open3.capture2e('rake', '--rakefile', 'spec/acceptance/fixtures/Rakefile', '-T')
10
+ end
11
+
12
+ it { expect(output[0]).to match %r{spec_prep} }
13
+ it { expect(output[1]).to be_success }
14
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ if ENV['COVERAGE'] == 'yes'
4
+ require 'simplecov'
5
+ require 'simplecov-console'
6
+ require 'codecov'
7
+
8
+ SimpleCov.formatters = [
9
+ SimpleCov::Formatter::HTMLFormatter,
10
+ SimpleCov::Formatter::Console,
11
+ SimpleCov::Formatter::Codecov,
12
+ ]
13
+ SimpleCov.start do
14
+ track_files 'lib/**/*.rb'
15
+
16
+ add_filter 'lib/puppetlabs_spec_helper/version.rb'
17
+
18
+ add_filter '/spec'
19
+
20
+ # do not track vendored files
21
+ add_filter '/vendor'
22
+ add_filter '/.vendor'
23
+ end
24
+ end
25
+
26
+ require 'fakefs/spec_helpers'
27
+
28
+ FakeFS::Pathname.class_eval do
29
+ def symlink?
30
+ File.symlink?(@path)
31
+ end
32
+ end
33
+
34
+ require 'puppetlabs_spec_helper/puppet_spec_helper'
35
+ require 'puppetlabs_spec_helper/puppetlabs_spec/puppet_internals'
36
+ require 'puppetlabs_spec_helper/rake_tasks'
37
+
38
+ RSpec.shared_context 'with a rake task', type: :task do
39
+ subject(:task) { Rake::Task[task_name] }
40
+
41
+ include FakeFS::SpecHelpers
42
+
43
+ let(:task_name) { self.class.top_level_description.sub(%r{\Arake }, '') }
44
+ end
45
+
46
+ # configure RSpec after including all the code
47
+ RSpec.configure do |config|
48
+ config.expect_with :rspec do |c|
49
+ c.syntax = :expect
50
+ end
51
+
52
+ config.include_context 'with a rake task', type: :task
53
+ end