rspec-puppet 2.11.0 → 4.0.0
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 +4 -4
- data/CHANGELOG.md +154 -469
- data/README.md +71 -168
- data/bin/rspec-puppet-init +4 -3
- data/lib/rspec-puppet/adapters.rb +84 -230
- data/lib/rspec-puppet/cache.rb +3 -2
- data/lib/rspec-puppet/consts.rb +16 -14
- data/lib/rspec-puppet/coverage.rb +37 -42
- data/lib/rspec-puppet/errors.rb +6 -6
- data/lib/rspec-puppet/example/class_example_group.rb +3 -1
- data/lib/rspec-puppet/example/define_example_group.rb +3 -1
- data/lib/rspec-puppet/example/function_example_group.rb +42 -57
- data/lib/rspec-puppet/example/host_example_group.rb +3 -1
- data/lib/rspec-puppet/example/provider_example_group.rb +2 -0
- data/lib/rspec-puppet/example/type_alias_example_group.rb +4 -2
- data/lib/rspec-puppet/example/type_example_group.rb +3 -1
- data/lib/rspec-puppet/example.rb +6 -9
- data/lib/rspec-puppet/facter_impl.rb +11 -10
- data/lib/rspec-puppet/matchers/allow_value.rb +10 -10
- data/lib/rspec-puppet/matchers/compile.rb +54 -61
- data/lib/rspec-puppet/matchers/count_generic.rb +18 -18
- data/lib/rspec-puppet/matchers/create_generic.rb +69 -79
- data/lib/rspec-puppet/matchers/dynamic_matchers.rb +15 -4
- data/lib/rspec-puppet/matchers/include_class.rb +5 -4
- data/lib/rspec-puppet/matchers/parameter_matcher.rb +11 -12
- data/lib/rspec-puppet/matchers/raise_error.rb +5 -1
- data/lib/rspec-puppet/matchers/run.rb +41 -42
- data/lib/rspec-puppet/matchers/type_matchers.rb +37 -48
- data/lib/rspec-puppet/matchers.rb +2 -0
- data/lib/rspec-puppet/monkey_patches/win32/registry.rb +7 -5
- data/lib/rspec-puppet/monkey_patches/win32/taskscheduler.rb +3 -1
- data/lib/rspec-puppet/monkey_patches/windows/taskschedulerconstants.rb +208 -205
- data/lib/rspec-puppet/monkey_patches.rb +80 -93
- data/lib/rspec-puppet/rake_task.rb +6 -4
- data/lib/rspec-puppet/raw_string.rb +2 -0
- data/lib/rspec-puppet/sensitive.rb +31 -39
- data/lib/rspec-puppet/setup.rb +45 -56
- data/lib/rspec-puppet/spec_helper.rb +2 -3
- data/lib/rspec-puppet/support.rb +129 -177
- data/lib/rspec-puppet/tasks/release_test.rb +8 -5
- data/lib/rspec-puppet/version.rb +5 -0
- data/lib/rspec-puppet.rb +37 -61
- metadata +18 -15
- data/lib/rspec-puppet/example/application_example_group.rb +0 -19
data/README.md
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
# RSpec tests for your Puppet manifests & modules
|
|
2
|
-
|
|
3
|
-
[](https://github.com/puppetlabs/rspec-puppet/blob/main/CODEOWNERS)
|
|
4
|
+

|
|
5
|
+

|
|
4
6
|
|
|
5
7
|
#### Table of Contents
|
|
6
8
|
|
|
7
9
|
* [Installation](#installation)
|
|
8
10
|
* [Starting out with a new module](#starting-out-with-a-new-module)
|
|
9
|
-
* [Configure manifests for Puppet 4](#configure-manifests-for-puppet-4)
|
|
10
11
|
* [Configuration](#configuration)
|
|
11
12
|
* [Naming conventions](#naming-conventions)
|
|
12
13
|
* [Example groups](#example-groups)
|
|
13
|
-
* [Defined Types
|
|
14
|
+
* [Defined Types and Classes](#defined-types-and-classes)
|
|
14
15
|
* [Functions](#functions)
|
|
15
16
|
* [Hiera integration](#hiera-integration)
|
|
16
17
|
* [Producing coverage reports](#producing-coverage-reports)
|
|
@@ -20,35 +21,17 @@
|
|
|
20
21
|
|
|
21
22
|
gem install rspec-puppet
|
|
22
23
|
|
|
23
|
-
> Note for ruby 1.8 users: while rspec-puppet itself supports ruby 1.8, you'll
|
|
24
|
-
> need to pin rspec itself to `~> 3.1.0`, as later rspec versions do not work
|
|
25
|
-
> on old rubies anymore.
|
|
26
|
-
|
|
27
24
|
## Starting out with a new module
|
|
28
25
|
|
|
29
26
|
When you start out on a new module, create a metadata.json file for your module and then run `rspec-puppet-init` to create the necessary files to configure rspec-puppet for your module's tests.
|
|
30
27
|
|
|
31
|
-
|
|
32
|
-
## Configure manifests for Puppet 4
|
|
33
|
-
|
|
34
|
-
With Puppet 3, the manifest is set to `$manifestdir/site.pp`. However Puppet 4 defaults to an empty value. In order to test manifests you will need to set appropriate settings.
|
|
35
|
-
|
|
36
|
-
Puppet configuration reference for `manifest` can be found online:
|
|
37
|
-
|
|
38
|
-
* Puppet 3: https://docs.puppet.com/puppet/3.8/reference/configuration.html#manifest
|
|
39
|
-
* Puppet 4: https://docs.puppet.com/puppet/4.8/reference/configuration.html#manifest
|
|
40
|
-
|
|
41
28
|
Configuration is typically done in a `spec/spec_helper.rb` file which each of your spec will require. Example code:
|
|
42
|
-
```ruby
|
|
43
|
-
# /spec
|
|
44
|
-
base_dir = File.dirname(File.expand_path(__FILE__))
|
|
45
29
|
|
|
30
|
+
```ruby
|
|
46
31
|
RSpec.configure do |c|
|
|
47
|
-
c.module_path = File.join(
|
|
48
|
-
c.manifest_dir = File.join(base_dir, 'fixtures', 'manifests')
|
|
49
|
-
c.manifest = File.join(base_dir, 'fixtures', 'manifests', 'site.pp')
|
|
32
|
+
c.module_path = File.join(File.dirname(File.expand_path(__FILE__)), 'fixtures', 'modules')
|
|
50
33
|
c.environmentpath = File.join(Dir.pwd, 'spec')
|
|
51
|
-
|
|
34
|
+
c.manifest = File.join(File.dirname(File.expand_path(__FILE__)), 'fixtures', 'manifests', 'site.pp')
|
|
52
35
|
# Coverage generation
|
|
53
36
|
c.after(:suite) do
|
|
54
37
|
RSpec::Puppet::Coverage.report!
|
|
@@ -61,60 +44,59 @@ end
|
|
|
61
44
|
rspec-puppet can be configured by modifying the `RSpec.configure` block in your
|
|
62
45
|
`spec/spec_helper.rb` file.
|
|
63
46
|
|
|
64
|
-
```
|
|
47
|
+
```ruby
|
|
65
48
|
RSpec.configure do |c|
|
|
66
49
|
c.<config option> = <value>
|
|
67
50
|
end
|
|
68
51
|
```
|
|
69
52
|
|
|
70
|
-
#### manifest\_dir
|
|
71
|
-
Type | Default | Puppet Version(s)
|
|
72
|
-
------ | -------- | -----------------
|
|
73
|
-
String | Required | 2.x, 3.x
|
|
74
|
-
|
|
75
|
-
The path to the directory containing your basic manifests like `site.pp`.
|
|
76
|
-
|
|
77
53
|
#### module\_path
|
|
78
54
|
Type | Default | Puppet Version(s)
|
|
79
55
|
------ | -------- | ------------------
|
|
80
|
-
String | Required |
|
|
56
|
+
String | Required | any
|
|
81
57
|
|
|
82
58
|
The path to the directory containing your Puppet modules.
|
|
83
59
|
|
|
84
60
|
#### default\_facts
|
|
85
61
|
Type | Default | Puppet Version(s)
|
|
86
62
|
---- | ------- | ------------------
|
|
87
|
-
Hash | `{}` |
|
|
63
|
+
Hash | `{}` | any
|
|
88
64
|
|
|
89
65
|
A hash of default facts that should be used for all the tests.
|
|
90
66
|
|
|
91
67
|
#### hiera\_config
|
|
92
68
|
Type | Default | Puppet Version(s)
|
|
93
69
|
------ | ------------- | -----------------
|
|
94
|
-
String | `"/dev/null"` |
|
|
70
|
+
String | `"/dev/null"` | any
|
|
95
71
|
|
|
96
72
|
The path to your `hiera.yaml` file (if used).
|
|
97
73
|
|
|
74
|
+
#### manifest
|
|
75
|
+
Type | Default | Puppet Version(s)
|
|
76
|
+
------ | ---------------------- | -----------------
|
|
77
|
+
String | Puppet's default value | any
|
|
78
|
+
|
|
79
|
+
Path to test manifest. Typically `spec/fixtures/manifests/site.pp`.
|
|
80
|
+
|
|
98
81
|
#### default\_node\_params
|
|
99
82
|
Type | Default | Puppet Version(s)
|
|
100
83
|
---- | ------- | -----------------
|
|
101
|
-
Hash | `{}` |
|
|
84
|
+
Hash | `{}` | any
|
|
102
85
|
|
|
103
86
|
A hash of default node parameters that should be used for all the tests.
|
|
104
87
|
|
|
105
88
|
#### default\_trusted\_facts
|
|
106
89
|
Type | Default | Puppet Version(s)
|
|
107
90
|
---- | ------- | -----------------
|
|
108
|
-
Hash | `{}` |
|
|
91
|
+
Hash | `{}` | any
|
|
109
92
|
|
|
110
93
|
A hash of default trusted facts that should be used for all the tests
|
|
111
|
-
(available in the manifests as the `$trusted` hash).
|
|
112
|
-
`trusted_node_data` setting must be set to `true`.
|
|
94
|
+
(available in the manifests as the `$trusted` hash).
|
|
113
95
|
|
|
114
96
|
#### trusted\_node\_data
|
|
115
97
|
Type | Default | Puppet Version(s)
|
|
116
98
|
------- | ------- | -----------------
|
|
117
|
-
Boolean | `false` |
|
|
99
|
+
Boolean | `false` | any
|
|
118
100
|
|
|
119
101
|
Configures rspec-puppet to use the `$trusted` hash when compiling the
|
|
120
102
|
catalogues.
|
|
@@ -122,7 +104,7 @@ catalogues.
|
|
|
122
104
|
#### trusted\_server\_facts
|
|
123
105
|
Type | Default | Puppet Version(s)
|
|
124
106
|
------- | ------- | -----------------
|
|
125
|
-
Boolean | `false` |
|
|
107
|
+
Boolean | `false` | any
|
|
126
108
|
|
|
127
109
|
Configures rspec-puppet to use the `$server_facts` hash when compiling the
|
|
128
110
|
catalogues.
|
|
@@ -130,62 +112,28 @@ catalogues.
|
|
|
130
112
|
#### confdir
|
|
131
113
|
Type | Default | Puppet Version(s)
|
|
132
114
|
------ | --------------- | ------------------
|
|
133
|
-
String | `"/etc/puppet"` |
|
|
115
|
+
String | `"/etc/puppet"` | any
|
|
134
116
|
|
|
135
117
|
The path to the main Puppet configuration directory.
|
|
136
118
|
|
|
137
119
|
#### config
|
|
138
120
|
Type | Default | Puppet Version(s)
|
|
139
121
|
------ | ---------------------- | ------------------
|
|
140
|
-
String | Puppet's default value |
|
|
122
|
+
String | Puppet's default value | any
|
|
141
123
|
|
|
142
124
|
The path to `puppet.conf`.
|
|
143
125
|
|
|
144
|
-
#### manifest
|
|
145
|
-
Type | Default | Puppet Version(s)
|
|
146
|
-
------ | ---------------------- | -----------------
|
|
147
|
-
String | Puppet's default value | 2.x, 3.x
|
|
148
|
-
|
|
149
|
-
The entry-point manifest for Puppet, usually `$manifest_dir/site.pp`.
|
|
150
|
-
|
|
151
|
-
#### template\_dir
|
|
152
|
-
Type | Default | Puppet Version(s)
|
|
153
|
-
------ | ------- | -----------------
|
|
154
|
-
String | `nil` | 2.x, 3.x
|
|
155
|
-
|
|
156
|
-
The path to the directory that Puppet should search for templates that are
|
|
157
|
-
stored outside of modules.
|
|
158
|
-
|
|
159
126
|
#### environmentpath
|
|
160
127
|
Type | Default | Puppet Version(s)
|
|
161
128
|
------ | ------------------------------------- | -----------------
|
|
162
|
-
String | `"/etc/puppetlabs/code/environments"` |
|
|
129
|
+
String | `"/etc/puppetlabs/code/environments"` | any
|
|
163
130
|
|
|
164
131
|
The search path for environment directories.
|
|
165
132
|
|
|
166
|
-
#### parser
|
|
167
|
-
Type | Default | Puppet Version(s)
|
|
168
|
-
------ | ----------- | -----------------
|
|
169
|
-
String | `"current"` | >= 3.2
|
|
170
|
-
|
|
171
|
-
This switches between the 3.x (`current`) and 4.x (`future`) parsers.
|
|
172
|
-
|
|
173
|
-
#### ordering
|
|
174
|
-
Type | Default | Puppet Version(s)
|
|
175
|
-
------ | -------------- | -----------------
|
|
176
|
-
String | `"title-hash"` | >= 3.3, 4.x, 5.x
|
|
177
|
-
|
|
178
|
-
How unrelated resources should be ordered when applying a catalogue.
|
|
179
|
-
* `manifest` - Use the order in which the resources are declared in the
|
|
180
|
-
manifest.
|
|
181
|
-
* `title-hash` - Order the resources randomly, but in a consistent manner
|
|
182
|
-
across runs (the order will only change if the manifest changes).
|
|
183
|
-
* `random` - Order the resources randomly.
|
|
184
|
-
|
|
185
133
|
#### strict\_variables
|
|
186
134
|
Type | Default | Puppet Version(s)
|
|
187
135
|
------- | ------- | -----------------
|
|
188
|
-
Boolean | `false` |
|
|
136
|
+
Boolean | `false` | any
|
|
189
137
|
|
|
190
138
|
Makes Puppet raise an error when it tries to reference a variable that hasn't
|
|
191
139
|
been defined (not including variables that have been explicitly set to
|
|
@@ -194,7 +142,7 @@ been defined (not including variables that have been explicitly set to
|
|
|
194
142
|
#### stringify\_facts
|
|
195
143
|
Type | Default | Puppet Version(s)
|
|
196
144
|
------- | ------- | -----------------
|
|
197
|
-
Boolean | `true` |
|
|
145
|
+
Boolean | `true` | any
|
|
198
146
|
|
|
199
147
|
Makes rspec-puppet coerce all the fact values into strings (matching the
|
|
200
148
|
behaviour of older versions of Puppet).
|
|
@@ -202,7 +150,7 @@ behaviour of older versions of Puppet).
|
|
|
202
150
|
#### enable\_pathname\_stubbing
|
|
203
151
|
Type | Default | Puppet Version(s)
|
|
204
152
|
------- | ------- | ------------------
|
|
205
|
-
Boolean |`false` |
|
|
153
|
+
Boolean |`false` | any
|
|
206
154
|
|
|
207
155
|
Configures rspec-puppet to stub out `Pathname#absolute?` with it's own
|
|
208
156
|
implementation. This should only be enabled if you're running into an issue
|
|
@@ -212,7 +160,7 @@ functions, etc) that use `Pathname#absolute?`.
|
|
|
212
160
|
#### setup\_fixtures
|
|
213
161
|
Type | Default | Puppet Version(s)
|
|
214
162
|
------- | ------- | ------------------
|
|
215
|
-
Boolean | `true` |
|
|
163
|
+
Boolean | `true` | any
|
|
216
164
|
|
|
217
165
|
Configures rspec-puppet to automatically create a link from the root of your
|
|
218
166
|
module to `spec/fixtures/<module name>` at the beginning of the test run.
|
|
@@ -220,7 +168,7 @@ module to `spec/fixtures/<module name>` at the beginning of the test run.
|
|
|
220
168
|
#### derive\_node\_facts\_from\_nodename
|
|
221
169
|
Type | Default | Puppet Version(s)
|
|
222
170
|
------- | ------- | -----------------
|
|
223
|
-
Boolean | `true` |
|
|
171
|
+
Boolean | `true` | any
|
|
224
172
|
|
|
225
173
|
If `true`, rspec-puppet will override the `fdqn`, `hostname`, and `domain`
|
|
226
174
|
facts with values that it derives from the node name (specified with
|
|
@@ -233,7 +181,7 @@ setting to `false`.
|
|
|
233
181
|
#### facter\_implementation
|
|
234
182
|
Type | Default | Puppet Version(s)
|
|
235
183
|
------- | -------- | -----------------
|
|
236
|
-
String | `facter` |
|
|
184
|
+
String | `facter` | any
|
|
237
185
|
|
|
238
186
|
Configures rspec-puppet to use a specific Facter implementation for running
|
|
239
187
|
unit tests. If the `rspec` implementation is set and Puppet does not support
|
|
@@ -261,9 +209,6 @@ structure and naming convention.
|
|
|
261
209
|
├── defines/
|
|
262
210
|
│ └── <define_name>_spec.rb
|
|
263
211
|
│
|
|
264
|
-
├── applications/
|
|
265
|
-
│ └── <application_name>_spec.rb
|
|
266
|
-
│
|
|
267
212
|
├── functions/
|
|
268
213
|
│ └── <function_name>_spec.rb
|
|
269
214
|
│
|
|
@@ -291,10 +236,6 @@ describe 'mydefine', :type => :define do
|
|
|
291
236
|
...
|
|
292
237
|
end
|
|
293
238
|
|
|
294
|
-
describe 'myapplication', :type => :application do
|
|
295
|
-
...
|
|
296
|
-
end
|
|
297
|
-
|
|
298
239
|
describe 'myfunction', :type => :puppet_function do
|
|
299
240
|
...
|
|
300
241
|
end
|
|
@@ -312,7 +253,7 @@ describe 'myhost.example.com', :type => :host do
|
|
|
312
253
|
end
|
|
313
254
|
```
|
|
314
255
|
|
|
315
|
-
## Defined Types
|
|
256
|
+
## Defined Types and Classes
|
|
316
257
|
|
|
317
258
|
### Matchers
|
|
318
259
|
|
|
@@ -603,7 +544,7 @@ let(:title) { 'foo' }
|
|
|
603
544
|
|
|
604
545
|
#### Specifying the parameters to pass to a resources or parameterised class
|
|
605
546
|
|
|
606
|
-
Parameters of a defined type
|
|
547
|
+
Parameters of a defined type or class can be passed defining `:params` in a let,
|
|
607
548
|
and passing it a hash as seen below.
|
|
608
549
|
|
|
609
550
|
```ruby
|
|
@@ -617,8 +558,13 @@ be translated to `undef` when compiling. For example:
|
|
|
617
558
|
let(:params) { {'user' => :undef, ...} }
|
|
618
559
|
```
|
|
619
560
|
|
|
561
|
+
For passing a sensitive value you can use the sensitive function with a value in brackets. For example
|
|
562
|
+
```ruby
|
|
563
|
+
let(:params) { {'password' =>sensitive('secret') } }
|
|
564
|
+
```
|
|
565
|
+
|
|
620
566
|
For references to nodes or resources as seen when using `require` or `before` properties,
|
|
621
|
-
|
|
567
|
+
you can pass the string as an argument to the `ref` helper:
|
|
622
568
|
|
|
623
569
|
```ruby
|
|
624
570
|
let(:params) { 'require' => ref('Package', 'sudoku') }
|
|
@@ -630,18 +576,6 @@ Which translates to:
|
|
|
630
576
|
mydefine { 'mytitle': require => Package['sudoku'] }
|
|
631
577
|
```
|
|
632
578
|
|
|
633
|
-
Another example, for an application setup (when using `app_management`):
|
|
634
|
-
|
|
635
|
-
```ruby
|
|
636
|
-
let(:params) { { 'nodes' => { ref('Node', 'dbnode') => ref('Myapp::Mycomponent', 'myapp') } } }
|
|
637
|
-
```
|
|
638
|
-
|
|
639
|
-
Will translate to:
|
|
640
|
-
|
|
641
|
-
```puppet
|
|
642
|
-
site { myapp { 'myimpl': nodes => { Node['dbnode'] => Myapp::Mycomponent['myimpl'] } } }
|
|
643
|
-
```
|
|
644
|
-
|
|
645
579
|
#### Specifying the FQDN of the test node
|
|
646
580
|
|
|
647
581
|
If the manifest you're testing expects to run on host with a particular name,
|
|
@@ -711,8 +645,6 @@ RSpec.configure do |c|
|
|
|
711
645
|
end
|
|
712
646
|
```
|
|
713
647
|
|
|
714
|
-
**NOTE** Setting top-scope variables is not supported in Puppet < 3.0.
|
|
715
|
-
|
|
716
648
|
#### Specifying extra code to load (pre-conditions)
|
|
717
649
|
|
|
718
650
|
If the manifest being tested relies on another class or variables to be set, these can be added via
|
|
@@ -764,7 +696,7 @@ let(:module_path) { '/path/to/your/module/dir' }
|
|
|
764
696
|
|
|
765
697
|
#### Specifying trusted facts
|
|
766
698
|
|
|
767
|
-
|
|
699
|
+
The trusted facts hash will have the standard trusted fact keys
|
|
768
700
|
(certname, domain, and hostname) populated based on the node name (as set with `:node`).
|
|
769
701
|
|
|
770
702
|
By default, the test environment contains no custom trusted facts (as usually obtained
|
|
@@ -789,8 +721,7 @@ end
|
|
|
789
721
|
|
|
790
722
|
#### Specifying trusted external data
|
|
791
723
|
|
|
792
|
-
|
|
793
|
-
key for trusted external data.
|
|
724
|
+
The trusted facts hash will have an `external` key for trusted external data.
|
|
794
725
|
|
|
795
726
|
By default, the test environment contains no trusted external data (as usually obtained from
|
|
796
727
|
trusted external commands and found in the `external` key). If you need to test against specific
|
|
@@ -832,46 +763,6 @@ You can also use `exported_resources` directly in a test:
|
|
|
832
763
|
it { expect(exported_resources).to contain_file('foo') }
|
|
833
764
|
```
|
|
834
765
|
|
|
835
|
-
#### Testing applications
|
|
836
|
-
|
|
837
|
-
Applications in some ways behave as defined resources, but are more complex so
|
|
838
|
-
require a number of elements already documented above to be combined for testing.
|
|
839
|
-
|
|
840
|
-
A full example of the simplest rspec test for a single component application:
|
|
841
|
-
|
|
842
|
-
```ruby
|
|
843
|
-
require 'spec_helper'
|
|
844
|
-
|
|
845
|
-
describe 'orch_app' do
|
|
846
|
-
let(:node) { 'my_node' }
|
|
847
|
-
let(:title) { 'my_awesome_app' }
|
|
848
|
-
let(:params) do
|
|
849
|
-
{
|
|
850
|
-
'nodes' => {
|
|
851
|
-
ref('Node', node) => ref('Orch_app::Db', title),
|
|
852
|
-
}
|
|
853
|
-
}
|
|
854
|
-
end
|
|
855
|
-
|
|
856
|
-
it { should compile }
|
|
857
|
-
it { should contain_orch_app(title) }
|
|
858
|
-
end
|
|
859
|
-
```
|
|
860
|
-
|
|
861
|
-
Each piece is required:
|
|
862
|
-
|
|
863
|
-
* You must turn on app_management during testing for the handling to work
|
|
864
|
-
* The `:node` definition is required to be set so later on you can reference it in the `:nodes` argument within `:params`
|
|
865
|
-
* Applications act like defined resources, and each require a `:title` to be defined
|
|
866
|
-
* The `:nodes` key in `:params` requires the use of node reference mappings to resource
|
|
867
|
-
mappings. The `ref` keyword allows you to provide these (a normal string will not work).
|
|
868
|
-
|
|
869
|
-
Beyond these requirements, the very basic `should compile` test and other matchers
|
|
870
|
-
as you would expect will work the same as classes and defined resources.
|
|
871
|
-
|
|
872
|
-
**Note:** for the moment, cross-node support is not available and will return an error.
|
|
873
|
-
Ensure you model your tests to be single-node for the time being.
|
|
874
|
-
|
|
875
766
|
## Functions
|
|
876
767
|
|
|
877
768
|
### Matchers
|
|
@@ -982,8 +873,17 @@ Some complex functions require access to the current parser's scope, e.g. for
|
|
|
982
873
|
stubbing other parts of the system.
|
|
983
874
|
|
|
984
875
|
```ruby
|
|
985
|
-
|
|
986
|
-
|
|
876
|
+
context 'when called with top-scope vars foo and bar set' do
|
|
877
|
+
before do
|
|
878
|
+
# :lookupvar is the method on scope that puppet calls internally to
|
|
879
|
+
# resolve the value of a variable.
|
|
880
|
+
allow(scope).to receive(:lookupvar).and_call_original
|
|
881
|
+
allow(scope).to receive(:lookupvar).with('::foo').and_return('Hello')
|
|
882
|
+
allow(scope).to receive(:lookupvar).with('::bar').and_return('World')
|
|
883
|
+
end
|
|
884
|
+
|
|
885
|
+
it { is_expected.to run.with_params().and_return('Hello World') }
|
|
886
|
+
end
|
|
987
887
|
```
|
|
988
888
|
|
|
989
889
|
Note that this does not work when testing manifests which use custom functions. Instead,
|
|
@@ -1096,23 +996,26 @@ end
|
|
|
1096
996
|
```
|
|
1097
997
|
|
|
1098
998
|
Resources declared outside of the module being tested (i.e. forge dependencies)
|
|
1099
|
-
are automatically removed from the coverage report.
|
|
1100
|
-
this though: **prior to Puppet 4.6.0**, resources created by functions
|
|
1101
|
-
(create\_resources(), ensure\_package(), etc) did not have the required
|
|
1102
|
-
information in them to determine which manifest they came from and so can not
|
|
1103
|
-
be excluded from the coverage report.
|
|
999
|
+
are automatically removed from the coverage report.
|
|
1104
1000
|
|
|
1105
1001
|
## Related projects
|
|
1106
1002
|
|
|
1107
1003
|
* [puppetlabs_spec_helper](https://github.com/puppetlabs/puppetlabs_spec_helper): shared spec helpers to setup puppet
|
|
1108
|
-
* [rspec-puppet-augeas](https://github.com/domcleal/rspec-puppet-augeas): RSpec tests for Augeas resources inside Puppet manifests
|
|
1109
|
-
* [jimdo-rspec-puppet-helpers](https://github.com/Jimdo/jimdo-rspec-puppet-helpers): Tests the contents of a file with a source
|
|
1110
|
-
* Ease development of specs
|
|
1111
|
-
* [puppet-catalog_rspec](https://github.com/enterprisemodules/puppet-catalog_rspec): Dump the Puppet Catalog as RSpec code at compile time
|
|
1112
|
-
* [create_specs](https://github.com/alexharv074/create_specs.git): A different implementation that takes a compiled catalog and writes out RSpec code with various options
|
|
1113
1004
|
* Fact providers
|
|
1114
|
-
* [rspec-puppet-facts](https://github.com/
|
|
1115
|
-
|
|
1116
|
-
|
|
1005
|
+
* [rspec-puppet-facts](https://github.com/voxpupuli/rspec-puppet-facts): Simplify your unit tests by looping on every supported Operating System and populating facts.
|
|
1006
|
+
|
|
1007
|
+
For a list of other module development tools see [DevX Tools](https://puppetlabs.github.io/content-and-tooling-team/tools/), or from our trusted Voxpupuli community [here](https://voxpupuli.org/plugins/).
|
|
1008
|
+
|
|
1009
|
+
## Reporting bugs or incorrect results
|
|
1010
|
+
|
|
1011
|
+
If you find a bug in Puppet Lint or its results, please create an issue in the repo issues tracker. Bonus points will be awarded if you also include a patch that fixes the issue.
|
|
1012
|
+
|
|
1013
|
+
## Development
|
|
1014
|
+
|
|
1015
|
+
If you run into an issue with this tool or would like to request a feature you can raise a PR with your suggested changes. Alternatively, you can raise a Github issue with a feature request or to report any bugs. Every other Tuesday the DevX team holds office hours in the Puppet Community Slack, where you can ask questions about this and any other supported tools. This session runs at 15:00 (GMT/BST) for about an hour.
|
|
1016
|
+
|
|
1017
|
+
If you have problems getting this tool up and running, please contact Support.
|
|
1018
|
+
|
|
1019
|
+
## Thank you
|
|
1117
1020
|
|
|
1118
|
-
|
|
1021
|
+
Many thanks to the original author of rspec-puppet Tim Sharpe (@rodjek).
|
data/bin/rspec-puppet-init
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
|
|
4
5
|
|
|
5
6
|
require 'rspec-puppet'
|
|
6
7
|
require 'optparse'
|
|
7
8
|
|
|
8
9
|
options = {
|
|
9
|
-
:
|
|
10
|
+
module_name: nil
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
OptionParser.new do |opts|
|
|
13
|
-
opts.banner =
|
|
14
|
+
opts.banner = 'Usage: rspec-puppet-init [options]'
|
|
14
15
|
|
|
15
16
|
opts.on('-n', '--name NAME', 'The name of the module (override autodetection)') do |v|
|
|
16
17
|
options[:module_name] = v
|