puppet-lint 0.4.0.pre1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/.travis.yml +3 -4
  2. data/Gemfile +2 -5
  3. data/README.md +2 -149
  4. data/Rakefile +0 -5
  5. data/lib/puppet-lint.rb +74 -20
  6. data/lib/puppet-lint/bin.rb +20 -85
  7. data/lib/puppet-lint/checkplugin.rb +158 -12
  8. data/lib/puppet-lint/checks.rb +39 -222
  9. data/lib/puppet-lint/configuration.rb +12 -31
  10. data/lib/puppet-lint/data.rb +329 -0
  11. data/lib/puppet-lint/lexer.rb +37 -30
  12. data/lib/puppet-lint/lexer/token.rb +14 -16
  13. data/lib/puppet-lint/monkeypatches/string_prepend.rb +6 -0
  14. data/lib/puppet-lint/optparser.rb +105 -0
  15. data/lib/puppet-lint/plugins.rb +28 -9
  16. data/lib/puppet-lint/plugins/check_classes.rb +162 -238
  17. data/lib/puppet-lint/plugins/check_comments.rb +40 -25
  18. data/lib/puppet-lint/plugins/check_conditionals.rb +16 -20
  19. data/lib/puppet-lint/plugins/check_documentation.rb +14 -20
  20. data/lib/puppet-lint/plugins/check_nodes.rb +23 -0
  21. data/lib/puppet-lint/plugins/check_resources.rb +127 -141
  22. data/lib/puppet-lint/plugins/check_strings.rb +133 -107
  23. data/lib/puppet-lint/plugins/check_variables.rb +11 -11
  24. data/lib/puppet-lint/plugins/check_whitespace.rb +86 -92
  25. data/lib/puppet-lint/tasks/puppet-lint.rb +17 -1
  26. data/lib/puppet-lint/version.rb +1 -1
  27. data/puppet-lint.gemspec +4 -2
  28. data/spec/fixtures/test/manifests/ignore.pp +1 -0
  29. data/spec/fixtures/test/manifests/ignore_reason.pp +1 -0
  30. data/spec/puppet-lint/bin_spec.rb +104 -84
  31. data/spec/puppet-lint/configuration_spec.rb +19 -19
  32. data/spec/puppet-lint/ignore_overrides_spec.rb +97 -0
  33. data/spec/puppet-lint/lexer/token_spec.rb +9 -9
  34. data/spec/puppet-lint/lexer_spec.rb +352 -325
  35. data/spec/puppet-lint/plugins/check_classes/autoloader_layout_spec.rb +77 -23
  36. data/spec/puppet-lint/plugins/check_classes/class_inherits_from_params_class_spec.rb +14 -12
  37. data/spec/puppet-lint/plugins/check_classes/inherits_across_namespaces_spec.rb +18 -14
  38. data/spec/puppet-lint/plugins/check_classes/names_containing_dash_spec.rb +30 -30
  39. data/spec/puppet-lint/plugins/check_classes/nested_classes_or_defines_spec.rb +31 -26
  40. data/spec/puppet-lint/plugins/check_classes/parameter_order_spec.rb +34 -28
  41. data/spec/puppet-lint/plugins/check_classes/right_to_left_relationship_spec.rb +14 -12
  42. data/spec/puppet-lint/plugins/check_classes/variable_scope_spec.rb +74 -30
  43. data/spec/puppet-lint/plugins/check_comments/slash_comments_spec.rb +27 -20
  44. data/spec/puppet-lint/plugins/check_comments/star_comments_spec.rb +78 -13
  45. data/spec/puppet-lint/plugins/check_conditionals/case_without_default_spec.rb +17 -12
  46. data/spec/puppet-lint/plugins/check_conditionals/selector_inside_resource_spec.rb +13 -10
  47. data/spec/puppet-lint/plugins/check_documentation/documentation_spec.rb +21 -16
  48. data/spec/puppet-lint/plugins/check_nodes/unquoted_node_name_spec.rb +69 -0
  49. data/spec/puppet-lint/plugins/check_resources/duplicate_params_spec.rb +42 -38
  50. data/spec/puppet-lint/plugins/check_resources/ensure_first_param_spec.rb +22 -10
  51. data/spec/puppet-lint/plugins/check_resources/ensure_not_symlink_target_spec.rb +81 -18
  52. data/spec/puppet-lint/plugins/check_resources/file_mode_spec.rb +69 -112
  53. data/spec/puppet-lint/plugins/check_resources/unquoted_file_mode_spec.rb +27 -20
  54. data/spec/puppet-lint/plugins/check_resources/unquoted_resource_title_spec.rb +177 -171
  55. data/spec/puppet-lint/plugins/check_strings/double_quoted_strings_spec.rb +165 -88
  56. data/spec/puppet-lint/plugins/check_strings/only_variable_string_spec.rb +97 -22
  57. data/spec/puppet-lint/plugins/check_strings/puppet_url_without_modules_spec.rb +25 -0
  58. data/spec/puppet-lint/plugins/check_strings/quoted_booleans_spec.rb +97 -111
  59. data/spec/puppet-lint/plugins/check_strings/single_quote_string_with_variables_spec.rb +10 -9
  60. data/spec/puppet-lint/plugins/check_strings/variables_not_enclosed_spec.rb +53 -53
  61. data/spec/puppet-lint/plugins/check_variables/variable_contains_dash_spec.rb +26 -14
  62. data/spec/puppet-lint/plugins/check_whitespace/2sp_soft_tabs_spec.rb +10 -9
  63. data/spec/puppet-lint/plugins/check_whitespace/80chars_spec.rb +31 -15
  64. data/spec/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb +340 -322
  65. data/spec/puppet-lint/plugins/check_whitespace/hard_tabs_spec.rb +30 -23
  66. data/spec/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb +42 -41
  67. data/spec/puppet-lint_spec.rb +3 -3
  68. data/spec/spec_helper.rb +109 -116
  69. metadata +109 -50
  70. data/spec/puppet-lint/plugins/check_classes/class_parameter_defaults_spec.rb +0 -60
