puppet-lint 0.1.9 → 0.1.10

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.
@@ -3,79 +3,69 @@ require 'spec_helper'
3
3
  describe PuppetLint::Plugins::CheckStrings do
4
4
  subject do
5
5
  klass = described_class.new
6
- klass.test(defined?(path).nil? ? '' : path, code)
6
+ klass.run(defined?(path).nil? ? '' : path, code)
7
7
  klass
8
8
  end
9
9
 
10
10
  describe 'double quoted string containing a variable insinde single quotes' do
11
11
  let(:code) { "exec { \"/usr/bin/wget -O - '${source}' | /usr/bin/apt-key add -\": }" }
12
12
 
13
- its(:warnings) { should be_empty }
14
- its(:errors) { should be_empty }
13
+ its(:problems) { should be_empty }
15
14
  end
16
15
 
17
16
  describe 'multiple strings in a line' do
18
17
  let(:code) { "\"aoeu\" '${foo}'" }
19
18
 
20
- its(:warnings) { should include "double quoted string containing no variables on line 1" }
21
- its(:errors) { should include "single quoted string containing a variable found on line 1" }
19
+ its(:problems) {
20
+ should have_problem :kind => :warning, :message => 'double quoted string containing no variables', :linenumber => '1'
21
+ should have_problem :kind => :error, :message => 'single quoted string containing a variable found', :linenumber => '1'
22
+ }
22
23
  end
23
24
 
24
25
  describe 'string containing only a variable' do
25
26
  let(:code) { '"${foo}"' }
26
27
 
27
- its(:warnings) { should include "string containing only a variable on line 1" }
28
- its(:errors) { should be_empty }
28
+ its(:problems) {
29
+ should only_have_problem :kind => :warning, :message => "string containing only a variable", :linenumber => '1'
30
+ }
29
31
  end
30
32
 
31
33
  describe 'variable not enclosed in {}' do
32
34
  let(:code) { '" $gronk"' }
33
35
 
34
- its(:warnings) { should include "variable not enclosed in {} on line 1" }
35
- its(:errors) { should be_empty }
36
- end
37
-
38
- if Puppet.version.start_with? "2.7"
39
- describe 'variable containing a dash' do
40
- let(:code) { '" $foo-bar"' }
36
+ its(:problems) {
37
+ should only_have_problem :kind => :warning, :message => "variable not enclosed in {}", :linenumber => '1'
38
+ }
41
39
 
42
- its(:warnings) { should include "variable contains a dash on line 1" }
43
- its(:errors) { should be_empty }
44
- end
45
40
  end
46
41
 
47
42
  describe 'double quoted string nested in a single quoted string' do
48
43
  let(:code) { "'grep \"status=sent\" /var/log/mail.log'" }
49
44
 
50
- its(:warnings) { should be_empty }
51
- its(:errors) { should be_empty }
45
+ its(:problems) { should be_empty }
52
46
  end
53
47
 
54
48
  describe 'double quoted string after a comment' do
55
49
  let(:code) { "service { 'foo': } # \"bar\"" }
56
50
 
57
- its(:warnings) { should be_empty }
58
- its(:errors) { should be_empty }
51
+ its(:problems) { should be_empty }
59
52
  end
60
53
 
61
54
  describe 'double quoted string containing newline but no variables' do
62
55
  let(:code) { '"foo\n"' }
63
56
 
64
- its(:warnings) { should be_empty }
65
- its(:errors) { should be_empty }
57
+ its(:problems) { should be_empty }
66
58
  end
67
59
 
68
60
  describe 'quoted false' do
69
61
  let(:code) { "class { 'foo': boolFlag => 'false' }" }
70
62
 
71
- its(:warnings) { should include "quoted boolean value found on line 1" }
72
- its(:errors) { should be_empty }
63
+ its(:problems) { should only_have_problem :kind => :warning, :message => "quoted boolean value found", :linenumber => 1 }
73
64
  end
74
65
 
75
66
  describe 'quoted true' do
76
67
  let(:code) { "class { 'foo': boolFlag => 'true' }" }
77
68
 
