puppet-check 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/.rubocop.yml +11 -0
  3. data/.travis.yml +21 -0
  4. data/CHANGELOG.md +14 -0
  5. data/Dockerfile +22 -0
  6. data/Gemfile +5 -0
  7. data/LICENSE.md +20 -0
  8. data/README.md +148 -0
  9. data/Rakefile +24 -0
  10. data/Vagrantfile +77 -0
  11. data/bin/puppet-check +5 -0
  12. data/config.reek +3 -0
  13. data/images/puppetcheck_new.png +0 -0
  14. data/images/puppetcheck_old.odp +0 -0
  15. data/images/puppetcheck_old.png +0 -0
  16. data/lib/puppet-check.rb +86 -0
  17. data/lib/puppet-check/cli.rb +33 -0
  18. data/lib/puppet-check/data_parser.rb +95 -0
  19. data/lib/puppet-check/puppet_parser.rb +77 -0
  20. data/lib/puppet-check/ruby_parser.rb +93 -0
  21. data/lib/puppet-check/tasks.rb +15 -0
  22. data/lib/puppet-check/utils.rb +22 -0
  23. data/puppet-check.gemspec +25 -0
  24. data/spec/fixtures/foobarbaz +1 -0
  25. data/spec/fixtures/hieradata/good.json +7 -0
  26. data/spec/fixtures/hieradata/good.yaml +7 -0
  27. data/spec/fixtures/hieradata/style.yaml +15 -0
  28. data/spec/fixtures/hieradata/syntax.json +8 -0
  29. data/spec/fixtures/hieradata/syntax.yaml +8 -0
  30. data/spec/fixtures/lib/good.rb +1 -0
  31. data/spec/fixtures/lib/rubocop_style.rb +3 -0
  32. data/spec/fixtures/lib/style.rb +12 -0
  33. data/spec/fixtures/lib/syntax.rb +1 -0
  34. data/spec/fixtures/librarian_good/Puppetfile +5 -0
  35. data/spec/fixtures/librarian_style/Puppetfile +5 -0
  36. data/spec/fixtures/librarian_syntax/Puppetfile +7 -0
  37. data/spec/fixtures/manifests/good.pp +1 -0
  38. data/spec/fixtures/manifests/style_lint.pp +4 -0
  39. data/spec/fixtures/manifests/style_parser.pp +2 -0
  40. data/spec/fixtures/manifests/syntax.pp +1 -0
  41. data/spec/fixtures/metadata_good/metadata.json +35 -0
  42. data/spec/fixtures/metadata_style/metadata.json +35 -0
  43. data/spec/fixtures/metadata_syntax/metadata.json +15 -0
  44. data/spec/fixtures/templates/good.epp +3 -0
  45. data/spec/fixtures/templates/good.erb +1 -0
  46. data/spec/fixtures/templates/no_method_error.erb +3 -0
  47. data/spec/fixtures/templates/style.erb +3 -0
  48. data/spec/fixtures/templates/syntax.epp +3 -0
  49. data/spec/fixtures/templates/syntax.erb +1 -0
  50. data/spec/integration/integration_spec.rb +41 -0
  51. data/spec/puppet-check/cli_spec.rb +48 -0
  52. data/spec/puppet-check/data_parser_spec.rb +64 -0
  53. data/spec/puppet-check/puppet_parser_spec.rb +67 -0
  54. data/spec/puppet-check/ruby_parser_spec.rb +111 -0
  55. data/spec/puppet-check/utils_spec.rb +20 -0
  56. data/spec/puppet-check_spec.rb +82 -0
  57. data/spec/spec_helper.rb +13 -0
  58. metadata +233 -0