@@ -1,25 +1,37 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'variable_contains_dash' do
4
- describe 'a variable containing a dash' do
4
+ let(:msg) { 'variable contains a dash' }
5
+
6
+ context 'a variable containing a dash' do
5
7
  let(:code) { '$foo-bar' }
6
8
 
7
- its(:problems) { should have_problem({
8
- :kind => :warning,
9
- :message => 'variable contains a dash',
10
- :linenumber => 1,
11
- :column => 1,
12
- }) }
9
+ it 'should only detect a single problem' do
10
+ expect(problems).to have(1).problem
11
+ end
12
+
13
+ it 'should create a warning' do
14
+ expect(problems).to contain_warning(msg).on_line(1).in_column(1)
15
+ end
13
16
  end
14
17
 
15
- describe 'variable containing a dash' do
18
+ context 'variable containing a dash' do
16
19
  let(:code) { '" $foo-bar"' }
17
20
 
18
- its(:problems) { should have_problem({
19
- :kind => :warning,
20
- :message => 'variable contains a dash',
21
- :linenumber => 1,
22
- :column => 3,
23
- }) }
21
+ it 'should only detect a single problem' do
22
+ expect(problems).to have(1).problem
23
+ end
24
+
25
+ it 'should create a warning' do
26
+ expect(problems).to contain_warning(msg).on_line(1).in_column(3)
27
+ end
28
+ end
29
+
30
+ context 'variable with an array reference containing a dash' do
31
+ let(:code) { "$foo[bar-baz]" }
32
+
33
+ it 'should not detect any problems' do
34
+ expect(problems).to be_empty
35
+ end
24
36
  end
25
37
  end
@@ -1,20 +1,21 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe '2sp_soft_tabs' do
4
- describe 'line indented by 3 spaces' do
4
+ let(:msg) { 'two-space soft tabs not used' }
5
+
6
+ context 'when a line is indented by 3 spaces' do
5
7
  let(:code) { "
6
8
  file { 'foo':
7
9
  foo => bar,
8
10
  }"
9
11
  }
