rspec-puppet 0.0.6 → 0.0.7
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.
- data/README.md +59 -25
- data/lib/rspec-puppet/matchers/create_generic.rb +13 -0
- data/rspec-puppet.gemspec +1 -1
- data/spec/defines/sysctl_spec.rb +2 -1
- metadata +12 -7
data/README.md
CHANGED
@@ -33,13 +33,15 @@ If you use the above directory structure, your examples will automatically be
|
|
33
33
|
placed in the correct groups and have access to the custom matchers. If you
|
34
34
|
choose not to, you can force the examples into the required groups as follows.
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
```ruby
|
37
|
+
describe 'myclass', :type => :class do
|
38
|
+
...
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
41
|
+
describe 'mydefine', :type => :define do
|
42
|
+
...
|
43
|
+
end
|
44
|
+
```
|
43
45
|
|
44
46
|
## Matchers
|
45
47
|
|
@@ -49,21 +51,39 @@ You can test if a class has been included in the catalogue with the
|
|
49
51
|
`include_class` matcher. It takes the class name as a string as its only
|
50
52
|
argument
|
51
53
|
|
52
|
-
|
54
|
+
```ruby
|
55
|
+
it { should include_class('foo') }
|
56
|
+
```
|
53
57
|
|
54
58
|
### Checking if a resources exists
|
55
59
|
|
56
60
|
You can test if a resource exists in the catalogue with the generic
|
57
|
-
`
|
61
|
+
`contain_<resource type>` matcher.
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
it { should contain_augeas('bleh') }
|
65
|
+
```
|
66
|
+
|
67
|
+
If your resource type includes :: (e.g.
|
58
68
|
`foo::bar` simply replace the :: with __ (two underscores).
|
59
69
|
|
60
|
-
|
61
|
-
|
70
|
+
```ruby
|
71
|
+
it { should contain_foo__bar('baz') }
|
72
|
+
```
|
62
73
|
|
63
74
|
You can further test the parameters that have been passed to the resources with
|
64
75
|
the generic `with_<parameter>` chains.
|
65
76
|
|
66
|
-
|
77
|
+
```ruby
|
78
|
+
it { should contain_package('mysql-server').with_ensure('present') }
|
79
|
+
```
|
80
|
+
|
81
|
+
You can also test that specific parameters have been left undefined with the
|
82
|
+
generic `without_<parameter>` chains.
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
it { should contain_file('/foo/bar').without_mode }
|
86
|
+
```
|
67
87
|
|
68
88
|
## Writing tests
|
69
89
|
|
@@ -81,46 +101,60 @@ Will cause the following resource to be in included in catalogue for a host
|
|
81
101
|
command => '/sbin/sysctl -p /etc/sysctl.conf',
|
82
102
|
}
|
83
103
|
|
84
|
-
We can write the following testcase
|
104
|
+
We can write the following testcase (in `spec/defines/sysctl_spec.rb`)
|
85
105
|
|
86
|
-
|
87
|
-
|
88
|
-
|
106
|
+
```ruby
|
107
|
+
describe 'sysctl' do
|
108
|
+
let(:title) { 'baz' }
|
109
|
+
let(:params) { { :value => 'foo' } }
|
89
110
|
|
90
|
-
|
91
|
-
|
111
|
+
it { should contain_exec('sysctl/reload').with_command("/sbin/sysctl -p /etc/sysctl.conf") }
|
112
|
+
end
|
113
|
+
```
|
92
114
|
|
93
115
|
### Specifying the title of a resource
|
94
116
|
|
95
|
-
|
117
|
+
```ruby
|
118
|
+
let(:title) { 'foo' }
|
119
|
+
```
|
96
120
|
|
97
121
|
### Specifying the parameters to pass to a resources or parametised class
|
98
122
|
|
99
|
-
|
123
|
+
```ruby
|
124
|
+
let(:params) { {:ensure => 'present', ...} }
|
125
|
+
```
|
100
126
|
|
101
127
|
### Specifying the FQDN of the test node
|
102
128
|
|
103
129
|
If the manifest you're testing expects to run on host with a particular name,
|
104
130
|
you can specify this as follows
|
105
131
|
|
106
|
-
|
132
|
+
```ruby
|
133
|
+
let(:node) { 'testhost.example.com' }
|
134
|
+
```
|
107
135
|
|
108
136
|
### Specifying the facts that should be available to your manifest
|
109
137
|
|
110
138
|
By default, the test environment contains no facts for your manifest to use.
|
111
139
|
You can set them with a hash
|
112
140
|
|
113
|
-
|
141
|
+
```ruby
|
142
|
+
let(:facts) { {:operatingsystem => 'Debian', :kernel => 'Linux', ...} }
|
143
|
+
```
|
114
144
|
|
115
145
|
### Specifying the path to find your modules
|
116
146
|
|
117
147
|
I recommend setting a default module path by adding the following code to your
|
118
148
|
`spec_helper.rb`
|
119
149
|
|
120
|
-
|
121
|
-
|
122
|
-
|
150
|
+
```ruby
|
151
|
+
RSpec.configure do |c|
|
152
|
+
c.module_path = '/path/to/your/module/dir'
|
153
|
+
end
|
154
|
+
```
|
123
155
|
|
124
156
|
However, if you want to specify it in each example, you can do so
|
125
157
|
|
126
|
-
|
158
|
+
```ruby
|
159
|
+
let(:module_path) { '/path/to/your/module/dir' }
|
160
|
+
```
|
@@ -14,6 +14,10 @@ module RSpec::Puppet
|
|
14
14
|
param = method.to_s.gsub(/^with_/, '')
|
15
15
|
(@expected_params ||= []) << [param, args[0]]
|
16
16
|
self
|
17
|
+
elsif method.to_s =~ /^without_/
|
18
|
+
param = method.to_s.gsub(/^without_/, '')
|
19
|
+
(@expected_undef_params ||= []) << param
|
20
|
+
self
|
17
21
|
else
|
18
22
|
super
|
19
23
|
end
|
@@ -34,6 +38,15 @@ module RSpec::Puppet
|
|
34
38
|
end
|
35
39
|
end
|
36
40
|
end
|
41
|
+
|
42
|
+
if @expected_undef_params
|
43
|
+
@expected_undef_params.each do |name|
|
44
|
+
unless resource.send(:parameters)[name.to_sym].nil?
|
45
|
+
ret = false
|
46
|
+
(@errors ||= []) << "#{name.to_s} undefined"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
37
50
|
end
|
38
51
|
|
39
52
|
ret
|
data/rspec-puppet.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'rspec-puppet'
|
3
|
-
s.version = '0.0.
|
3
|
+
s.version = '0.0.7'
|
4
4
|
s.homepage = 'https://github.com/rodjek/rspec-puppet/'
|
5
5
|
s.summary = 'RSpec tests for your Puppet manifests'
|
6
6
|
s.description = 'RSpec tests for your Puppet manifests'
|
data/spec/defines/sysctl_spec.rb
CHANGED
@@ -9,5 +9,6 @@ describe 'sysctl' do
|
|
9
9
|
.with_context('/files/etc/sysctl.conf') \
|
10
10
|
.with_changes("set vm.swappiness '60'") \
|
11
11
|
.with_onlyif("match vm.swappiness[.='60'] size == 0") \
|
12
|
-
.with_notify('Exec[sysctl/reload]')
|
12
|
+
.with_notify('Exec[sysctl/reload]')\
|
13
|
+
.without_foo }
|
13
14
|
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-puppet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 17
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
9
|
+
- 7
|
10
|
+
version: 0.0.7
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Tim Sharpe
|
@@ -14,16 +15,17 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2011-08-
|
18
|
-
default_executable:
|
18
|
+
date: 2011-08-29 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rspec
|
22
22
|
prerelease: false
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
24
25
|
requirements:
|
25
26
|
- - ">="
|
26
27
|
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
27
29
|
segments:
|
28
30
|
- 0
|
29
31
|
version: "0"
|
@@ -58,7 +60,6 @@ files:
|
|
58
60
|
- spec/fixtures/boolean/manifests/init.pp
|
59
61
|
- spec/fixtures/sysctl/manifests/init.pp
|
60
62
|
- spec/spec_helper.rb
|
61
|
-
has_rdoc: true
|
62
63
|
homepage: https://github.com/rodjek/rspec-puppet/
|
63
64
|
licenses: []
|
64
65
|
|
@@ -68,23 +69,27 @@ rdoc_options: []
|
|
68
69
|
require_paths:
|
69
70
|
- lib
|
70
71
|
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
71
73
|
requirements:
|
72
74
|
- - ">="
|
73
75
|
- !ruby/object:Gem::Version
|
76
|
+
hash: 3
|
74
77
|
segments:
|
75
78
|
- 0
|
76
79
|
version: "0"
|
77
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
78
82
|
requirements:
|
79
83
|
- - ">="
|
80
84
|
- !ruby/object:Gem::Version
|
85
|
+
hash: 3
|
81
86
|
segments:
|
82
87
|
- 0
|
83
88
|
version: "0"
|
84
89
|
requirements: []
|
85
90
|
|
86
91
|
rubyforge_project:
|
87
|
-
rubygems_version: 1.
|
92
|
+
rubygems_version: 1.8.6
|
88
93
|
signing_key:
|
89
94
|
specification_version: 3
|
90
95
|
summary: RSpec tests for your Puppet manifests
|