78
- its(:warnings) { should include "quoted boolean value found on line 1" }
79
- its(:errors) { should be_empty }
69
+ its(:problems) { should only_have_problem :kind => :warning, :message => "quoted boolean value found", :linenumber => 1 }
80
70
  end
81
71
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe PuppetLint::Plugins::CheckVariables do
4
4
  subject do
5
5
  klass = described_class.new
6
- klass.test(defined?(path).nil? ? '' : path, code)
6
+ klass.run(defined?(path).nil? ? '' : path, code)
7
7
  klass
8
8
  end
9
9
 
@@ -11,8 +11,13 @@ describe PuppetLint::Plugins::CheckVariables do
11
11
  describe 'a variable containing a dash' do
12
12
  let(:code) { "$foo-bar" }
13
13
 
14
- its(:warnings) { should include "Variable contains a dash on line 1" }
15
- its(:errors) { should be_empty }
14
+ its(:problems) { should have_problem :kind => :warning, :message => "variable contains a dash", :linenumber => 1 }
15
+ end
16
+
17
+ describe 'variable containing a dash' do
18
+ let(:code) { '" $foo-bar"' }
19
+
20
+ its(:problems) { should have_problem :kind => :warning, :message => "variable contains a dash", :linenumber => 1 }
16
21
  end
17
22
  end
18
23
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe PuppetLint::Plugins::CheckWhitespace do
4
4
  subject do
5
5
  klass = described_class.new
6
- klass.test(defined?(path).nil? ? '' : path, code)
6
+ klass.run(defined?(path).nil? ? '' : path, code)
7
7
  klass
8
8
  end
9
9
 
@@ -18,8 +18,7 @@ describe PuppetLint::Plugins::CheckWhitespace do
18
18
  }"
19
19
  }
20
20
 
21
- its(:warnings) { should be_empty }
22
- its(:errors) { should be_empty }
21
+ its(:problems) { should be_empty }
23
22
  end
24
23
 
25
24
  describe 'selectors in the middle of a resource' do
@@ -33,8 +32,7 @@ describe PuppetLint::Plugins::CheckWhitespace do
33
32
  }"
34
33
  }
35
34
 
36
- its(:warnings) { should be_empty }
37
- its(:errors) { should be_empty }
35
+ its(:problems) { should be_empty }
38
36
  end
39
37
 
40
38
  describe 'file resource with a source line > 80c' do
@@ -44,8 +42,7 @@ describe PuppetLint::Plugins::CheckWhitespace do
44
42
  }"
45
43
  }
46
44
 
47
- its(:warnings) { should be_empty }
48
- its(:errors) { should be_empty }
45
+ its(:problems) { should be_empty }
49
46
  end
50
47
 
51
48
  describe 'selector inside a resource' do
@@ -58,8 +55,7 @@ describe PuppetLint::Plugins::CheckWhitespace do
58
55
  group => 'foo4',
59
56
  mode => '0755'," }
60
57
 
61
- its(:warnings) { should be_empty }
62
- its(:errors) { should be_empty }
58
+ its(:problems) { should be_empty }
63
59
  end
64
60
 
65
61
  describe 'selector inside a hash inside a resource' do
@@ -75,8 +71,7 @@ describe PuppetLint::Plugins::CheckWhitespace do
75
71
  group => 'foo4',
76
72
  mode => '0755'," }
77
73
 
78
- its(:warnings) { should be_empty }
79
- its(:errors) { should be_empty }
74
+ its(:problems) { should be_empty }
80
75
  end
81
76
 
82
77
  describe 'issue #37' do
@@ -107,7 +102,6 @@ describe PuppetLint::Plugins::CheckWhitespace do
107
102
  }"
108
103
  }
109
104
 
110
- its(:warnings) { should be_empty }
111
- its(:errors) { should be_empty }
105
+ its(:problems) { should be_empty }
112
106
  end
113
107
  end
data/spec/spec_helper.rb CHANGED
@@ -9,3 +9,101 @@ require 'puppet-lint'
9
9
  #PuppetLint::CheckPlugin.any_instance.stub(:error) do |arg|
10
10
  # raise PuppetLint::Error
11
11
  #end