10
12
 
11
- its(:problems) {
12
- should have_problem({
13
- :kind => :error,
14
- :message => 'two-space soft tabs not used',
15
- :linenumber => 3,
16
- :column => 1,
17
- })
18
- }
13
+ it 'should only detect a single problem' do
14
+ expect(problems).to have(1).problem
15
+ end
16
+
17
+ it 'should create an error' do
18
+ expect(problems).to contain_error(msg).on_line(3).in_column(1)
19
+ end
19
20
  end
20
21
  end
@@ -2,37 +2,53 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe '80chars' do
5
- describe 'file resource with a source line > 80c' do
5
+ let(:msg) { 'line has more than 80 characters' }
6
+
7
+ context 'file resource with a source line > 80c' do
6
8
  let(:code) { "
7
9
  file {
8
10
  source => 'puppet:///modules/certificates/etc/ssl/private/wildcard.example.com.crt',
9
11
  }"
10
12
  }
11
13
 
12
- its(:problems) { should be_empty }
14
+ it 'should not detect any problems' do
15
+ expect(problems).to have(0).problems
16
+ end
17
+ end
18
+
19
+ context 'file resource with a template line > 80c' do
20
+ let(:code) { "
21
+ file {
22
+ content => template('mymodule/this/is/a/truely/absurdly/long/path/that/should/make/you/feel/bad'),
23
+ }"
24
+ }
25
+
26
+ it 'should not detect any problems' do
27
+ expect(problems).to have(0).problems
28
+ end
13
29
  end
14
30
 
15
- describe 'length of lines with UTF-8 characters' do
31
+ context 'length of lines with UTF-8 characters' do
16
32
  let(:code) { "
17
33
  # ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
18
34
  # ┃ Configuration ┃
19
35
  # ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛"
20
36
  }
21
- its(:problems) {
22
- should be_empty
23
- }
37
+
38
+ it 'should not detect any problems' do
39
+ expect(problems).to have(0).problems
40
+ end
24
41
  end
25
42
 
26
- describe '81 character line' do
43
+ context '81 character line' do
27
44
  let(:code) { 'a' * 81 }
28
45
 
29
- its(:problems) {
30
- should have_problem({
31
- :kind => :warning,
32
- :message => 'line has more than 80 characters',
33
- :linenumber => 1,
34
- :column => 80,
35
- })
36
- }
46
+ it 'should only detect a single problem' do
47
+ expect(problems).to have(1).problem
48
+ end
49
+
50
+ it 'should create a warning' do
51
+ expect(problems).to contain_warning(msg).on_line(1).in_column(80)
52
+ end
37
53
  end
38
54
  end
@@ -1,304 +1,244 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'arrow_alignment' do
4
- describe 'selectors inside a resource' do
5
- let(:code) { "
6
- file { 'foo':
7
- ensure => $ensure,
8
- require => $ensure ? {
9
- present => Class['tomcat::install'],
10
- absent => undef;
11
- },
12
- foo => bar,
13
- }"
14
- }
4
+ let(:msg) { 'indentation of => is not properly aligned' }
5
+
6
+ context 'with fix disabled' do
7
+ context 'selectors inside a resource' do
8
+ let(:code) { "
9
+ file { 'foo':
10
+ ensure => $ensure,
11
+ require => $ensure ? {
12
+ present => Class['tomcat::install'],
13
+ absent => undef;
14
+ },
15
+ foo => bar,
16
+ }"
17
+ }
18
+
19
+ it 'should not detect any problems' do
20
+ expect(problems).to have(0).problems
21
+ end
22
+ end
15
23
 