@@ -0,0 +1 @@
1
+ i => am : a '' ruby.file { with } &bad syntax
@@ -0,0 +1,5 @@
1
+ mod 'i',
2
+ am: 'a',
3
+ good: 'librarian'
4
+
5
+ mod 'puppet', 'file'
@@ -0,0 +1,5 @@
1
+ mod 'i',
2
+ am: 'a',
3
+ librarian: 'puppet'
4
+
5
+ mod 'file', :with => 'bad style'
@@ -0,0 +1,7 @@
1
+ mod 'i',
2
+ am: 'a'
3
+ librarian: 'puppet'
4
+
5
+ mod 'file', with:
6
+
7
+ mod 'bad', :'syntax'
@@ -0,0 +1 @@
1
+ notify { 'i am a good manifest': }
@@ -0,0 +1,4 @@
1
+ notify { 'i am':
2
+ a => "manifest",
3
+ with => 'bad lint style',
4
+ }
@@ -0,0 +1,2 @@
1
+ #test for warnings
2
+ notify { 'i am a manifest with': message => "bad parser \[\] and lint style" }
@@ -0,0 +1 @@
1
+ $"iam${amanifest}$withbadsyntax"
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "puppetlabs-stdlib",
3
+ "version": "4.11.0",
4
+ "author": "puppetlabs",
5
+ "summary": "Standard library of resources for Puppet modules.",
6
+ "license": "Apache-2.0",
7
+ "source": "https://github.com/puppetlabs/puppetlabs-stdlib",
8
+ "project_page": "https://github.com/puppetlabs/puppetlabs-stdlib",
9
+ "issues_url": "https://tickets.puppetlabs.com/browse/MODULES",
10
+ "operatingsystem_support": [
11
+ {
12
+ "operatingsystem": "RedHat",
13
+ "operatingsystemrelease": [
14
+ "4",
15
+ "5",
16
+ "6",
17
+ "7"
18
+ ]
19
+ }
20
+ ],
21
+ "requirements": [
22
+ {
23
+ "name": "pe",
24
+ "version_requirement": ">= 3.0.0 < 2015.4.0"
25
+ },
26
+ {
27
+ "name": "puppet",
28
+ "version_requirement": ">=2.7.20 <5.0.0"
29
+ }
30
+ ],
31
+ "description": "Standard Library for Puppet Modules",
32
+ "dependencies": [
33
+
34
+ ]
35
+ }
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "puppetlabs-stdlib",
3
+ "version": "4.11.0",
4
+ "author": "puppetlabs",
5
+ "summary": "Standard library of resources for Puppet modules.",
6
+ "license": "Imaginary",
7
+ "source": "https://github.com/puppetlabs/puppetlabs-stdlib",
8
+ "project_page": "https://github.com/puppetlabs/puppetlabs-stdlib",
9
+ "issues_url": "https://tickets.puppetlabs.com/browse/MODULES",
10
+ "operatingsystem_support": [
11
+ {
12
+ "operatingsystem": "RedHat",
13
+ "operatingsystemrelease": [
14
+ "4",
15
+ "5",
16
+ "6",
17
+ "7"
18
+ ]
19
+ }
20
+ ],
21
+ "requirements": [
22
+ {
23
+ "name": "pe",
24
+ "version_requirement": ">= 3.0.0 < 2015.4.0"
25
+ },
26
+ {
27
+ "name": "puppet",
28
+ "version_requirement": ">=2.7.20 <5.0.0"
29
+ }
30
+ ],
31
+ "description": "Standard Library for Puppet Modules",
32
+ "dependencies": [
33
+
34
+ ]
35
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "puppetlabs-stdlib",
3
+ "author": "puppetlabs",
4
+ "summary": "This is the song that never ends. Yes it goes on and on my friends. Some people, started singing it not knowing what it was. And they will keep singing it forever just because.",
5
+ "license": "Apache-2.0",
6
+ "source": "https://github.com/puppetlabs/puppetlabs-stdlib",
7
+ "project_page": "https://github.com/puppetlabs/puppetlabs-stdlib",
8
+ "issues_url": "https://tickets.puppetlabs.com/browse/MODULES",
9
+ "description": "Standard Library for Puppet Modules",
10
+ "dependencies": [
11
+ {"name": "puppetlabs/nothing", "version_requirement": ">=1.1.1 < 2.2.2"},
12
+ {"name": "puppetlabs/nothing", "version_requirement": ">=1.1.1 < 2.2.2"}
13
+ ],
14
+ "checksum": "foo"
15
+ }
@@ -0,0 +1,3 @@
1
+ <%# i am %>
2
+ <% $a = 'good' -%>
3
+ puppet template
@@ -0,0 +1 @@
1
+ i am a good <%= @ruby -%> template
@@ -0,0 +1,3 @@
1
+ i am a
2
+ <% @ruby.upcase @template.downcase %>
3
+ with nomethoderror
@@ -0,0 +1,3 @@
1
+ i am a ruby
2
+ <% TEMPLATE = 'with' %>
3
+ <% TEMPLATE = 'bad style' %>
@@ -0,0 +1,3 @@
1
+ i am a
2
+ <% puppet template %>
3
+ < $with = 'bad syntax %>
@@ -0,0 +1 @@
1
+ i am <%= @a ruby %> template <%= @with -> bad syntax
@@ -0,0 +1,41 @@
1
+ require 'rake'
2
+ require_relative '../spec_helper.rb'
3
+ require_relative '../../lib/puppet-check/cli'
4
+ require_relative '../../lib/puppet-check/tasks'
5
+
6
+ describe 'PuppetCheck' do
7
+ context 'executed as a system from the CLI with arguments and various files to be processed' do
8
+ let(:cli) { PuppetCheck::CLI.run(%W(-s --puppet-lint no-hard_tabs-check,no-80chars-check --rubocop Metrics/LineLength,Style/Encoding #{fixtures_dir})) }
9
+
10
+ it 'outputs diagnostic results correctly after processing all of the files' do
11
+ expect(cli).to eql(1)
12
+ expect { cli }.not_to raise_exception
13
+ expect(PuppetCheck.error_files.length).to eql(8)
14
+ expect(PuppetCheck.warning_files.length).to eql(8)
15
+ expect(PuppetCheck.clean_files.length).to eql(9)
16
+ expect(PuppetCheck.ignored_files.length).to eql(1)
17
+ end
18
+ end
19
+
20
+ context 'executed as a system from the Rakefile with arguments and various files to be processed' do
21
+ let(:tasks) { Rake::Task['puppetcheck:file'].invoke }
22
+
23
+ before(:each) do
24
+ FileUtils.cd fixtures_dir
25
+ PuppetCheck.error_files = []
26
+ PuppetCheck.warning_files = []
27
+ PuppetCheck.clean_files = []
28
+ PuppetCheck.ignored_files = []
29
+ PuppetCheck.style_check = true
30
+ end
31
+
32
+ it 'outputs diagnostic results correctly after processing all of the files' do
33
+ expect(tasks).to eql(1)
34
+ expect { tasks }.not_to raise_exception
35
+ expect(PuppetCheck.error_files.length).to eql(8)
36
+ expect(PuppetCheck.warning_files.length).to eql(8)
37
+ expect(PuppetCheck.clean_files.length).to eql(9)
38
+ expect(PuppetCheck.ignored_files.length).to eql(1)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,48 @@
1
+ require_relative '../spec_helper'
2
+ require_relative '../../lib/puppet-check/cli'
3
+
4
+ describe PuppetCheck::CLI do
5
+ context '.run' do
6
+ it 'raises an error if no paths were specified' do
7
+ expect { PuppetCheck::CLI.run(%w(-s -f)) }.to raise_error(RuntimeError, 'puppet-check: no paths specified')
8
+ end
9
+ end
10
+
11
+ context '.parse' do
12
+ it 'raises an error if an invalid option was specified' do
13
+ expect { PuppetCheck::CLI.parse(%w(-s -f -asdf foo)) }.to raise_error(OptionParser::InvalidOption)
14
+ end
15
+
16
+ it 'allows future parser and style check to be enabled' do
17
+ PuppetCheck.future_parser = false
18
+ PuppetCheck.style_check = false
19
+ PuppetCheck::CLI.parse(%w(-s -f foo))
20
+ expect(PuppetCheck.future_parser).to eql(true)
21
+ expect(PuppetCheck.style_check).to eql(true)
22
+ end
23
+
24
+ it 'correctly parses PuppetLint arguments' do
25
+ PuppetCheck.puppetlint_args = []
26
+ PuppetCheck::CLI.parse(%w(--puppet-lint puppetlint-arg-one,puppetlint-arg-two foo))
27
+ expect(PuppetCheck.puppetlint_args).to eql(['--puppetlint-arg-one', '--puppetlint-arg-two'])
28
+ end
29
+
30
+ it 'correctly parses Rubocop arguments' do
31
+ PuppetCheck.rubocop_args = []
32
+ PuppetCheck::CLI.parse(%w(--rubocop rubocop-arg-one,rubocop-arg-two foo))
33
+ expect(PuppetCheck.rubocop_args).to eql(['--except', 'rubocop-arg-one,rubocop-arg-two'])
34
+ end
35
+
36
+ it 'correctly parses multiple sets of arguments' do
37
+ PuppetCheck.future_parser = false
38
+ PuppetCheck.style_check = false
39
+ PuppetCheck.puppetlint_args = []
40
+ PuppetCheck.rubocop_args = []
41
+ PuppetCheck::CLI.parse(%w(-s -f --puppet-lint puppetlint-arg-one,puppetlint-arg-two --rubocop rubocop-arg-one,rubocop-arg-two foo))
42
+ expect(PuppetCheck.future_parser).to eql(true)
43
+ expect(PuppetCheck.style_check).to eql(true)
44
+ expect(PuppetCheck.puppetlint_args).to eql(['--puppetlint-arg-one', '--puppetlint-arg-two'])
45
+ expect(PuppetCheck.rubocop_args).to eql(['--except', 'rubocop-arg-one,rubocop-arg-two'])
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,64 @@
1
+ require_relative '../spec_helper'
2
+ require_relative '../../lib/puppet-check/data_parser'
3
+
4
+ describe DataParser do
5
+ before(:each) do
6
+ PuppetCheck.error_files = []
7
+ PuppetCheck.warning_files = []
8
+ PuppetCheck.clean_files = []
9
+ end
10
+
11
+ context '.yaml' do
12
+ it 'puts a bad syntax yaml file in the error files array' do
13
+ DataParser.yaml([fixtures_dir + 'hieradata/syntax.yaml'])
14
+ expect(PuppetCheck.error_files[0]).to match(%r{^\-\- #{fixtures_dir}hieradata/syntax.yaml:\nblock sequence entries are not allowed})
15
+ expect(PuppetCheck.warning_files).to eql([])
16
+ expect(PuppetCheck.clean_files).to eql([])
17
+ end
18
+ it 'puts a good yaml file with potential hiera issues in the warning files array' do
19
+ DataParser.yaml([fixtures_dir + 'hieradata/style.yaml'])
20
+ expect(PuppetCheck.error_files).to eql([])
21
+ expect(PuppetCheck.warning_files[0]).to match(%r{^\-\- #{fixtures_dir}hieradata/style.yaml:\nValues missing in key})
22
+ expect(PuppetCheck.clean_files).to eql([])
23
+ end
24
+ it 'puts a good yaml file in the clean files array' do
25
+ DataParser.yaml([fixtures_dir + 'hieradata/good.yaml'])
26
+ expect(PuppetCheck.error_files).to eql([])
27
+ expect(PuppetCheck.warning_files).to eql([])
28
+ expect(PuppetCheck.clean_files).to eql(["-- #{fixtures_dir}hieradata/good.yaml"])
29
+ end
30
+ end
31
+
32
+ context '.json' do
33
+ it 'puts a bad syntax json file in the error files array' do
34
+ DataParser.json([fixtures_dir + 'hieradata/syntax.json'])
35
+ expect(PuppetCheck.error_files[0]).to match(%r{^\-\- #{fixtures_dir}hieradata/syntax.json:\n.*unexpected token})
36
+ expect(PuppetCheck.warning_files).to eql([])
37
+ expect(PuppetCheck.clean_files).to eql([])
38
+ end
39
+ it 'puts a bad metadata json file in the error files array' do
40
+ DataParser.json([fixtures_dir + 'metadata_syntax/metadata.json'])
41
+ expect(PuppetCheck.error_files[0]).to match(%r{^\-\- #{fixtures_dir}metadata_syntax/metadata.json:\nRequired field.*\nDuplicate dependencies.*\nDeprecated field.*\nSummary exceeds})
42
+ expect(PuppetCheck.warning_files).to eql([])
43
+ expect(PuppetCheck.clean_files).to eql([])
44
+ end
45
+ it 'puts a bad style metadata json file in the warning files array' do
46
+ DataParser.json([fixtures_dir + 'metadata_style/metadata.json'])
47
+ expect(PuppetCheck.error_files).to eql([])
48
+ expect(PuppetCheck.warning_files[0]).to match(%r{^\-\- #{fixtures_dir}metadata_style/metadata.json:\nLicense identifier})
49
+ expect(PuppetCheck.clean_files).to eql([])
50
+ end
51
+ it 'puts a good json file in the clean files array' do
52
+ DataParser.json([fixtures_dir + 'hieradata/good.json'])
53
+ expect(PuppetCheck.error_files).to eql([])
54
+ expect(PuppetCheck.warning_files).to eql([])
55
+ expect(PuppetCheck.clean_files).to eql(["-- #{fixtures_dir}hieradata/good.json"])
56
+ end
57
+ it 'puts a good metadata json file in the clean files array' do
58
+ DataParser.json([fixtures_dir + 'metadata_good/metadata.json'])
59
+ expect(PuppetCheck.error_files).to eql([])
60
+ expect(PuppetCheck.warning_files).to eql([])
61
+ expect(PuppetCheck.clean_files).to eql(["-- #{fixtures_dir}metadata_good/metadata.json"])
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,67 @@
1
+ require_relative '../spec_helper'
2
+ require_relative '../../lib/puppet-check/puppet_parser'
3
+
4
+ describe PuppetParser do
5
+ before(:each) do
6
+ PuppetCheck.error_files = []
7
+ PuppetCheck.warning_files = []
8
+ PuppetCheck.clean_files = []
9
+ PuppetCheck.future_parser = false
10
+ PuppetCheck.style_check = false
11
+ PuppetCheck.puppetlint_args = []
12
+ end
13
+
14
+ context '.manifest' do
15
+ it 'puts a bad syntax Puppet manifest in the error files array' do
16
+ PuppetParser.manifest([fixtures_dir + 'manifests/syntax.pp'])
17
+ # expect(subject.instance_variable_get(:@error_files)[0]).to match(%r{^\-\- #{fixtures_dir}manifests/syntax.pp:.*syntax error})
18
+ expect(PuppetCheck.error_files[0]).to match(%r{^\-\- #{fixtures_dir}manifests/syntax.pp:\nThis Variable has no effect.*\nIllegal variable name})
19
+ expect(PuppetCheck.warning_files).to eql([])
20
+ expect(PuppetCheck.clean_files).to eql([])
21
+ end
22
+ it 'puts a bad parser and lint style Puppet manifest in the warning files array' do
23
+ PuppetCheck.style_check = true
24
+ PuppetParser.manifest([fixtures_dir + 'manifests/style_parser.pp'])
25
+ expect(PuppetCheck.error_files).to eql([])
26
+ expect(PuppetCheck.warning_files[0]).to match(%r{^\-\- #{fixtures_dir}manifests/style_parser.pp:\nUnrecognized escape sequence.*\nUnrecognized escape sequence.*\ndouble quoted string containing})
27
+ expect(PuppetCheck.clean_files).to eql([])
28
+ end
29
+ it 'puts a bad lint style Puppet manifest in the warning files array' do
30
+ PuppetCheck.style_check = true
31
+ PuppetParser.manifest([fixtures_dir + 'manifests/style_lint.pp'])
32
+ expect(PuppetCheck.error_files).to eql([])
33
+ expect(PuppetCheck.warning_files[0]).to match(%r{^\-\- #{fixtures_dir}manifests/style_lint.pp:\ndouble quoted string containing.*\nindentation of})
34
+ expect(PuppetCheck.clean_files).to eql([])
35
+ end
36
+ it 'puts a bad style Puppet manifest in the clean files array when puppetlint_args ignores its warnings' do
37
+ PuppetCheck.style_check = true
38
+ PuppetCheck.puppetlint_args = ['--no-double_quoted_strings-check', '--no-arrow_alignment-check']
39
+ PuppetParser.manifest([fixtures_dir + 'manifests/style_lint.pp'])
40
+ expect(PuppetCheck.error_files).to eql([])
41
+ expect(PuppetCheck.warning_files).to eql([])
42
+ expect(PuppetCheck.clean_files).to eql(["-- #{fixtures_dir}manifests/style_lint.pp"])
43
+ end
44
+ it 'puts a good Puppet manifest in the clean files array' do
45
+ PuppetCheck.style_check = true
46
+ PuppetParser.manifest([fixtures_dir + 'manifests/good.pp'])
47
+ expect(PuppetCheck.error_files).to eql([])
48
+ expect(PuppetCheck.warning_files).to eql([])
49
+ expect(PuppetCheck.clean_files).to eql(["-- #{fixtures_dir}manifests/good.pp"])
50
+ end
51
+ end
52
+
53
+ context '.template' do
54
+ it 'puts a bad syntax Puppet template in the error files array' do
55
+ PuppetParser.template([fixtures_dir + 'templates/syntax.epp'])
56
+ expect(PuppetCheck.error_files[0]).to match(%r{^\-\- #{fixtures_dir}templates/syntax.epp:\nThis Name has no effect})
57
+ expect(PuppetCheck.warning_files).to eql([])
58
+ expect(PuppetCheck.clean_files).to eql([])
59
+ end
60
+ it 'puts a good Puppet template in the clean files array' do
61
+ PuppetParser.template([fixtures_dir + 'templates/good.epp'])
62
+ expect(PuppetCheck.error_files).to eql([])
63
+ expect(PuppetCheck.warning_files).to eql([])
64
+ expect(PuppetCheck.clean_files).to eql(["-- #{fixtures_dir}templates/good.epp"])
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,111 @@
1
+ require_relative '../spec_helper'
2
+ require_relative '../../lib/puppet-check/ruby_parser'
3
+
4
+ describe RubyParser do
5
+ before(:each) do
6
+ PuppetCheck.error_files = []
7
+ PuppetCheck.warning_files = []
8
+ PuppetCheck.clean_files = []
9
+ PuppetCheck.style_check = false
10
+ PuppetCheck.rubocop_args = []
11
+ end
12
+
13
+ context '.ruby' do
14
+ it 'puts a bad syntax ruby file in the error files array' do
15
+ RubyParser.ruby([fixtures_dir + 'lib/syntax.rb'])
16
+ expect(PuppetCheck.error_files[0]).to match(%r{^\-\- #{fixtures_dir}lib/syntax.rb:\n.*syntax error})
17
+ expect(PuppetCheck.warning_files).to eql([])
18
+ expect(PuppetCheck.clean_files).to eql([])
19
+ end
20
+ if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.1.0')
21
+ it 'puts a bad style ruby file in the warning files array' do
22
+ PuppetCheck.style_check = true
23
+ RubyParser.ruby([fixtures_dir + 'lib/style.rb'])
24
+ expect(PuppetCheck.error_files).to eql([])
25
+ expect(PuppetCheck.warning_files[0]).to match(%r{^\-\- #{fixtures_dir}lib/style.rb:\n.*Useless assignment.*\n.*Use the new.*\n.*Do not introduce.*\n.*Prefer single.*\n.*is a writable attribute.*\n.*Issue has no descriptive comment})
26
+ expect(PuppetCheck.clean_files).to eql([])
27
+ end
28
+ else
29
+ it 'puts a bad style ruby file in the warning files array' do
30
+ PuppetCheck.style_check = true
31
+ RubyParser.ruby([fixtures_dir + 'lib/style.rb'])
32
+ expect(PuppetCheck.error_files).to eql([])
33
+ expect(PuppetCheck.warning_files[0]).to match(%r{^\-\- #{fixtures_dir}lib/style.rb:\n.*Useless assignment.*\n.*Use the new.*\n.*Do not introduce.*\n.*Prefer single})
34
+ expect(PuppetCheck.clean_files).to eql([])
35
+ end
36
+ end
37
+ it 'puts a bad style ruby file in the clean files array when rubocop_args ignores its warnings' do
38
+ PuppetCheck.style_check = true
39
+ PuppetCheck.rubocop_args = ['--except', 'Lint/UselessAssignment,Style/HashSyntax,Style/GlobalVars,Style/StringLiterals']
40
+ RubyParser.ruby([fixtures_dir + 'lib/rubocop_style.rb'])
41
+ expect(PuppetCheck.error_files).to eql([])
42
+ expect(PuppetCheck.warning_files).to eql([])
43
+ expect(PuppetCheck.clean_files).to eql(["-- #{fixtures_dir}lib/rubocop_style.rb"])
44
+ end
45
+ it 'puts a good ruby file in the clean files array' do
46
+ PuppetCheck.style_check = true
47
+ RubyParser.ruby([fixtures_dir + 'lib/good.rb'])
48
+ expect(PuppetCheck.error_files).to eql([])
49
+ expect(PuppetCheck.warning_files).to eql([])
50
+ expect(PuppetCheck.clean_files).to eql(["-- #{fixtures_dir}lib/good.rb"])
51
+ end
52
+ end
53
+
54
+ context '.template' do
55
+ it 'puts a bad syntax ruby template file in the error files array' do
56
+ RubyParser.template([fixtures_dir + 'templates/syntax.erb'])
57
+ expect(PuppetCheck.error_files[0]).to match(%r{^\-\- #{fixtures_dir}templates/syntax.erb:\n.*syntax error, unexpected tIDENTIFIER})
58
+ expect(PuppetCheck.warning_files).to eql([])
59
+ expect(PuppetCheck.clean_files).to eql([])
60
+ end
61
+ it 'puts a bad style ruby template file in the warning files array' do
62
+ RubyParser.template([fixtures_dir + 'templates/style.erb'])
63
+ expect(PuppetCheck.error_files).to eql([])
64
+ expect(PuppetCheck.warning_files[0]).to match(%r{^\-\- #{fixtures_dir}templates/style.erb:\n.*already initialized constant.*\n.*(previous definition of|already initialized constant)})
65
+ expect(PuppetCheck.clean_files).to eql([])
66
+ end
67
+ it 'puts a ruby template file with ignored errors in the clean files array' do
68
+ RubyParser.template([fixtures_dir + 'templates/no_method_error.erb'])
69
+ expect(PuppetCheck.error_files).to eql([])
70
+ expect(PuppetCheck.warning_files).to eql([])
71
+ expect(PuppetCheck.clean_files).to eql(["-- #{fixtures_dir}templates/no_method_error.erb"])
72
+ end
73
+ it 'puts a good ruby template file in the clean files array' do
74
+ RubyParser.template([fixtures_dir + 'templates/good.erb'])
75
+ expect(PuppetCheck.error_files).to eql([])
76
+ expect(PuppetCheck.warning_files).to eql([])
77
+ expect(PuppetCheck.clean_files).to eql(["-- #{fixtures_dir}templates/good.erb"])
78
+ end
79
+ end
80
+
81
+ context '.librarian' do
82
+ it 'puts a bad syntax librarian Puppet file in the error files array' do
83
+ RubyParser.librarian([fixtures_dir + 'librarian_syntax/Puppetfile'])
84
+ expect(PuppetCheck.error_files[0]).to match(%r{^\-\- #{fixtures_dir}librarian_syntax/Puppetfile:\n.*syntax error})
85
+ expect(PuppetCheck.warning_files).to eql([])
86
+ expect(PuppetCheck.clean_files).to eql([])
87
+ end
88
+ it 'puts a bad style librarian Puppet file in the warning files array' do
89
+ PuppetCheck.style_check = true
90
+ RubyParser.librarian([fixtures_dir + 'librarian_style/Puppetfile'])
91
+ expect(PuppetCheck.error_files).to eql([])
92
+ expect(PuppetCheck.warning_files[0]).to match(%r{^\-\- #{fixtures_dir}librarian_style/Puppetfile:\n.*Align the parameters.*\n.*Use the new})
93
+ expect(PuppetCheck.clean_files).to eql([])
94
+ end
95
+ it 'puts a bad style librarian Puppet file in the clean files array when rubocop_args ignores its warnings' do
96
+ PuppetCheck.style_check = true
97
+ PuppetCheck.rubocop_args = ['--except', 'Style/AlignParameters,Style/HashSyntax']
98
+ RubyParser.librarian([fixtures_dir + 'librarian_style/Puppetfile'])
99
+ expect(PuppetCheck.error_files).to eql([])
100
+ expect(PuppetCheck.warning_files).to eql([])
101
+ expect(PuppetCheck.clean_files).to eql(["-- #{fixtures_dir}librarian_style/Puppetfile"])
102
+ end
103
+ it 'puts a good librarian Puppet file in the clean files array' do
104
+ PuppetCheck.style_check = true
105
+ RubyParser.librarian([fixtures_dir + 'librarian_good/Puppetfile'])
106
+ expect(PuppetCheck.error_files).to eql([])
107
+ expect(PuppetCheck.warning_files).to eql([])
108
+ expect(PuppetCheck.clean_files).to eql(["-- #{fixtures_dir}librarian_good/Puppetfile"])
109
+ end
110
+ end
111
+ end