12
+
13
+ # filter_array_of_hashes(array, filter) -> an_array
14
+ #
15
+ # Filters out hashes by applying filter_hash to each hash
16
+ # in the array. All set value/key pairs in filter_hash must
17
+ # match before a hash is allowed.
18
+ # Returns all hashes that matched in an array.
19
+ #
20
+ # filter_array_of_hashes(
21
+ # [
22
+ # {:filter => 1, :name => 'one'},
23
+ # {:filter => 2, :name => 'two'},
24
+ # {:filter => 3, :name => 'three'},
25
+ # ],
26
+ # { :filter => 2 }
27
+ # )
28
+ # => [{:filter=>2, :name=>"two"}]
29
+ #
30
+ # filter_array_of_hashes([{:f => 1}, {:f => 2}], {})
31
+ # => [{:f=>1}, {:f=>2}]
32
+ #
33
+ def filter_array_of_hashes(array_of_hashes, filter_hash)
34
+ array_of_hashes.select { |hash_to_check|
35
+ val = true
36
+ filter_hash.each do |k,v|
37
+ if ! hash_to_check.key?(k)
38
+ val = false
39
+ break
40
+ elsif hash_to_check[k].to_s != v.to_s
41
+ val = false
42
+ break
43
+ end
44
+ end
45
+ val
46
+ }
47
+ end
48
+
49
+ RSpec::Matchers.define :have_problem do |filter|
50
+
51
+ match do |problems|
52
+ filter_array_of_hashes(problems, filter).length > 0
53
+ end
54
+
55
+ failure_message_for_should do |problems|
56
+ message = "could not find any problems matching the filter."
57
+ message << "
58
+ * filter = #{filter.inspect}
59
+ * problems = [
60
+ "
61
+ problems.each { |prob| message << " #{prob.inspect}," }
62
+ message << "
63
+ ]"
64
+ message
65
+ end
66
+
67
+ failure_message_for_should_not do |problems|
68
+ message = "some problems matched the filter."
69
+ message << "
70
+ * filter = #{filter.inspect}
71
+ * matched = [
72
+ "
73
+ filter_array_of_hashes(problems, filter).each { |prob| message << " #{prob.inspect}," }
74
+ message << "
75
+ ]"
76
+ message
77
+ end
78
+
79
+ end
80
+
81
+ RSpec::Matchers.define :only_have_problem do |filter|
82
+
83
+ match do |actual|
84
+ res = filter_array_of_hashes(actual, filter)
85
+ res.length == actual.length
86
+ end
87
+
88
+ failure_message_for_should do |problems|
89
+ left = problems - filter_problems(actual, filter)
90
+ message = "There were problems not matching filter."
91
+ message << "
92
+ * filter = #{filter.inspect}
93
+ * unmatched = [
94
+ "
95
+ left.each { |prob| message << " #{prob.inspect}," }
96
+ message << "
97
+ ]"
98
+ message
99
+ end
100
+
101
+ failure_message_for_should_not do |problems|
102
+ message = "There were no problems found besides the ones matched with filter."
103
+ message << "
104
+ * filter = #{filter.inspect}
105
+ "
106
+ message
107
+ end
108
+
109
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-lint
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 9
10
- version: 0.1.9
9
+ - 10
10
+ version: 0.1.10
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tim Sharpe
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-12-27 00:00:00 Z
18
+ date: 2012-01-11 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rspec
@@ -31,6 +31,20 @@ dependencies:
31
31
  version: "0"
32
32
  type: :development
33
33
  version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rdoc
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :development
47
+ version_requirements: *id002
34
48
  description: |-
35
49
  Checks your Puppet manifests against the Puppetlabs
36
50
  style guide and alerts you to any discrepancies.
@@ -43,6 +57,7 @@ extra_rdoc_files: []
43
57
 
44
58
  files:
45
59
  - bin/puppet-lint
60
+ - lib/puppet-lint/configuration.rb
46
61
  - lib/puppet-lint/plugin.rb
47
62
  - lib/puppet-lint/plugins/check_classes.rb
48
63
  - lib/puppet-lint/plugins/check_conditionals.rb