puppet-check 2.4.0 → 2.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c5c74c1af6aee54ad5dcfd3eeefa459ed9fd5eaaafdc847f346a8e3674ffb362
4
- data.tar.gz: c11db9238470434a489608d62360d12fe1ff10dda29627a05cdded940785b992
3
+ metadata.gz: a3c5911fe2362e7462d111f97705eea6b60842ce107bb94d35e6f8657cea6812
4
+ data.tar.gz: 52413822ec2375afd5fab3bb933220ad15bbcab285641f6717d94057c7fe0554
5
5
  SHA512:
6
- metadata.gz: 12416f0a0d2d2615c467645cb238e0b14be8f42c9172e5adf7acf3bfbdddbdae1d5b08ccd2a967dcb7b6af41a8149f2e30e22ed5d0db97c5f05e586e384c4a61
7
- data.tar.gz: 053f4f90842f2d71ccbc82a3b05cd5ef1347af5399686fc3ed4a7cbf824baeee63ad412c1d6261f3640929bdcba789db7e2fe46d7f3e529cf3cd6b1c8b9690d8
6
+ metadata.gz: fa0c790ee8186c5d1f2eb7091c78d789c68fef7d16292fe3a70c3d41a41d1eb65c3ece36462578bfe2874bb236316fa9b5737f7316f6902d1017bb15c182cf0a
7
+ data.tar.gz: 87e82df7685a13f4122838b225ef8e44d8de30b9e14f8cbb75577b76074fff5f40ca895c7bef00a7648862abba1edc31d5e237b0cb4ba8e0e5e1eb5aa4486304
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ### 2.5.1
2
+ - Fix explicit `fail_on_warnings` default value assignment.
3
+ - Improve message transformation for Puppet::Face errors and warnings.
4
+ - Improve EYAML certification validation check.
5
+ - Verify that files to be validated are readable by current user.
6
+ - Fix Puppet 5.4-6.4 syntax error output format.
7
+
8
+ ### 2.5.0
9
+ - Minimum Ruby version increased to 3.1.
10
+ - Minimum Puppet-Lint increased to 5.0.
11
+ - Restore ERB validation mock Ruby binding.
12
+ - Update Reek API usage.
13
+ - Ensure `rubocop-rspec` plugin only loaded for spec files.
14
+
1
15
  ### 2.4.0
2
16
  - Minimum Ruby version increased to 3.0.
3
17
  - Fix `rubocop-performance` inclusion warning.
data/README.md CHANGED
@@ -331,6 +331,4 @@ To overcome the lack of convenient portability, you could try spinning up the Va
331
331
  ## Contributing
332
332
  Code should pass all spec tests. New features should involve new spec tests. Adherence to Rubocop and Reek is expected where not overly onerous or where the check is of dubious cost/benefit.
333
333
 
334
- A [Dockerfile](Dockerfile) is provided for easy rake testing. A [Vagrantfile](Vagrantfile) is provided for easy gem building, installation, and post-installation testing.
335
-
336
334
  Please consult the GitHub Project for the current development roadmap.
@@ -33,9 +33,9 @@ class DataParser
33
33
  end
34
34
 
35
35
  # keys exist?
36
- unless File.file?(public) && File.file?(private)
36
+ unless File.readable?(public) && File.readable?(private)
37
37
  PuppetCheck.files[:ignored].concat(files)
38
- return warn 'Specified Public X509 and/or Private RSA PKCS7 certs do not exist. EYAML checks will not be executed.'
38
+ return warn 'Specified Public X509 and/or Private RSA PKCS7 certs do not exist or are not readable. EYAML checks will not be executed.'
39
39
  end
40
40
 
41
41
  # setup decryption
@@ -32,12 +32,12 @@ class PuppetParser
32
32
  new_error = Puppet::Face[:parser, :current].validate(file)
33
33
  # puppet 6.5 output format is now a hash from the face api
34
34
  if Gem::Version.new(Puppet::PUPPETVERSION) >= Gem::Version.new('6.5.0') && new_error != {}