16
- its(:problems) { should be_empty }
17
- end
24
+ context 'selectors in the middle of a resource' do
25
+ let(:code) { "
26
+ file { 'foo':
27
+ ensure => $ensure ? {
28
+ present => directory,
29
+ absent => undef,
30
+ },
31
+ owner => 'tomcat6',
32
+ }"
33
+ }
34
+
35
+ it 'should not detect any problems' do
36
+ expect(problems).to have(0).problems
37
+ end
38
+ end
18
39
 
19
- describe 'selectors in the middle of a resource' do
20
- let(:code) { "
21
- file { 'foo':
22
- ensure => $ensure ? {
40
+ context 'selector inside a resource' do
41
+ let(:code) { "
42
+ ensure => $ensure ? {
43
+ present => directory,
44
+ absent => undef,
45
+ },
46
+ owner => 'foo4',
47
+ group => 'foo4',
48
+ mode => '0755'," }
49
+
50
+ it 'should not detect any problems' do
51
+ expect(problems).to have(0).problems
52
+ end
53
+ end
54
+
55
+ context 'selector inside a hash inside a resource' do
56
+ let(:code) { "
57
+ server => {
58
+ ensure => ensure => $ensure ? {
23
59
  present => directory,
24
60
  absent => undef,
25
61
  },
26
- owner => 'tomcat6',
27
- }"
28
- }
29
-
30
- its(:problems) { should be_empty }
31
- end
32
-
33
- describe 'selector inside a resource' do
34
- let(:code) { "
35
- ensure => $ensure ? {
36
- present => directory,
37
- absent => undef,
38
- },
39
- owner => 'foo4',
40
- group => 'foo4',
41
- mode => '0755'," }
42
-
43
- its(:problems) { should be_empty }
44
- end
45
-
46
- describe 'selector inside a hash inside a resource' do
47
- let(:code) { "
48
- server => {
49
- ensure => ensure => $ensure ? {
50
- present => directory,
51
- absent => undef,
62
+ ip => '192.168.1.1'
52
63
  },
53
- ip => '192.168.1.1'
54
- },
55
- owner => 'foo4',
56
- group => 'foo4',
57
- mode => '0755'," }
64
+ owner => 'foo4',
65
+ group => 'foo4',
66
+ mode => '0755'," }
58
67
 
59
- its(:problems) { should be_empty }
60
- end
68
+ it 'should not detect any problems' do
69
+ expect(problems).to have(0).problems
70
+ end
71
+ end
61
72
 
62
- describe 'issue #37' do
63
- let(:code) { "
64
- class { 'lvs::base':
65
- virtualeservers => {
66
- '192.168.2.13' => {
67
- vport => '11025',
68
- service => 'smtp',
69
- scheduler => 'wlc',
70
- protocol => 'tcp',
71
- checktype => 'external',
72
- checkcommand => '/path/to/checkscript',
73
- real_servers => {
74
- 'server01' => {
75
- real_server => '192.168.2.14',
76
- real_port => '25',
77
- forwarding => 'masq',
78
- },
79
- 'server02' => {
80
- real_server => '192.168.2.15',
81
- real_port => '25',
82
- forwarding => 'masq',
73
+ context 'nested hashes with correct indentation' do
74
+ let(:code) { "
75
+ class { 'lvs::base':
76
+ virtualeservers => {
77
+ '192.168.2.13' => {
78
+ vport => '11025',
79
+ service => 'smtp',
80
+ scheduler => 'wlc',
81
+ protocol => 'tcp',
82
+ checktype => 'external',
83
+ checkcommand => '/path/to/checkscript',
84
+ real_servers => {
85
+ 'server01' => {
86
+ real_server => '192.168.2.14',
87
+ real_port => '25',
88
+ forwarding => 'masq',
89
+ },
90
+ 'server02' => {
91
+ real_server => '192.168.2.15',
92
+ real_port => '25',
93
+ forwarding => 'masq',
94
+ }
83
95
  }
84
96
  }
85
97
  }
86
- }
87
- }"
88
- }
98
+ }"
99
+ }
89
100
 
90
- its(:problems) { should be_empty }
91
- end
92
-
93
- describe 'single resource with a misaligned =>' do
94
- let(:code) { "
95
- file { '/tmp/foo':
96
- foo => 1,
97
- bar => 2,
98
- gronk => 3,
99
- baz => 4,
100
- meh => 5,
101
- }"
102
- }
103
-
104
- its(:problems) do
105
- should have_problem({
106
- :kind => :warning,
107
- :message => 'indentation of => is not properly aligned',
108
- :linenumber => 3,
109
- :column => 13,
110
- })
111
- should have_problem({
112
- :kind => :warning,
113
- :message => 'indentation of => is not properly aligned',
114
- :linenumber => 4,
115
- :column => 13,
116
- })
117
- should have_problem({
118
- :kind => :warning,
119
- :message => 'indentation of => is not properly aligned',
120
- :linenumber => 6,
121
- :column => 14,
122
- })
123
- should have_problem({
124
- :kind => :warning,
125
- :message => 'indentation of => is not properly aligned',
126
- :linenumber => 7,
127
- :column => 13,
128
- })
101
+ it 'should not detect any problems' do
102
+ expect(problems).to have(0).problems
103
+ end
129
104
  end
130
- end
131
105
 
132
- describe 'single resource with a misaligned => w/fix' do
133
- before do
134
- PuppetLint.configuration.fix = true
106
+ context 'single resource with a misaligned =>' do
107
+ let(:code) { "
108
+ file { '/tmp/foo':
109
+ foo => 1,
110
+ bar => 2,
111
+ gronk => 3,
112
+ baz => 4,
113
+ meh => 5,
114
+ }"
115
+ }
116
+
117
+ it 'should detect four problems' do
118
+ expect(problems).to have(4).problems
119
+ end
120
+
121
+ it 'should create four warnings' do
122
+ expect(problems).to contain_warning(msg).on_line(3).in_column(15)
123
+ expect(problems).to contain_warning(msg).on_line(4).in_column(15)
124
+ expect(problems).to contain_warning(msg).on_line(6).in_column(16)
125
+ expect(problems).to contain_warning(msg).on_line(7).in_column(15)
126
+ end
135
127
  end
136
128
 
137
- after do
138
- PuppetLint.configuration.fix = false
129
+ context 'complex resource with a misaligned =>' do
130
+ let(:code) { "
131
+ file { '/tmp/foo':
132
+ foo => 1,
133
+ bar => $baz ? {
134
+ gronk => 2,
135
+ meh => 3,
136
+ },
137
+ meep => 4,
138
+ bah => 5,
139
+ }"
140
+ }
141
+
142
+ it 'should detect three problems' do
143
+ expect(problems).to have(3).problems
144
+ end
145
+
146
+ it 'should create three warnings' do
147
+ expect(problems).to contain_warning(msg).on_line(3).in_column(15)
148
+ expect(problems).to contain_warning(msg).on_line(6).in_column(17)
149
+ expect(problems).to contain_warning(msg).on_line(9).in_column(15)
150
+ end
139
151
  end
140
152
 
141
- let(:code) { "
142
- file { '/tmp/foo':
143
- foo => 1,
144
- bar => 2,
145
- gronk => 3,
146
- baz => 4,
147
- meh => 5,
148
- }"
149
- }
150
-
151
- its(:problems) do
152
- should have_problem({
153
- :kind => :fixed,
154
- :message => 'indentation of => is not properly aligned',
155
- :linenumber => 3,
156
- :column => 13,
157
- })
158
- should have_problem({
159
- :kind => :fixed,
160
- :message => 'indentation of => is not properly aligned',
161
- :linenumber => 4,
162
- :column => 13,
163
- })
164
- should have_problem({
165
- :kind => :fixed,
166
- :message => 'indentation of => is not properly aligned',
167
- :linenumber => 6,
168
- :column => 14,
169
- })
170
- should have_problem({
171
- :kind => :fixed,
172
- :message => 'indentation of => is not properly aligned',
173
- :linenumber => 7,
174
- :column => 13,
175
- })
153
+ context 'multi-resource with a misaligned =>' do
154
+ let(:code) { "
155
+ file {
156
+ '/tmp/foo': ;
157
+ '/tmp/bar':
158
+ foo => 'bar';
159
+ '/tmp/baz':
160
+ gronk => 'bah',
161
+ meh => 'no'
162
+ }"
163
+ }
164
+
165
+ it 'should only detect a single problem' do
166
+ expect(problems).to have(1).problem
167
+ end
168
+
169
+ it 'should create a warning' do
170
+ expect(problems).to contain_warning(msg).on_line(8).in_column(17)
171
+ end
176
172
  end
177
173
 
178
- its(:manifest) { should == "
179
- file { '/tmp/foo':
180
- foo => 1,
181
- bar => 2,
182
- gronk => 3,
183
- baz => 4,
184
- meh => 5,
185
- }"
186
- }
187
- end
174
+ context 'multiple single line resources' do
175
+ let(:code) { "
176
+ file { 'foo': ensure => file }
177
+ package { 'bar': ensure => present }"
178
+ }
188
179
 
189
- describe 'complex resource with a misaligned =>' do
190
- let(:code) { "
191
- file { '/tmp/foo':
192
- foo => 1,
193
- bar => $baz ? {
194
- gronk => 2,
195
- meh => 3,
196
- },
197
- meep => 4,
198
- bah => 5,
199
- }"
200
- }
201
-
202
- its(:problems) do
203
- should have_problem({
204
- :kind => :warning,
205
- :message => 'indentation of => is not properly aligned',
206
- :linenumber => 3,
207
- :column => 13,
208
- })
209
- should have_problem({
210
- :kind => :warning,
211
- :message => 'indentation of => is not properly aligned',
212
- :linenumber => 6,
213
- :column => 15,
214
- })
215
- should have_problem({
216
- :kind => :warning,
217
- :message => 'indentation of => is not properly aligned',
218
- :linenumber => 9,
219
- :column => 13,
220
- })
180
+ it 'should not detect any problems' do
181
+ expect(problems).to have(0).problems
182
+ end
221
183
  end
222
- end
223
184
 
224
- describe 'complex resource with a misaligned => w/fix' do
225
- before do
226
- PuppetLint.configuration.fix = true
185
+ context 'resource with unaligned => in commented line' do
186
+ let(:code) { "
187
+ file { 'foo':
188
+ ensure => directory,
189
+ # purge => true,
190
+ }"
191
+ }
192
+
193
+ it 'should not detect any problems' do
194
+ expect(problems).to have(0).problems
195
+ end
227
196
  end
228
197
 
229
- after do
230
- PuppetLint.configuration.fix = false
231
- end
198
+ context 'single line resource spread out on multiple lines' do
199
+ let(:code) {"
200
+ file {
201
+ 'foo': ensure => present,
202
+ }"
203
+ }
232
204
 
233
- let(:code) { "
234
- file { '/tmp/foo':
235
- foo => 1,
236
- bar => $baz ? {
237
- gronk => 2,
238
- meh => 3,
239
- },
240
- meep => 4,
241
- bah => 5,
242
- }"
243
- }
244
-
245
- its(:problems) do
246
- should have_problem({
247
- :kind => :fixed,
248
- :message => 'indentation of => is not properly aligned',
249
- :linenumber => 3,
250
- :column => 13,
251
- })
252
- should have_problem({
253
- :kind => :fixed,
254
- :message => 'indentation of => is not properly aligned',
255
- :linenumber => 6,
256
- :column => 15,
257
- })
258
- should have_problem({
259
- :kind => :fixed,
260
- :message => 'indentation of => is not properly aligned',
261
- :linenumber => 9,
262
- :column => 13,
263
- })
205
+ it 'should not detect any problems' do
206
+ expect(problems).to have(0).problems
207
+ end
264
208
  end
265
209
 
266
- its(:manifest) { should == "
267
- file { '/tmp/foo':
268
- foo => 1,
269
- bar => $baz ? {
270
- gronk => 2,
271
- meh => 3,
272
- },
273
- meep => 4,
274
- bah => 5,
275
- }"
276
- }
277
- end
210
+ context 'multiline resource with a single line of params' do
211
+ let(:code) { "
212
+ mymodule::do_thing { 'some thing':
213
+ whatever => { foo => 'bar', one => 'two' },
214
+ }"
215
+ }
278
216
 
279
- describe 'multi-resource with a misaligned =>' do
280
- let(:code) { "
281
- file {
282
- '/tmp/foo': ;
283
- '/tmp/bar':
284
- foo => 'bar';
285
- '/tmp/baz':
286
- gronk => 'bah',
287
- meh => 'no'
288
- }"
289
- }
290
-
291
- its(:problems) do
292
- should only_have_problem({
293
- :kind => :warning,
294
- :message => 'indentation of => is not properly aligned',
295
- :linenumber => 8,
296
- :column => 15,
297
- })
217
+ it 'should not detect any problems' do
218
+ expect(problems).to have(0).problems
219
+ end
220
+ end
221
+
222
+ context 'resource with aligned => too far out' do
223
+ let(:code) { "
224
+ file { '/tmp/foo':
225
+ ensure => file,
226
+ mode => '0444',
227
+ }"
228
+ }
229
+
230
+ it 'should detect 2 problems' do
231
+ expect(problems).to have(2).problems
232
+ end
233
+
234
+ it 'should create 2 warnings' do
235
+ expect(problems).to contain_warning(msg).on_line(3).in_column(19)
236
+ expect(problems).to contain_warning(msg).on_line(4).in_column(19)
237
+ end
298
238
  end
299
239
  end
300
240
 
301
- describe 'multi-resource with a misaligned => w/fix' do
241
+ context 'with fix enabled' do
302
242
  before do
303
243
  PuppetLint.configuration.fix = true
304
244
  end
@@ -307,65 +247,143 @@ describe 'arrow_alignment' do
307
247
  PuppetLint.configuration.fix = false
308
248
  end
309
249
 
310
- let(:code) { "
311
- file {
312
- '/tmp/foo': ;
313
- '/tmp/bar':
314
- foo => 'bar';
315
- '/tmp/baz':
316
- gronk => 'bah',
317
- meh => 'no'
318
- }"
319
- }
320
-
321
- its(:problems) do
322
- should only_have_problem({
323
- :kind => :fixed,
324
- :message => 'indentation of => is not properly aligned',
325
- :linenumber => 8,
326
- :column => 15,
327
- })
250
+ context 'single resource with a misaligned =>' do
251
+ let(:code) { "
252
+ file { '/tmp/foo':
253
+ foo => 1,
254
+ bar => 2,
255
+ gronk => 3,
256
+ baz => 4,
257
+ meh => 5,
258
+ }"
259
+ }
260
+ let(:fixed) { "
261
+ file { '/tmp/foo':
262
+ foo => 1,
263
+ bar => 2,
264
+ gronk => 3,
265
+ baz => 4,
266
+ meh => 5,
267
+ }"
268
+ }
269
+
270
+ it 'should detect four problems' do
271
+ expect(problems).to have(4).problems
272
+ end
273
+
274
+ it 'should fix the manifest' do
275
+ expect(problems).to contain_fixed(msg).on_line(3).in_column(15)
276
+ expect(problems).to contain_fixed(msg).on_line(4).in_column(15)
277
+ expect(problems).to contain_fixed(msg).on_line(6).in_column(16)
278
+ expect(problems).to contain_fixed(msg).on_line(7).in_column(15)
279
+ end
280
+
281
+ it 'should align the arrows' do
282
+ expect(manifest).to eq(fixed)
283
+ end
328
284
  end
329
285
 
330
- its(:manifest) { should == "
331
- file {
332
- '/tmp/foo': ;
333
- '/tmp/bar':
334
- foo => 'bar';
335
- '/tmp/baz':
336
- gronk => 'bah',
337
- meh => 'no'
338
- }"
339
- }
340
- end
341
-
342
- describe 'multiple single line resources' do
343
- let(:code) { "
344
- file { 'foo': ensure => file }
345
- package { 'bar': ensure => present }"
346
- }
347
-
348
- its(:problems) { should be_empty }
349
- end
350
-
351
- describe 'resource with unaligned => in commented line' do
352
- let(:code) { "
353
- file { 'foo':
354
- ensure => directory,
355
- # purge => true,
356
- }"
357
- }
358
-
359
- its(:problems) { should be_empty }
360
- end
286
+ context 'complex resource with a misaligned =>' do
287
+ let(:code) { "
288
+ file { '/tmp/foo':
289
+ foo => 1,
290
+ bar => $baz ? {
291
+ gronk => 2,
292
+ meh => 3,
293
+ },
294
+ meep => 4,
295
+ bah => 5,
296
+ }"
297
+ }
298
+ let(:fixed) { "
299
+ file { '/tmp/foo':
300
+ foo => 1,
301
+ bar => $baz ? {
302
+ gronk => 2,
303
+ meh => 3,
304
+ },
305
+ meep => 4,
306
+ bah => 5,
307
+ }"
308
+ }
309
+
310
+ it 'should detect three problems' do
311
+ expect(problems).to have(3).problems
312
+ end
313
+
314
+ it 'should fix the manifest' do
315
+ expect(problems).to contain_fixed(msg).on_line(3).in_column(15)
316
+ expect(problems).to contain_fixed(msg).on_line(6).in_column(17)
317
+ expect(problems).to contain_fixed(msg).on_line(9).in_column(15)
318
+ end
319
+
320
+ it 'should align the arrows' do
321
+ expect(manifest).to eq(fixed)
322
+ end
323
+ end
361
324
 
362
- describe 'single line resource spread out on multiple lines' do
363
- let(:code) {"
364
- file {
365
- 'foo': ensure => present,
366
- }"
367
- }
325
+ context 'multi-resource with a misaligned =>' do
326
+ let(:code) { "
327
+ file {
328
+ '/tmp/foo': ;
329
+ '/tmp/bar':
330
+ foo => 'bar';
331
+ '/tmp/baz':
332
+ gronk => 'bah',
333
+ meh => 'no'
334
+ }"
335
+ }
336
+ let(:fixed) { "
337
+ file {
338
+ '/tmp/foo': ;
339
+ '/tmp/bar':
340
+ foo => 'bar';
341
+ '/tmp/baz':
342
+ gronk => 'bah',
343
+ meh => 'no'
344
+ }"
345
+ }
346
+
347
+ it 'should only detect a single problem' do
348
+ expect(problems).to have(1).problem
349
+ end
350
+
351
+ it 'should fix the manifest' do
352
+ expect(problems).to contain_fixed(msg).on_line(8).in_column(17)
353
+ end
354
+
355
+ it 'should align the arrows' do
356
+ expect(manifest).to eq(fixed)
357
+ end
358
+ end
368
359
 
369
- its(:problems) { should == [] }
360
+ context 'resource with aligned => too far out' do
361
+ let(:code) { "
362
+ file { '/tmp/foo':
363
+ ensure => file,
364
+ mode => '0444',
365
+ }"
366
+ }
367
+
368
+ let(:fixed) { "
369
+ file { '/tmp/foo':
370
+ ensure => file,
371
+ mode => '0444',
372
+ }"
373
+ }
374
+
375
+ it 'should detect 2 problems' do
376
+ expect(problems).to have(2).problems
377
+ end
378
+
379
+ it 'should create 2 warnings' do
380
+ expect(problems).to contain_fixed(msg).on_line(3).in_column(19)
381
+ expect(problems).to contain_fixed(msg).on_line(4).in_column(19)
382
+ end
383
+
384
+ it 'should realign the arrows with the minimum whitespace' do
385
+ expect(manifest).to eq(fixed)
386
+ end
387
+ end
370
388
  end
371
389
  end