35
- messages.concat(new_error.values.map(&:to_s).map { |error| error.gsub(/ \(file: #{File.absolute_path(file)}(, |\))/, '') }.map { |error| error.gsub('Could not parse for environment *root*: ', '') })
35
+ messages.concat(new_error.values.map(&:to_s).map { |error| error.gsub(Regexp.escape(" (file: #{File.absolute_path(file)}(, |))"), '') }.map { |error| error.gsub('Could not parse for environment *root*: ', '') })
36
36
  end
37
37
  # this is the actual error that we need to rescue Puppet::Face from
38
38
  rescue SystemExit
39
39
  # puppet 5.4-6.4 has a new validator output format and eof errors have fake dir env info
40
- messages.concat(errors.map(&:to_s).join("\n").map { |error| error.gsub(/file: #{File.absolute_path(file)}(, |\))/, '') }.map { |error| error.gsub(/Could not parse.*: /, '') })
40
+ messages.concat(errors.map(&:to_s).map { |error| error.gsub(Regexp.escape("file: #{File.absolute_path(file)}(, |))"), '') }.map { |error| error.gsub(/Could not parse.*: /, '') })
41
41
  end
42
42
 
43
43
  Puppet::Util::Log.close_all
@@ -50,7 +50,7 @@ class PuppetParser
50
50
  # weirdly puppet >= 6.5 still does not return warnings and logs them instead unlike errors
51
51
  unless errors.empty?
52
52
  # puppet >= 5.4 has a new validator output format
53
- warnings.concat(errors.map(&:to_s).join("\n").gsub("file: #{File.absolute_path(file)}, ", '').split("\n"))
53
+ warnings.concat(errors.map(&:to_s).join("\n").gsub(Regexp.escape("file: #{File.absolute_path(file)}(, |))"), '').split("\n"))
54
54
  end
55
55
 
56
56
  # check puppet style
@@ -10,7 +10,6 @@ class RubyParser
10
10
  require 'json'
11
11
  require 'rubocop'
12
12
  require 'reek'
13
- require 'reek/cli/application'
14
13
 
15
14
  rubocop_cli = RuboCop::CLI.new
16
15
  end
@@ -23,13 +22,16 @@ class RubyParser
23
22
  else
24
23
  # check ruby style
25
24
  if style
25
+ # add rubocop rspec plugin if the file is a spec
26
+ rc_args.push('--plugin', 'rubocop-rspec') if file =~ /_spec\.rb$/
27
+
26
28
  # check RuboCop and parse warnings' JSON output
27
- rubocop_warnings = Utils.capture_stdout { rubocop_cli.run(rc_args + ['--enable-pending-cops', '--plugin', 'rubocop-performance', '--plugin', 'rubocop-rspec', '--format', 'json', file]) }
29
+ rubocop_warnings = Utils.capture_stdout { rubocop_cli.run(rc_args + ['--enable-pending-cops', '--plugin', 'rubocop-performance', '--format', 'json', file]) }
28
30
  rubocop_offenses = JSON.parse(rubocop_warnings)['files'][0]['offenses'].map { |warning| "#{warning['location']['line']}:#{warning['location']['column']} #{warning['message']}" }
29
31
 
30
- # check Reek and parse warnings' JSON output
31
- reek_warnings = Utils.capture_stdout { Reek::CLI::Application.new(['-f', 'json', file]).execute }
32
- reek_offenses = JSON.parse(reek_warnings).map { |warning| "#{warning['lines'].join(',')}: #{warning['context']} #{warning['message']}" }
32
+ # check Reek using examiner api
33
+ examiner = Reek::Examiner.new(Pathname.new(file))
34
+ reek_offenses = examiner.smells.map { |warning| "#{warning.lines.join(',')}: #{warning.context} #{warning.message}" }
33
35
 
34
36
  # assign warnings from combined offenses
35
37
  warnings = rubocop_offenses + reek_offenses
@@ -48,10 +50,7 @@ class RubyParser
48
50
  files.each do |file|
49
51
  # check ruby template syntax
50
52
  begin
51
- # need to eventually have this associated with a different binding during each iteration
52
- # older usage throws extra warning and mixes with valid warnings confusingly
53
- warnings = Utils.capture_stderr { ERB.new(File.read(file), trim_mode: '-').result }
54
- # warnings = ERB.new(File.read(file), trim_mode: '-').result(RubyParser.new.bind)
53
+ warnings = Utils.capture_stderr { ERB.new(File.read(file), trim_mode: '-').result(Object.new.instance_eval { binding }) }
55
54
  rescue NameError, TypeError
56
55
  # empty out warnings since it would contain an error if this pass triggers
57
56
  warnings = ''
@@ -79,8 +78,7 @@ class RubyParser
79
78
 
80
79
  files.each do |file|
81
80
  # check librarian puppet syntax
82
- # prevents ruby code from actually executing the input ruby file
83
- catch(:good) { instance_eval("BEGIN {throw :good}; #{File.read(file)} # BEGIN {throw :good}; ruby_file_content", file) }
81
+ RubyVM::InstructionSequence.compile_file(file)
84
82
  rescue SyntaxError, LoadError, ArgumentError => err
85
83
  PuppetCheck.files[:errors][file] = err.to_s.gsub("#{file}:", '').split("\n")
86
84
  # check librarian puppet style
@@ -95,9 +93,4 @@ class RubyParser
95
93
  PuppetCheck.files[:clean].push(file.to_s)
96
94
  end
97
95
  end
98
-
99
- # potentially for unique erb bindings
100
- def bind
101
- binding
102
- end
103
96
  end
data/lib/puppet_check.rb CHANGED
@@ -75,7 +75,7 @@ class PuppetCheck
75
75
  # return settings with defaults where unspecified
76
76
  {
77
77
  # initialize fail on warning, style check, and regression check bools
78
- fail_on_warning: false,
78
+ fail_on_warnings: false,
79
79
  style: false,
80
80
  smoke: false,
81
81
  regression: false,
@@ -101,11 +101,11 @@ class PuppetCheck
101
101
  paths.uniq.each do |path|
102
102
  if File.directory?(path)
103
103
  # glob all files in directory and concat them
104
- files.concat(Dir.glob("#{path}/**/*").select { |subpath| File.file?(subpath) && !subpath.include?('fixtures') })
105
- elsif File.file?(path) && !path.include?('fixtures')
104
+ files.concat(Dir.glob("#{path}/**/*").select { |subpath| File.file?(subpath) && File.readable?(subpath) && !subpath.include?('fixtures') })
105
+ elsif File.file?(path) && File.readable?(path) && !path.include?('fixtures')
106
106
  files.push(path)
107
107
  else
108
- warn "puppet-check: #{path} is not a directory, file, or symlink, and will not be considered during parsing"
108
+ warn "puppet-check: #{path} is not a readable directory, file, or symlink, and will not be considered during parsing"
109
109
  end
110
110
  end
111
111
 
data/puppet-check.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'puppet-check'
3
- spec.version = '2.4.0'
3
+ spec.version = '2.5.1'
4
4
  spec.authors = ['Matt Schuchard']
5
5
  spec.description = 'Puppet Check is a gem that provides a comprehensive, streamlined, and efficient analysis of the syntax, style, and validity of your entire Puppet code and data.'
6
6
  spec.summary = 'A streamlined comprehensive set of checks for your entire Puppet code and data'
@@ -11,9 +11,9 @@ Gem::Specification.new do |spec|
11
11
  spec.executables = spec.files.grep(%r{^bin/}) { |file| File.basename(file) }
12
12
  spec.require_paths = Dir['lib']
13
13
 
14
- spec.required_ruby_version = '>= 3.0.0'
14
+ spec.required_ruby_version = '>= 3.1.0'
15
15
  spec.add_dependency 'puppet', '>= 5.5', '< 9'
16
- spec.add_dependency 'puppet-lint', '~> 4.0'
16
+ spec.add_dependency 'puppet-lint', '~> 5.0'
17
17
  spec.add_dependency 'reek', '~> 6.0'
18
18
  spec.add_dependency 'rubocop', '~> 1.72'
19
19
  spec.add_dependency 'rubocop-performance', '~> 1.0'
@@ -5,8 +5,8 @@ describe PuppetCheck::CLI do
5
5
  context '.run' do
6
6
  it 'targets the current working directory if no paths were specified' do
7
7
  expect { PuppetCheck::CLI.run(%w[--fail-on-warnings]) }.not_to raise_exception
8
- expect(PuppetCheck.files[:clean].length).to eql(30)
9
- if ci_env
8
+ expect(PuppetCheck.files[:clean].length).to eql(29)
9
+ if CI_ENV
10
10
  expect(PuppetCheck.files[:ignored].length).to eql(8)
11
11
  else
12
12
  expect(PuppetCheck.files[:ignored].length).to eql(7)
@@ -40,7 +40,7 @@ describe PuppetCheck::CLI do
40
40
  end
41
41
 
42
42
  it 'correctly loads a .puppet-lint.rc' do
43
- expect(PuppetCheck::CLI.send(:parse, %W[-c #{fixtures_dir}/manifests/.puppet-lint.rc])).to include(puppetlint_args: ['--puppetlint-arg-one', '--puppetlint-arg-two'])
43
+ expect(PuppetCheck::CLI.send(:parse, %W[-c #{FIXTURES_DIR}/manifests/.puppet-lint.rc])).to include(puppetlint_args: ['--puppetlint-arg-one', '--puppetlint-arg-two'])
44
44
  end
45
45
 
46
46
  it 'correctly parses Rubocop arguments' do
@@ -13,24 +13,24 @@ describe DataParser do
13
13
 
14
14
  context '.yaml' do
15
15
  it 'puts a bad syntax yaml file in the error files hash' do
16
- DataParser.yaml(["#{fixtures_dir}hieradata/syntax.yaml"])
17
- expect(PuppetCheck.files[:errors].keys).to eql(["#{fixtures_dir}hieradata/syntax.yaml"])
18
- expect(PuppetCheck.files[:errors]["#{fixtures_dir}hieradata/syntax.yaml"].join("\n")).to match(/^block sequence entries are not allowed/)
16
+ DataParser.yaml(["#{FIXTURES_DIR}hieradata/syntax.yaml"])
17
+ expect(PuppetCheck.files[:errors].keys).to eql(["#{FIXTURES_DIR}hieradata/syntax.yaml"])
18
+ expect(PuppetCheck.files[:errors]["#{FIXTURES_DIR}hieradata/syntax.yaml"].join("\n")).to match(/^block sequence entries are not allowed/)
19
19
  expect(PuppetCheck.files[:warnings]).to eql({})
20
20
  expect(PuppetCheck.files[:clean]).to eql([])
21
21
  end
22
22
  it 'puts a good yaml file with potential hiera issues in the warning files array' do
23
- DataParser.yaml(["#{fixtures_dir}hieradata/style.yaml"])
23
+ DataParser.yaml(["#{FIXTURES_DIR}hieradata/style.yaml"])
24
24
  expect(PuppetCheck.files[:errors]).to eql({})
25
- expect(PuppetCheck.files[:warnings].keys).to eql(["#{fixtures_dir}hieradata/style.yaml"])
26
- expect(PuppetCheck.files[:warnings]["#{fixtures_dir}hieradata/style.yaml"].join("\n")).to match(/^Value\(s\) missing in key.*\nValue\(s\) missing in key.*\nThe string --- appears more than once in this data and Hiera may fail to parse it correctly/)
25
+ expect(PuppetCheck.files[:warnings].keys).to eql(["#{FIXTURES_DIR}hieradata/style.yaml"])
26
+ expect(PuppetCheck.files[:warnings]["#{FIXTURES_DIR}hieradata/style.yaml"].join("\n")).to match(/^Value\(s\) missing in key.*\nValue\(s\) missing in key.*\nThe string --- appears more than once in this data and Hiera may fail to parse it correctly/)
27
27
  expect(PuppetCheck.files[:clean]).to eql([])
28
28
  end
29
29
  it 'puts a good yaml file in the clean files array' do
30
- DataParser.yaml(["#{fixtures_dir}hieradata/good.yaml"])
30
+ DataParser.yaml(["#{FIXTURES_DIR}hieradata/good.yaml"])
31
31
  expect(PuppetCheck.files[:errors]).to eql({})
32
32
  expect(PuppetCheck.files[:warnings]).to eql({})
33
- expect(PuppetCheck.files[:clean]).to eql(["#{fixtures_dir}hieradata/good.yaml"])
33
+ expect(PuppetCheck.files[:clean]).to eql(["#{FIXTURES_DIR}hieradata/good.yaml"])
34
34
  end
35
35
  end
36
36
 
@@ -42,83 +42,83 @@ describe DataParser do
42
42
  expect { DataParser.eyaml(['foo.eyaml'], 'public.pem', nil) }.to output("Public X509 and/or Private RSA PKCS7 certs were not specified. EYAML checks will not be executed.\n").to_stderr
43
43
  end
44
44
  it 'returns a warning if the public key or private key are not existing files' do
45
- expect { DataParser.eyaml(['foo.eyaml'], 'public.pem', 'private.pem') }.to output("Specified Public X509 and/or Private RSA PKCS7 certs do not exist. EYAML checks will not be executed.\n").to_stderr
45
+ expect { DataParser.eyaml(['foo.eyaml'], 'public.pem', 'private.pem') }.to output("Specified Public X509 and/or Private RSA PKCS7 certs do not exist or are not readable. EYAML checks will not be executed.\n").to_stderr
46
46
  end
47
47
  it 'puts a bad syntax eyaml file in the error files hash' do
48
- DataParser.eyaml(["#{fixtures_dir}hieradata/syntax.eyaml"], "#{fixtures_dir}keys/public_key.pkcs7.pem", "#{fixtures_dir}keys/private_key.pkcs7.pem")
49
- expect(PuppetCheck.files[:errors].keys).to eql(["#{fixtures_dir}hieradata/syntax.eyaml"])
50
- expect(PuppetCheck.files[:errors]["#{fixtures_dir}hieradata/syntax.eyaml"].join("\n")).to match(/^block sequence entries are not allowed/)
48
+ DataParser.eyaml(["#{FIXTURES_DIR}hieradata/syntax.eyaml"], "#{FIXTURES_DIR}keys/public_key.pkcs7.pem", "#{FIXTURES_DIR}keys/private_key.pkcs7.pem")
49
+ expect(PuppetCheck.files[:errors].keys).to eql(["#{FIXTURES_DIR}hieradata/syntax.eyaml"])
50
+ expect(PuppetCheck.files[:errors]["#{FIXTURES_DIR}hieradata/syntax.eyaml"].join("\n")).to match(/^block sequence entries are not allowed/)
51
51
  expect(PuppetCheck.files[:warnings]).to eql({})
52
52
  expect(PuppetCheck.files[:clean]).to eql([])
53
53
  end
54
54
  it 'puts a good eyaml file with potential hiera issues in the warning files array' do
55
- DataParser.eyaml(["#{fixtures_dir}hieradata/style.eyaml"], "#{fixtures_dir}keys/public_key.pkcs7.pem", "#{fixtures_dir}keys/private_key.pkcs7.pem")
55
+ DataParser.eyaml(["#{FIXTURES_DIR}hieradata/style.eyaml"], "#{FIXTURES_DIR}keys/public_key.pkcs7.pem", "#{FIXTURES_DIR}keys/private_key.pkcs7.pem")
56
56
  expect(PuppetCheck.files[:errors]).to eql({})
57
- expect(PuppetCheck.files[:warnings].keys).to eql(["#{fixtures_dir}hieradata/style.eyaml"])
58
- expect(PuppetCheck.files[:warnings]["#{fixtures_dir}hieradata/style.eyaml"].join("\n")).to match(/^Value\(s\) missing in key.*\nValue\(s\) missing in key.*\nThe string --- appears more than once in this data and Hiera may fail to parse it correctly/)
57
+ expect(PuppetCheck.files[:warnings].keys).to eql(["#{FIXTURES_DIR}hieradata/style.eyaml"])
58
+ expect(PuppetCheck.files[:warnings]["#{FIXTURES_DIR}hieradata/style.eyaml"].join("\n")).to match(/^Value\(s\) missing in key.*\nValue\(s\) missing in key.*\nThe string --- appears more than once in this data and Hiera may fail to parse it correctly/)
59
59
  expect(PuppetCheck.files[:clean]).to eql([])
60
60
  end
61
61
  it 'puts a good eyaml file in the clean files array' do
62
- DataParser.eyaml(["#{fixtures_dir}hieradata/good.eyaml"], "#{fixtures_dir}keys/public_key.pkcs7.pem", "#{fixtures_dir}keys/private_key.pkcs7.pem")
62
+ DataParser.eyaml(["#{FIXTURES_DIR}hieradata/good.eyaml"], "#{FIXTURES_DIR}keys/public_key.pkcs7.pem", "#{FIXTURES_DIR}keys/private_key.pkcs7.pem")
63
63
  expect(PuppetCheck.files[:errors]).to eql({})
64
64
  expect(PuppetCheck.files[:warnings]).to eql({})
65
- expect(PuppetCheck.files[:clean]).to eql(["#{fixtures_dir}hieradata/good.eyaml"])
65
+ expect(PuppetCheck.files[:clean]).to eql(["#{FIXTURES_DIR}hieradata/good.eyaml"])
66
66
  end
67
67
  end
68
68
 
69
69
  context '.json' do
70
70
  it 'puts a bad syntax json file in the error files hash' do
71
- DataParser.json(["#{fixtures_dir}hieradata/syntax.json"])
72
- expect(PuppetCheck.files[:errors].keys).to eql(["#{fixtures_dir}hieradata/syntax.json"])
73
- expect(PuppetCheck.files[:errors]["#{fixtures_dir}hieradata/syntax.json"].join("\n")).to match(/after object value, got.*at line 2 column 3/)
71
+ DataParser.json(["#{FIXTURES_DIR}hieradata/syntax.json"])
72
+ expect(PuppetCheck.files[:errors].keys).to eql(["#{FIXTURES_DIR}hieradata/syntax.json"])
73
+ expect(PuppetCheck.files[:errors]["#{FIXTURES_DIR}hieradata/syntax.json"].join("\n")).to match(/after object value, got.*at line 2 column 3/)
74
74
  expect(PuppetCheck.files[:warnings]).to eql({})
75
75
  expect(PuppetCheck.files[:clean]).to eql([])
76
76
  end
77
77
  it 'puts a bad metadata json file in the error files hash' do
78
- DataParser.json(["#{fixtures_dir}metadata_syntax/metadata.json"])
79
- expect(PuppetCheck.files[:errors].keys).to eql(["#{fixtures_dir}metadata_syntax/metadata.json"])
80
- expect(PuppetCheck.files[:errors]["#{fixtures_dir}metadata_syntax/metadata.json"].join("\n")).to match(/^Required field.*\nField 'requirements'.*\nDuplicate dependencies.*\nDeprecated field.*\nSummary exceeds/)
78
+ DataParser.json(["#{FIXTURES_DIR}metadata_syntax/metadata.json"])
79
+ expect(PuppetCheck.files[:errors].keys).to eql(["#{FIXTURES_DIR}metadata_syntax/metadata.json"])
80
+ expect(PuppetCheck.files[:errors]["#{FIXTURES_DIR}metadata_syntax/metadata.json"].join("\n")).to match(/^Required field.*\nField 'requirements'.*\nDuplicate dependencies.*\nDeprecated field.*\nSummary exceeds/)
81
81
  expect(PuppetCheck.files[:warnings]).to eql({})
82
82
  expect(PuppetCheck.files[:clean]).to eql([])
83
83
  end
84
84
  it 'puts a bad style metadata json file in the warning files array' do
85
- DataParser.json(["#{fixtures_dir}metadata_style/metadata.json"])
85
+ DataParser.json(["#{FIXTURES_DIR}metadata_style/metadata.json"])
86
86
  expect(PuppetCheck.files[:errors]).to eql({})
87
- expect(PuppetCheck.files[:warnings].keys).to eql(["#{fixtures_dir}metadata_style/metadata.json"])
88
- expect(PuppetCheck.files[:warnings]["#{fixtures_dir}metadata_style/metadata.json"].join("\n")).to match(/^'pe' is missing an upper bound.\n.*operatingsystem_support.*\nLicense identifier/)
87
+ expect(PuppetCheck.files[:warnings].keys).to eql(["#{FIXTURES_DIR}metadata_style/metadata.json"])
88
+ expect(PuppetCheck.files[:warnings]["#{FIXTURES_DIR}metadata_style/metadata.json"].join("\n")).to match(/^'pe' is missing an upper bound.\n.*operatingsystem_support.*\nLicense identifier/)
89
89
  expect(PuppetCheck.files[:clean]).to eql([])
90
90
  end
91
91
  it 'puts another bad style metadata json file in the warning files array' do
92
- DataParser.json(["#{fixtures_dir}metadata_style_two/metadata.json"])
92
+ DataParser.json(["#{FIXTURES_DIR}metadata_style_two/metadata.json"])
93
93
  expect(PuppetCheck.files[:errors]).to eql({})
94
- expect(PuppetCheck.files[:warnings].keys).to eql(["#{fixtures_dir}metadata_style_two/metadata.json"])
95
- expect(PuppetCheck.files[:warnings]["#{fixtures_dir}metadata_style_two/metadata.json"].join("\n")).to match(%r{^'puppetlabs/one' has non-semantic versioning.*\n'puppetlabs/two' is missing an upper bound\.\n.*operatingsystem.*\n.*operatingsystemrelease})
94
+ expect(PuppetCheck.files[:warnings].keys).to eql(["#{FIXTURES_DIR}metadata_style_two/metadata.json"])
95
+ expect(PuppetCheck.files[:warnings]["#{FIXTURES_DIR}metadata_style_two/metadata.json"].join("\n")).to match(%r{^'puppetlabs/one' has non-semantic versioning.*\n'puppetlabs/two' is missing an upper bound\.\n.*operatingsystem.*\n.*operatingsystemrelease})
96
96
  expect(PuppetCheck.files[:clean]).to eql([])
97
97
  end
98
98
  it 'puts a bad task metadata json file in the warning files array' do
99
- DataParser.json(["#{fixtures_dir}task_metadata/task_bad.json"])
99
+ DataParser.json(["#{FIXTURES_DIR}task_metadata/task_bad.json"])
100
100
  expect(PuppetCheck.files[:errors]).to eql({})
101
- expect(PuppetCheck.files[:warnings].keys).to eql(["#{fixtures_dir}task_metadata/task_bad.json"])
102
- expect(PuppetCheck.files[:warnings]["#{fixtures_dir}task_metadata/task_bad.json"].join("\n")).to match(/^description value is not a String\ninput_method value is not one of environment, stdin, or powershell\nparameters value is not a Hash\npuppet_task_version value is not an Integer\nsupports_noop value is not a Boolean/)
101
+ expect(PuppetCheck.files[:warnings].keys).to eql(["#{FIXTURES_DIR}task_metadata/task_bad.json"])
102
+ expect(PuppetCheck.files[:warnings]["#{FIXTURES_DIR}task_metadata/task_bad.json"].join("\n")).to match(/^description value is not a String\ninput_method value is not one of environment, stdin, or powershell\nparameters value is not a Hash\npuppet_task_version value is not an Integer\nsupports_noop value is not a Boolean/)
103
103
  expect(PuppetCheck.files[:clean]).to eql([])
104
104
  end
105
105
  it 'puts a good json file in the clean files array' do
106
- DataParser.json(["#{fixtures_dir}hieradata/good.json"])
106
+ DataParser.json(["#{FIXTURES_DIR}hieradata/good.json"])
107
107
  expect(PuppetCheck.files[:errors]).to eql({})
108
108
  expect(PuppetCheck.files[:warnings]).to eql({})
109
- expect(PuppetCheck.files[:clean]).to eql(["#{fixtures_dir}hieradata/good.json"])
109
+ expect(PuppetCheck.files[:clean]).to eql(["#{FIXTURES_DIR}hieradata/good.json"])
110
110
  end
111
111
  it 'puts a good metadata json file in the clean files array' do
112
- DataParser.json(["#{fixtures_dir}metadata_good/metadata.json"])
112
+ DataParser.json(["#{FIXTURES_DIR}metadata_good/metadata.json"])
113
113
  expect(PuppetCheck.files[:errors]).to eql({})
114
114
  expect(PuppetCheck.files[:warnings]).to eql({})
115
- expect(PuppetCheck.files[:clean]).to eql(["#{fixtures_dir}metadata_good/metadata.json"])
115
+ expect(PuppetCheck.files[:clean]).to eql(["#{FIXTURES_DIR}metadata_good/metadata.json"])
116
116
  end
117
117
  it 'puts a good task metadata json file in the clean files array' do
118
- DataParser.json(["#{fixtures_dir}task_metadata/task_good.json"])
118
+ DataParser.json(["#{FIXTURES_DIR}task_metadata/task_good.json"])
119
119
  expect(PuppetCheck.files[:errors]).to eql({})
120
120
  expect(PuppetCheck.files[:warnings]).to eql({})
121
- expect(PuppetCheck.files[:clean]).to eql(["#{fixtures_dir}task_metadata/task_good.json"])
121
+ expect(PuppetCheck.files[:clean]).to eql(["#{FIXTURES_DIR}task_metadata/task_good.json"])
122
122
  end
123
123
  end
124
124
  end
@@ -13,12 +13,12 @@ describe PuppetParser do
13
13
 
14
14
  context '.manifest' do
15
15
  it 'puts a bad syntax Puppet manifest in the error files hash' do
16
- PuppetParser.manifest(["#{fixtures_dir}manifests/syntax.pp"], false, [])
17
- expect(PuppetCheck.files[:errors].keys).to eql(["#{fixtures_dir}manifests/syntax.pp"])
16
+ PuppetParser.manifest(["#{FIXTURES_DIR}manifests/syntax.pp"], false, [])
17
+ expect(PuppetCheck.files[:errors].keys).to eql(["#{FIXTURES_DIR}manifests/syntax.pp"])
18
18
  if Gem::Version.new(Puppet::PUPPETVERSION) >= Gem::Version.new('6.5.0')
19
- expect(PuppetCheck.files[:errors]["#{fixtures_dir}manifests/syntax.pp"].join("\n")).to match(/^Language validation logged 2 errors/)
19
+ expect(PuppetCheck.files[:errors]["#{FIXTURES_DIR}manifests/syntax.pp"].join("\n")).to match(/^Language validation logged 2 errors/)
20
20
  else
21
- expect(PuppetCheck.files[:errors]["#{fixtures_dir}hieradata/syntax.yaml"].join("\n")).to match(/^This Variable has no effect.*\nIllegal variable name/)
21
+ expect(PuppetCheck.files[:errors]["#{FIXTURES_DIR}manifests/syntax.pp"].join("\n")).to match(/^This Variable has no effect.*\nIllegal variable name/)
22
22
  end
23
23
  expect(PuppetCheck.files[:warnings]).to eql({})
24
24
  expect(PuppetCheck.files[:clean]).to eql([])
@@ -26,77 +26,77 @@ describe PuppetParser do
26
26
  # puppet 5 api has output issues for this fixture
27
27
  unless Gem::Version.new(Puppet::PUPPETVERSION) < Gem::Version.new('6.0.0')
28
28
  it 'puts a bad syntax at eof Puppet manifest in the error files hash' do
29
- PuppetParser.manifest(["#{fixtures_dir}manifests/eof_syntax.pp"], false, [])
30
- expect(PuppetCheck.files[:errors].keys).to eql(["#{fixtures_dir}manifests/eof_syntax.pp"])
31
- expect(PuppetCheck.files[:errors]["#{fixtures_dir}manifests/eof_syntax.pp"].join("\n")).to match(/^Syntax error at end of input/)
29
+ PuppetParser.manifest(["#{FIXTURES_DIR}manifests/eof_syntax.pp"], false, [])
30
+ expect(PuppetCheck.files[:errors].keys).to eql(["#{FIXTURES_DIR}manifests/eof_syntax.pp"])
31
+ expect(PuppetCheck.files[:errors]["#{FIXTURES_DIR}manifests/eof_syntax.pp"].join("\n")).to match(/^Syntax error at end of input/)
32
32
  expect(PuppetCheck.files[:warnings]).to eql({})
33
33
  expect(PuppetCheck.files[:clean]).to eql([])
34
34
  end
35
35
  end
36
36
  it 'puts a bad syntax Puppet plan in the error files hash' do
37
- PuppetParser.manifest(["#{fixtures_dir}plans/syntax.pp"], false, [])
38
- expect(PuppetCheck.files[:errors].keys).to eql(["#{fixtures_dir}plans/syntax.pp"])
39
- expect(PuppetCheck.files[:errors]["#{fixtures_dir}plans/syntax.pp"].join("\n")).to match(/^Syntax error at '\)'/)
37
+ PuppetParser.manifest(["#{FIXTURES_DIR}plans/syntax.pp"], false, [])
38
+ expect(PuppetCheck.files[:errors].keys).to eql(["#{FIXTURES_DIR}plans/syntax.pp"])
39
+ expect(PuppetCheck.files[:errors]["#{FIXTURES_DIR}plans/syntax.pp"].join("\n")).to match(/^Syntax error at '\)'/)
40
40
  expect(PuppetCheck.files[:warnings]).to eql({})
41
41
  expect(PuppetCheck.files[:clean]).to eql([])
42
42
  end
43
43
  it 'puts a bad parser style and lint style Puppet manifest in the warning files array' do
44
- PuppetParser.manifest(["#{fixtures_dir}manifests/style_parser.pp"], true, [])
44
+ PuppetParser.manifest(["#{FIXTURES_DIR}manifests/style_parser.pp"], true, [])
45
45
  expect(PuppetCheck.files[:errors]).to eql({})
46
- expect(PuppetCheck.files[:warnings].keys).to eql(["#{fixtures_dir}manifests/style_parser.pp"])
47
- expect(PuppetCheck.files[:warnings]["#{fixtures_dir}manifests/style_parser.pp"].join("\n")).to match(/^Unrecognized escape sequence.*\nUnrecognized escape sequence.*\n.*double quoted string containing/)
46
+ expect(PuppetCheck.files[:warnings].keys).to eql(["#{FIXTURES_DIR}manifests/style_parser.pp"])
47
+ expect(PuppetCheck.files[:warnings]["#{FIXTURES_DIR}manifests/style_parser.pp"].join("\n")).to match(/^Unrecognized escape sequence.*\nUnrecognized escape sequence.*\n.*double quoted string containing/)
48
48
  expect(PuppetCheck.files[:clean]).to eql([])
49
49
  end
50
50
  it 'puts a bad lint style Puppet manifest in the warning files array' do
51
- PuppetParser.manifest(["#{fixtures_dir}manifests/style_lint.pp"], true, [])
51
+ PuppetParser.manifest(["#{FIXTURES_DIR}manifests/style_lint.pp"], true, [])
52
52
  expect(PuppetCheck.files[:errors]).to eql({})
53
- expect(PuppetCheck.files[:warnings].keys).to eql(["#{fixtures_dir}manifests/style_lint.pp"])
54
- expect(PuppetCheck.files[:warnings]["#{fixtures_dir}manifests/style_lint.pp"].join("\n")).to match(/(?:indentation of|double quoted string containing).*\n.*(?:indentation of|double quoted string containing)/)
53
+ expect(PuppetCheck.files[:warnings].keys).to eql(["#{FIXTURES_DIR}manifests/style_lint.pp"])
54
+ expect(PuppetCheck.files[:warnings]["#{FIXTURES_DIR}manifests/style_lint.pp"].join("\n")).to match(/(?:indentation of|double quoted string containing).*\n.*(?:indentation of|double quoted string containing)/)
55
55
  expect(PuppetCheck.files[:clean]).to eql([])
56
56
  end
57
57
  it 'puts a bad style Puppet manifest in the clean files array when puppetlint_args ignores its warnings' do
58
- PuppetParser.manifest(["#{fixtures_dir}manifests/style_lint.pp"], true, ['--no-double_quoted_strings-check', '--no-arrow_alignment-check'])
58
+ PuppetParser.manifest(["#{FIXTURES_DIR}manifests/style_lint.pp"], true, ['--no-double_quoted_strings-check', '--no-arrow_alignment-check'])
59
59
  expect(PuppetCheck.files[:errors]).to eql({})
60
60
  expect(PuppetCheck.files[:warnings]).to eql({})
61
- expect(PuppetCheck.files[:clean]).to eql(["#{fixtures_dir}manifests/style_lint.pp"])
61
+ expect(PuppetCheck.files[:clean]).to eql(["#{FIXTURES_DIR}manifests/style_lint.pp"])
62
62
  end
63
63
  it 'puts a bad style Puppet plan in the warning files array' do
64
- PuppetParser.manifest(["#{fixtures_dir}plans/style.pp"], true, [])
64
+ PuppetParser.manifest(["#{FIXTURES_DIR}plans/style.pp"], true, [])
65
65
  expect(PuppetCheck.files[:errors]).to eql({})
66
- expect(PuppetCheck.files[:warnings].keys).to eql(["#{fixtures_dir}plans/style.pp"])
67
- expect(PuppetCheck.files[:warnings]["#{fixtures_dir}plans/style.pp"].join("\n")).to match(/variable not enclosed in {}/)
66
+ expect(PuppetCheck.files[:warnings].keys).to eql(["#{FIXTURES_DIR}plans/style.pp"])
67
+ expect(PuppetCheck.files[:warnings]["#{FIXTURES_DIR}plans/style.pp"].join("\n")).to match(/variable not enclosed in {}/)
68
68
  expect(PuppetCheck.files[:clean]).to eql([])
69
69
  end
70
70
  it 'puts a good Puppet manifest in the clean files array' do
71
- PuppetParser.manifest(["#{fixtures_dir}manifests/good.pp"], true, [])
71
+ PuppetParser.manifest(["#{FIXTURES_DIR}manifests/good.pp"], true, [])
72
72
  expect(PuppetCheck.files[:errors]).to eql({})
73
73
  expect(PuppetCheck.files[:warnings]).to eql({})
74
- expect(PuppetCheck.files[:clean]).to eql(["#{fixtures_dir}manifests/good.pp"])
74
+ expect(PuppetCheck.files[:clean]).to eql(["#{FIXTURES_DIR}manifests/good.pp"])
75
75
  end
76
76
  it 'puts a good Puppet plan in the clean files array' do
77
- PuppetParser.manifest(["#{fixtures_dir}plans/good.pp"], true, [])
77
+ PuppetParser.manifest(["#{FIXTURES_DIR}plans/good.pp"], true, [])
78
78
  expect(PuppetCheck.files[:errors]).to eql({})
79
79
  expect(PuppetCheck.files[:warnings]).to eql({})
80
- expect(PuppetCheck.files[:clean]).to eql(["#{fixtures_dir}plans/good.pp"])
80
+ expect(PuppetCheck.files[:clean]).to eql(["#{FIXTURES_DIR}plans/good.pp"])
81
81
  end
82
82
  it 'throws a well specified error for an invalid PuppetLint argument' do
83
- expect { PuppetParser.manifest(["#{fixtures_dir}manifests/style_lint.pp"], true, ['--non-existent', '--does-not-exist']) }.to raise_error(RuntimeError, 'puppet-lint: invalid option supplied among --non-existent --does-not-exist')
83
+ expect { PuppetParser.manifest(["#{FIXTURES_DIR}manifests/style_lint.pp"], true, ['--non-existent', '--does-not-exist']) }.to raise_error(RuntimeError, 'puppet-lint: invalid option supplied among --non-existent --does-not-exist')
84
84
  end
85
85
  end
86
86
 
87
87
  context '.template' do
88
88
  it 'puts a bad syntax Puppet template in the error files hash' do
89
- PuppetParser.template(["#{fixtures_dir}templates/syntax.epp"])
90
- expect(PuppetCheck.files[:errors].keys).to eql(["#{fixtures_dir}templates/syntax.epp"])
91
- expect(PuppetCheck.files[:errors]["#{fixtures_dir}templates/syntax.epp"].join("\n")).to match(/^This Name has no effect/)
89
+ PuppetParser.template(["#{FIXTURES_DIR}templates/syntax.epp"])
90
+ expect(PuppetCheck.files[:errors].keys).to eql(["#{FIXTURES_DIR}templates/syntax.epp"])
91
+ expect(PuppetCheck.files[:errors]["#{FIXTURES_DIR}templates/syntax.epp"].join("\n")).to match(/^This Name has no effect/)
92
92
  expect(PuppetCheck.files[:warnings]).to eql({})
93
93
  expect(PuppetCheck.files[:clean]).to eql([])
94
94
  end
95
95
  it 'puts a good Puppet template in the clean files array' do
96
- PuppetParser.template(["#{fixtures_dir}templates/good.epp"])
96
+ PuppetParser.template(["#{FIXTURES_DIR}templates/good.epp"])
97
97
  expect(PuppetCheck.files[:errors]).to eql({})
98
98
  expect(PuppetCheck.files[:warnings]).to eql({})
99
- expect(PuppetCheck.files[:clean]).to eql(["#{fixtures_dir}templates/good.epp"])
99
+ expect(PuppetCheck.files[:clean]).to eql(["#{FIXTURES_DIR}templates/good.epp"])
100
100
  end
101
101
  end
102
102
  end
@@ -7,10 +7,10 @@ begin
7
7
  context '.config' do
8
8
  # json gem is messed up for the EOL Ruby versions
9
9
  it 'raise an appropriate error if the file is malformed' do
10
- expect { RegressionCheck.send(:config, "#{fixtures_dir}metadata.json") }.to raise_error(OctocatalogDiff::Errors::ConfigurationFileContentError, 'Configuration must define OctocatalogDiff::Config!')
10
+ expect { RegressionCheck.send(:config, "#{FIXTURES_DIR}metadata.json") }.to raise_error(OctocatalogDiff::Errors::ConfigurationFileContentError, 'Configuration must define OctocatalogDiff::Config!')
11
11
  end
12
12
  it 'loads in a good octocatalog-diff config file' do
13
- expect { RegressionCheck.send(:config, "#{octocatalog_diff_dir}octocatalog_diff.cfg.rb") }.not_to raise_exception
13
+ expect { RegressionCheck.send(:config, "#{OCTOCATALOG_DIFF_DIR}octocatalog_diff.cfg.rb") }.not_to raise_exception
14
14
  end
15
15
  it 'loads in the settings from the file correctly' do
16
16
  # TODO
@@ -19,16 +19,16 @@ begin
19
19
 
20
20
  context '.smoke' do
21
21
  # octocatalog-diff is returning a blank error for these tests
22
- unless ci_env
22
+ unless CI_ENV
23
23
  it 'returns a pass for a successful catalog compilation' do
24
- expect { RegressionCheck.smoke(['good.example.com'], "#{octocatalog_diff_dir}octocatalog_diff.cfg.rb") }.not_to raise_exception
24
+ expect { RegressionCheck.smoke(['good.example.com'], "#{OCTOCATALOG_DIFF_DIR}octocatalog_diff.cfg.rb") }.not_to raise_exception
25
25
  end
26
26
  it 'returns a failure for a catalog with an error' do
27
- expect { RegressionCheck.smoke(['does_not_exist.example.com'], "#{octocatalog_diff_dir}octocatalog_diff.cfg.rb") }.to raise_error(OctocatalogDiff::Errors::CatalogError)
27
+ expect { RegressionCheck.smoke(['does_not_exist.example.com'], "#{OCTOCATALOG_DIFF_DIR}octocatalog_diff.cfg.rb") }.to raise_error(OctocatalogDiff::Errors::CatalogError)
28
28
  end
29
29
  end
30
30
  it 'returns a failure for a good and bad catalog' do
31
- # RegressionCheck.smoke(['good.example.com', 'syntax_error.example.com'], "#{fixtures_dir}octocatalog_diff.cfg.rb")
31
+ # RegressionCheck.smoke(['good.example.com', 'syntax_error.example.com'], "#{FIXTURES_DIR}octocatalog_diff.cfg.rb")
32
32
  end
33
33
  end
34
34
 
@@ -5,17 +5,17 @@ require 'fileutils'
5
5
  describe RSpecPuppetSupport do
6
6
  after(:all) do
7
7
  # cleanup rspec_puppet_setup
8
- File.delete("#{fixtures_dir}/spec/spec_helper.rb")
9
- %w[manifests modules].each { |dir| FileUtils.rm_r("#{fixtures_dir}/spec/fixtures/#{dir}") }
8
+ File.delete("#{FIXTURES_DIR}/spec/spec_helper.rb")
9
+ %w[manifests modules].each { |dir| FileUtils.rm_r("#{FIXTURES_DIR}/spec/fixtures/#{dir}") }
10
10
  end
11
11
 
12
12
  context '.run' do
13
13
  let(:rspec_puppet_setup) { RSpecPuppetSupport.run }
14
- before(:each) { Dir.chdir(fixtures_dir) }
14
+ before(:each) { Dir.chdir(FIXTURES_DIR) }
15
15
 
16
16
  it 'creates missing directories, missing site.pp, missing symlinks, and a missing spec_helper' do
17
17
  # circle ci and gh actions
18
- if ci_env
18
+ if CI_ENV
19
19
  expect { rspec_puppet_setup }.to output("git is not installed and cannot be used to retrieve dependency modules\nsubversion is not installed and cannot be used to retrieve dependency modules\npuppetlabs/gruntmaster has an unspecified, or specified but unsupported, download method.\n").to_stderr
20
20
  else
21
21
  expect { rspec_puppet_setup }.to output("subversion is not installed and cannot be used to retrieve dependency modules\npuppetlabs/gruntmaster has an unspecified, or specified but unsupported, download method.\n").to_stderr
@@ -29,7 +29,7 @@ describe RSpecPuppetSupport do
29
29
  expect(File.file?('spec/spec_helper.rb')).to be true
30
30
 
31
31
  # .dependency_setup
32
- expect(File.directory?('spec/fixtures/modules/puppetlabs-lvm')).to be true unless ci_env
32
+ expect(File.directory?('spec/fixtures/modules/puppetlabs-lvm')).to be true unless CI_ENV
33
33
  expect(File.directory?('spec/fixtures/modules/stdlib')).to be true
34
34
  end
35
35
  end
@@ -13,96 +13,96 @@ describe RubyParser do
13
13
 
14
14
  context '.ruby' do
15
15
  it 'puts a bad syntax ruby file in the error files hash' do
16
- RubyParser.ruby(["#{fixtures_dir}lib/syntax.rb"], false, [])
17
- expect(PuppetCheck.files[:errors].keys).to eql(["#{fixtures_dir}lib/syntax.rb"])
18
- expect(PuppetCheck.files[:errors]["#{fixtures_dir}lib/syntax.rb"].join("\n")).to match(/^.*syntax error/)
16
+ RubyParser.ruby(["#{FIXTURES_DIR}lib/syntax.rb"], false, [])
17
+ expect(PuppetCheck.files[:errors].keys).to eql(["#{FIXTURES_DIR}lib/syntax.rb"])
18
+ expect(PuppetCheck.files[:errors]["#{FIXTURES_DIR}lib/syntax.rb"].join("\n")).to match(/^.*syntax error/)
19
19
  expect(PuppetCheck.files[:warnings]).to eql({})
20
20
  expect(PuppetCheck.files[:clean]).to eql([])
21
21
  end
22
22
  it 'puts a bad style ruby file in the warning files array' do
23
- RubyParser.ruby(["#{fixtures_dir}lib/style.rb"], true, [])
23
+ RubyParser.ruby(["#{FIXTURES_DIR}lib/style.rb"], true, [])
24
24
  expect(PuppetCheck.files[:errors]).to eql({})
25
- expect(PuppetCheck.files[:warnings].keys).to eql(["#{fixtures_dir}lib/style.rb"])
26
- unless ci_env
27
- expect(PuppetCheck.files[:warnings]["#{fixtures_dir}lib/style.rb"].join("\n")).to match(/Useless assignment.*\n.*Use the new.*\n.*Do not introduce.*\n.*Prefer single.*\n.*Remove unnecessary empty.*\n.*Source code comment is empty.*\n.*is a writable attribute.*\n.*Issue has no descriptive comment/)
25
+ expect(PuppetCheck.files[:warnings].keys).to eql(["#{FIXTURES_DIR}lib/style.rb"])
26
+ unless CI_ENV
27
+ expect(PuppetCheck.files[:warnings]["#{FIXTURES_DIR}lib/style.rb"].length).to eql(8)
28
28
  else
29
- expect(PuppetCheck.files[:warnings]["#{fixtures_dir}lib/style.rb"].join("\n")).to match(/Useless assignment.*\n.*Use the new.*\n.*Do not introduce.*\n.*Prefer single.*\n.*Remove unnecessary empty.*\n.*Source code comment is empty/)
29
+ expect(PuppetCheck.files[:warnings]["#{FIXTURES_DIR}lib/style.rb"].join("\n")).to match(/Useless assignment.*\n.*Use the new.*\n.*Do not introduce.*\n.*Prefer single.*\n.*Remove unnecessary empty.*\n.*Source code comment is empty/)
30
30
  end
31
31
  expect(PuppetCheck.files[:clean]).to eql([])
32
32
  end
33
33
  it 'puts a bad style ruby file in the clean files array when rubocop_args ignores its warnings' do
34
- RubyParser.ruby(["#{fixtures_dir}lib/rubocop_style.rb"], true, ['--except', 'Lint/UselessAssignment,Style/HashSyntax,Style/GlobalVars,Style/StringLiterals'])
34
+ RubyParser.ruby(["#{FIXTURES_DIR}lib/rubocop_style.rb"], true, ['--except', 'Lint/UselessAssignment,Style/HashSyntax,Style/GlobalVars,Style/StringLiterals'])
35
35
  expect(PuppetCheck.files[:errors]).to eql({})
36
36
  expect(PuppetCheck.files[:warnings]).to eql({})
37
- expect(PuppetCheck.files[:clean]).to eql(["#{fixtures_dir}lib/rubocop_style.rb"])
37
+ expect(PuppetCheck.files[:clean]).to eql(["#{FIXTURES_DIR}lib/rubocop_style.rb"])
38
38
  end
39
39
  it 'puts a good ruby file in the clean files array' do
40
- RubyParser.ruby(["#{fixtures_dir}lib/good.rb"], true, [])
40
+ RubyParser.ruby(["#{FIXTURES_DIR}lib/good.rb"], true, [])
41
41
  expect(PuppetCheck.files[:errors]).to eql({})
42
42
  expect(PuppetCheck.files[:warnings]).to eql({})
43
- expect(PuppetCheck.files[:clean]).to eql(["#{fixtures_dir}lib/good.rb"])
43
+ expect(PuppetCheck.files[:clean]).to eql(["#{FIXTURES_DIR}lib/good.rb"])
44
44
  end
45
45
  end
46
46
 
47
47
  context '.template' do
48
48
  it 'puts a bad syntax ruby template file in the error files hash' do
49
- RubyParser.template(["#{fixtures_dir}templates/syntax.erb"])
50
- expect(PuppetCheck.files[:errors].keys).to eql(["#{fixtures_dir}templates/syntax.erb"])
49
+ RubyParser.template(["#{FIXTURES_DIR}templates/syntax.erb"])
50
+ expect(PuppetCheck.files[:errors].keys).to eql(["#{FIXTURES_DIR}templates/syntax.erb"])
51
51
  if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7')
52
- expect(PuppetCheck.files[:errors]["#{fixtures_dir}templates/syntax.erb"].join("\n")).to match(/1: syntax error, unexpected.*\n.*ruby/)
52
+ expect(PuppetCheck.files[:errors]["#{FIXTURES_DIR}templates/syntax.erb"].join("\n")).to match(/1: syntax error, unexpected.*\n.*ruby/)
53
53
  else
54
- expect(PuppetCheck.files[:errors]["#{fixtures_dir}templates/syntax.erb"].join("\n")).to match(/syntax error, unexpected tIDENTIFIER/)
54
+ expect(PuppetCheck.files[:errors]["#{FIXTURES_DIR}templates/syntax.erb"].join("\n")).to match(/syntax error, unexpected tIDENTIFIER/)
55
55
  end
56
56
  expect(PuppetCheck.files[:warnings]).to eql({})
57
57
  expect(PuppetCheck.files[:clean]).to eql([])
58
58
  end
59
59
  it 'puts a bad style ruby template file in the warning files array' do
60
- RubyParser.template(["#{fixtures_dir}templates/style.erb"])
60
+ RubyParser.template(["#{FIXTURES_DIR}templates/style.erb"])
61
61
  expect(PuppetCheck.files[:errors]).to eql({})
62
- expect(PuppetCheck.files[:warnings].keys).to eql(["#{fixtures_dir}templates/style.erb"])
63
- expect(PuppetCheck.files[:warnings]["#{fixtures_dir}templates/style.erb"].join("\n")).to match(/already initialized constant.*\n.*previous definition of/)
62
+ expect(PuppetCheck.files[:warnings].keys).to eql(["#{FIXTURES_DIR}templates/style.erb"])
63
+ expect(PuppetCheck.files[:warnings]["#{FIXTURES_DIR}templates/style.erb"].join("\n")).to match(/already initialized constant.*\n.*previous definition of/)
64
64
  expect(PuppetCheck.files[:clean]).to eql([])
65
65
  end
66
66
  it 'puts a ruby template file with ignored errors in the clean files array' do
67
- RubyParser.template(["#{fixtures_dir}templates/no_method_error.erb"])
67
+ RubyParser.template(["#{FIXTURES_DIR}templates/no_method_error.erb"])
68
68
  expect(PuppetCheck.files[:errors]).to eql({})
69
69
  expect(PuppetCheck.files[:warnings]).to eql({})
70
- expect(PuppetCheck.files[:clean]).to eql(["#{fixtures_dir}templates/no_method_error.erb"])
70
+ expect(PuppetCheck.files[:clean]).to eql(["#{FIXTURES_DIR}templates/no_method_error.erb"])
71
71
  end
72
72
  it 'puts a good ruby template file in the clean files array' do
73
- RubyParser.template(["#{fixtures_dir}templates/good.erb"])
73
+ RubyParser.template(["#{FIXTURES_DIR}templates/good.erb"])
74
74
  expect(PuppetCheck.files[:errors]).to eql({})
75
75
  expect(PuppetCheck.files[:warnings]).to eql({})
76
- expect(PuppetCheck.files[:clean]).to eql(["#{fixtures_dir}templates/good.erb"])
76
+ expect(PuppetCheck.files[:clean]).to eql(["#{FIXTURES_DIR}templates/good.erb"])
77
77
  end
78
78
  end
79
79
 
80
80
  context '.librarian' do
81
81
  it 'puts a bad syntax librarian Puppet file in the error files hash' do
82
- RubyParser.librarian(["#{fixtures_dir}librarian/Puppetfile_syntax"], false, [])
83
- expect(PuppetCheck.files[:errors].keys).to eql(["#{fixtures_dir}librarian/Puppetfile_syntax"])
84
- expect(PuppetCheck.files[:errors]["#{fixtures_dir}librarian/Puppetfile_syntax"].join("\n")).to match(/^.*syntax error/)
82
+ RubyParser.librarian(["#{FIXTURES_DIR}librarian/Puppetfile_syntax"], false, [])
83
+ expect(PuppetCheck.files[:errors].keys).to eql(["#{FIXTURES_DIR}librarian/Puppetfile_syntax"])
84
+ expect(PuppetCheck.files[:errors]["#{FIXTURES_DIR}librarian/Puppetfile_syntax"].join("\n")).to match(/^.*syntax error/)
85
85
  expect(PuppetCheck.files[:warnings]).to eql({})
86
86
  expect(PuppetCheck.files[:clean]).to eql([])
87
87
  end
88
88
  it 'puts a bad style librarian Puppet file in the warning files array' do
89
- RubyParser.librarian(["#{fixtures_dir}librarian/Puppetfile_style"], true, [])
89
+ RubyParser.librarian(["#{FIXTURES_DIR}librarian/Puppetfile_style"], true, [])
90
90
  expect(PuppetCheck.files[:errors]).to eql({})
91
- expect(PuppetCheck.files[:warnings].keys).to eql(["#{fixtures_dir}librarian/Puppetfile_style"])
92
- expect(PuppetCheck.files[:warnings]["#{fixtures_dir}librarian/Puppetfile_style"].join("\n")).to match(/Align the arguments.*\n.*Use the new/)
91
+ expect(PuppetCheck.files[:warnings].keys).to eql(["#{FIXTURES_DIR}librarian/Puppetfile_style"])
92
+ expect(PuppetCheck.files[:warnings]["#{FIXTURES_DIR}librarian/Puppetfile_style"].join("\n")).to match(/Align the arguments.*\n.*Use the new/)
93
93
  expect(PuppetCheck.files[:clean]).to eql([])
94
94
  end
95
95
  it 'puts a bad style librarian Puppet file in the clean files array when rubocop_args ignores its warnings' do
96
- RubyParser.librarian(["#{fixtures_dir}librarian/Puppetfile_style"], true, ['--except', 'Layout/ArgumentAlignment,Style/HashSyntax'])
96
+ RubyParser.librarian(["#{FIXTURES_DIR}librarian/Puppetfile_style"], true, ['--except', 'Layout/ArgumentAlignment,Style/HashSyntax'])
97
97
  expect(PuppetCheck.files[:errors]).to eql({})
98
98
  expect(PuppetCheck.files[:warnings]).to eql({})
99
- expect(PuppetCheck.files[:clean]).to eql(["#{fixtures_dir}librarian/Puppetfile_style"])
99
+ expect(PuppetCheck.files[:clean]).to eql(["#{FIXTURES_DIR}librarian/Puppetfile_style"])
100
100
  end
101
101
  it 'puts a good librarian Puppet file in the clean files array' do
102
- RubyParser.librarian(["#{fixtures_dir}librarian/Puppetfile_good"], true, [])
102
+ RubyParser.librarian(["#{FIXTURES_DIR}librarian/Puppetfile_good"], true, [])
103
103
  expect(PuppetCheck.files[:errors]).to eql({})
104
104
  expect(PuppetCheck.files[:warnings]).to eql({})
105
- expect(PuppetCheck.files[:clean]).to eql(["#{fixtures_dir}librarian/Puppetfile_good"])
105
+ expect(PuppetCheck.files[:clean]).to eql(["#{FIXTURES_DIR}librarian/Puppetfile_good"])
106
106
  end
107
107
  end
108
108
  end
@@ -5,15 +5,15 @@ require_relative '../../lib/puppet-check/tasks'
5
5
  describe PuppetCheck::Tasks do
6
6
  after(:all) do
7
7
  # cleanup rspec_puppet_setup
8
- File.delete("#{fixtures_dir}/spec/spec_helper.rb")
9
- %w[manifests modules].each { |dir| FileUtils.rm_r("#{fixtures_dir}/spec/fixtures/#{dir}") }
8
+ File.delete("#{FIXTURES_DIR}/spec/spec_helper.rb")
9
+ %w[manifests modules].each { |dir| FileUtils.rm_r("#{FIXTURES_DIR}/spec/fixtures/#{dir}") }
10
10
  end
11
11
 
12
12
  context 'puppetcheck:spec' do
13
13
  let(:spec_tasks) { Rake::Task[:'puppetcheck:spec'].invoke }
14
14
 
15
15
  it 'executes RSpec and RSpec-Puppet checks in the expected manner' do
16
- Dir.chdir(fixtures_dir)
16
+ Dir.chdir(FIXTURES_DIR)
17
17
 
18
18
  # rspec task executed
19
19
  expect { spec_tasks }.to output(%r{spec/facter/facter_spec.rb}).to_stdout
@@ -35,7 +35,7 @@ describe PuppetCheck do
35
35
  it 'returns defaults correctly' do
36
36
  expect(PuppetCheck.send(:defaults)).to eql(
37
37
  {
38
- fail_on_warning: false,
38
+ fail_on_warnings: false,
39
39
  style: false,
40
40
  smoke: false,
41
41
  regression: false,
@@ -52,7 +52,7 @@ describe PuppetCheck do
52
52
 
53
53
  it 'modifies settings correctly' do
54
54
  settings = {
55
- fail_on_warning: true,
55
+ fail_on_warnings: true,
56
56
  style: true,
57
57
  smoke: true,
58
58
  regression: true,
@@ -69,9 +69,10 @@ describe PuppetCheck do
69
69
  end
70
70
 
71
71
  context '.parse_paths' do
72
- before(:each) { Dir.chdir(fixtures_dir) }
72
+ before(:each) { Dir.chdir(FIXTURES_DIR) }
73
73
 
74
74
  let(:no_files) { PuppetCheck.send(:parse_paths, %w[foo bar baz]) }
75
+ let(:mixed_files) { PuppetCheck.send(:parse_paths, %w[foo lib/good.rb]) }
75
76
  let(:file) { PuppetCheck.send(:parse_paths, ['lib/good.rb']) }
76
77
  let(:dir) { PuppetCheck.send(:parse_paths, ['.']) }
77
78
  let(:multi_dir) { PuppetCheck.send(:parse_paths, %w[hieradata lib manifests]) }
@@ -81,13 +82,18 @@ describe PuppetCheck do
81
82
  expect { no_files }.to raise_error(RuntimeError, 'puppet-check: no files found in supplied paths \'foo, bar, baz\'.')
82
83
  end
83
84
 
85
+ it 'warns on invalid path and correctly parses a valid file path' do
86
+ expect { mixed_files }.to output("puppet-check: foo is not a readable directory, file, or symlink, and will not be considered during parsing\n").to_stderr
87
+ expect(mixed_files[0]).to eql('lib/good.rb')
88
+ end
89
+
84
90
  it 'correctly parses one file and returns it' do
85
91
  expect(file[0]).to eql('lib/good.rb')
86
92
  end
87
93
 
88
94
  it 'correctly parses one directory and returns all of its files' do
89
95
  dir.each { |file| expect(File.file?(file)).to be true }
90
- if ci_env
96
+ if CI_ENV
91
97
  expect(dir.length).to eql(37)
92
98
  else
93
99
  expect(dir.length).to eql(40)
data/spec/spec_helper.rb CHANGED
@@ -1,23 +1,10 @@
1
1
  require 'rspec'
2
2
 
3
3
  # for path to fixtures
4
- module Variables
5
- extend RSpec::SharedContext
6
-
7
- def fixtures_dir
8
- @fixtures_dir = "#{File.dirname(__FILE__)}/fixtures/"
9
- end
10
-
11
- def octocatalog_diff_dir
12
- @octocatalog_diff_dir = "#{File.dirname(__FILE__)}/octocatalog-diff/"
13
- end
14
-
15
- def ci_env
16
- @ci_env = ENV['CIRCLECI'] == 'true' || ENV['GITHUB_ACTIONS'] == 'true'
17
- end
18
- end
4
+ FIXTURES_DIR = "#{File.dirname(__FILE__)}/fixtures/".freeze
5
+ OCTOCATALOG_DIFF_DIR = "#{File.dirname(__FILE__)}/octocatalog-diff/".freeze
6
+ CI_ENV = ENV['CIRCLECI'] == 'true' || ENV['GITHUB_ACTIONS'] == 'true'
19
7
 
20
8
  RSpec.configure do |config|
21
- config.include Variables
22
9
  config.color = true
23
10
  end
@@ -6,10 +6,10 @@ require_relative '../../lib/puppet-check/tasks'
6
6
  describe PuppetCheck do
7
7
  context 'executed as a system from the CLI with arguments and various files to be processed' do
8
8
  it 'outputs diagnostic results correctly after processing all of the files' do
9
- Dir.chdir(fixtures_dir)
9
+ Dir.chdir(FIXTURES_DIR)
10
10
 
11
11
  # see regression_check_spec
12
- if ci_env
12
+ if CI_ENV
13
13
  expect(PuppetCheck::CLI.run(%w[-s --puppet-lint no-hard_tabs-check,no-140chars-check --rubocop Layout/LineLength,Style/Encoding --public keys/public_key.pkcs7.pem --private keys/private_key.pkcs7.pem .])).to eql(2)
14
14
  else
15
15
  expect(PuppetCheck::CLI.run(%w[-s --puppet-lint no-hard_tabs-check,no-140chars-check --rubocop Layout/LineLength,Style/Encoding --public keys/public_key.pkcs7.pem --private keys/private_key.pkcs7.pem --smoke -n good.example.com --octoconfig spec/octocatalog-diff/octocatalog-diff.cfg.rb .])).to eql(2)
@@ -25,7 +25,7 @@ describe PuppetCheck do
25
25
  context 'executed as a system from the Rakefile with arguments and various files to be processed' do
26
26
  it 'outputs diagnostic results correctly after processing all of the files' do
27
27
  # ensure rake only checks the files inside fixtures
28
- Dir.chdir(fixtures_dir)
28
+ Dir.chdir(FIXTURES_DIR)
29
29
 
30
30
  # clear out files member from previous system test
31
31
  PuppetCheck.files = {
@@ -47,7 +47,7 @@ describe PuppetCheck do
47
47
 
48
48
  it 'uses override settings and outputs diagnostic results correctly after processing all of the files' do
49
49
  # ensure rake only checks the files inside fixtures
50
- Dir.chdir(fixtures_dir)
50
+ Dir.chdir(FIXTURES_DIR)
51
51
 
52
52
  # clear out files member from previous system test
53
53
  PuppetCheck.files = {
@@ -60,7 +60,7 @@ describe PuppetCheck do
60
60
  # assign settings
61
61
  settings = { style: true }
62
62
  # see regression_check_spec
63
- unless ci_env
63
+ unless CI_ENV
64
64
  settings[:smoke] = true
65
65
  settings[:octonodes] = %w[good.example.com]
66
66
  settings[:octoconfig] = 'spec/octocatalog-diff/octocatalog-diff.cfg.rb'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-check
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Schuchard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-10-18 00:00:00.000000000 Z
11
+ date: 2026-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puppet
@@ -36,14 +36,14 @@ dependencies:
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '4.0'
39
+ version: '5.0'
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '4.0'
46
+ version: '5.0'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: reek
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -221,7 +221,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
221
221
  requirements:
222
222
  - - ">="
223
223
  - !ruby/object:Gem::Version
224
- version: 3.0.0
224
+ version: 3.1.0
225
225
  required_rubygems_version: !ruby/object:Gem::Requirement
226
226
  requirements:
227
227
  - - ">="