2222
2323 gem install rspec-puppet
2424
25- > Note for ruby 1.8 users: while rspec-puppet itself supports ruby 1.8, you'll
26- > need to pin rspec itself to ` ~> 3.1.0 ` , as later rspec versions do not work
27- > on old rubies anymore.
28-
2925## Starting out with a new module
3026
3127When 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.
3228
33-
34- ## Configure manifests for Puppet 4
35-
36- 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.
37-
38- Puppet configuration reference for ` manifest ` can be found online:
39-
40- * Puppet 3: https://docs.puppet.com/puppet/3.8/reference/configuration.html#manifest
41- * Puppet 4: https://docs.puppet.com/puppet/4.8/reference/configuration.html#manifest
42-
4329Configuration is typically done in a ` spec/spec_helper.rb ` file which each of your spec will require. Example code:
44- ``` ruby
45- # /spec
46- base_dir = File .dirname(File .expand_path(__FILE__ ))
4730
31+ ``` ruby
4832RSpec .configure do |c |
49- c.module_path = File .join(base_dir, ' fixtures' , ' modules' )
50- c.manifest_dir = File .join(base_dir, ' fixtures' , ' manifests' )
51- c.manifest = File .join(base_dir, ' fixtures' , ' manifests' , ' site.pp' )
33+ c.module_path = File .join(File .dirname(File .expand_path(__FILE__ )), ' fixtures' , ' modules' )
5234 c.environmentpath = File .join(Dir .pwd, ' spec' )
53-
35+ c.manifest = File .join( File .dirname( File .expand_path( __FILE__ )), ' fixtures ' , ' manifests ' , ' site.pp ' )
5436 # Coverage generation
5537 c.after(:suite ) do
5638 RSpec ::Puppet ::Coverage .report!
6345rspec-puppet can be configured by modifying the ` RSpec.configure ` block in your
6446` spec/spec_helper.rb ` file.
6547
66- ```
48+ ``` ruby
6749RSpec .configure do |c |
6850 c.< config option> = < value>
6951end
7052```
7153
72- #### manifest\_ dir
73- Type | Default | Puppet Version(s)
74- ------ | -------- | -----------------
75- String | Required | 2.x, 3.x
76-
77- The path to the directory containing your basic manifests like ` site.pp ` .
78-
7954#### module\_ path
8055Type | Default | Puppet Version(s)
8156------ | -------- | ------------------
82- String | Required | 2.x, 3.x, 4.x, 5.x
57+ String | Required | any
8358
8459The path to the directory containing your Puppet modules.
8560
8661#### default\_ facts
8762Type | Default | Puppet Version(s)
8863---- | ------- | ------------------
89- Hash | ` {} ` | 2.x, 3.x, 4.x, 5.x
64+ Hash | ` {} ` | any
9065
9166A hash of default facts that should be used for all the tests.
9267
9368#### hiera\_ config
9469Type | Default | Puppet Version(s)
9570------ | ------------- | -----------------
96- String | ` "/dev/null" ` | 3.x, 4.x, 5.x
71+ String | ` "/dev/null" ` | any
9772
9873The path to your ` hiera.yaml ` file (if used).
9974
75+ #### manifest
76+ Type | Default | Puppet Version(s)
77+ ------ | ---------------------- | -----------------
78+ String | Puppet's default value | any
79+
80+ Path to test manifest. Typically ` spec/fixtures/manifests/site.pp ` .
81+
10082#### default\_ node\_ params
10183Type | Default | Puppet Version(s)
10284---- | ------- | -----------------
103- Hash | ` {} ` | 4.x, 5.x
85+ Hash | ` {} ` | any
10486
10587A hash of default node parameters that should be used for all the tests.
10688
10789#### default\_ trusted\_ facts
10890Type | Default | Puppet Version(s)
10991---- | ------- | -----------------
110- Hash | ` {} ` | 4.x, 5.x
92+ Hash | ` {} ` | any
11193
11294A hash of default trusted facts that should be used for all the tests
113- (available in the manifests as the ` $trusted ` hash). In order to use this, the
114- ` trusted_node_data ` setting must be set to ` true ` .
95+ (available in the manifests as the ` $trusted ` hash).
11596
11697#### trusted\_ node\_ data
11798Type | Default | Puppet Version(s)
11899------- | ------- | -----------------
119- Boolean | ` false ` | >=3.4, 4.x, 5.x
100+ Boolean | ` false ` | any
120101
121102Configures rspec-puppet to use the ` $trusted ` hash when compiling the
122103catalogues.
123104
124105#### trusted\_ server\_ facts
125106Type | Default | Puppet Version(s)
126107------- | ------- | -----------------
127- Boolean | ` false ` | >=4.3, 5.x
108+ Boolean | ` false ` | any
128109
129110Configures rspec-puppet to use the ` $server_facts ` hash when compiling the
130111catalogues.
131112
132113#### confdir
133114Type | Default | Puppet Version(s)
134115------ | --------------- | ------------------
135- String | ` "/etc/puppet" ` | 2.x, 3.x, 4.x, 5.x
116+ String | ` "/etc/puppet" ` | any
136117
137118The path to the main Puppet configuration directory.
138119
139120#### config
140121Type | Default | Puppet Version(s)
141122------ | ---------------------- | ------------------
142- String | Puppet's default value | 2.x, 3.x, 4.x, 5.x
123+ String | Puppet's default value | any
143124
144125The path to ` puppet.conf ` .
145126
146- #### manifest
147- Type | Default | Puppet Version(s)
148- ------ | ---------------------- | -----------------
149- String | Puppet's default value | 2.x, 3.x
150-
151- The entry-point manifest for Puppet, usually ` $manifest_dir/site.pp ` .
152-
153- #### template\_ dir
154- Type | Default | Puppet Version(s)
155- ------ | ------- | -----------------
156- String | ` nil ` | 2.x, 3.x
157-
158- The path to the directory that Puppet should search for templates that are
159- stored outside of modules.
160-
161127#### environmentpath
162128Type | Default | Puppet Version(s)
163129------ | ------------------------------------- | -----------------
164- String | ` "/etc/puppetlabs/code/environments" ` | 4.x, 5.x
130+ String | ` "/etc/puppetlabs/code/environments" ` | any
165131
166132The search path for environment directories.
167133
168- #### parser
169- Type | Default | Puppet Version(s)
170- ------ | ----------- | -----------------
171- String | ` "current" ` | >= 3.2
172-
173- This switches between the 3.x (` current ` ) and 4.x (` future ` ) parsers.
174-
175- #### ordering
176- Type | Default | Puppet Version(s)
177- ------ | -------------- | -----------------
178- String | ` "title-hash" ` | >= 3.3, 4.x, 5.x
179-
180- How unrelated resources should be ordered when applying a catalogue.
181- * ` manifest ` - Use the order in which the resources are declared in the
182- manifest.
183- * ` title-hash ` - Order the resources randomly, but in a consistent manner
184- across runs (the order will only change if the manifest changes).
185- * ` random ` - Order the resources randomly.
186-
187134#### strict\_ variables
188135Type | Default | Puppet Version(s)
189136------- | ------- | -----------------
190- Boolean | ` false ` | >= 3.5, 4.x, 5.x
137+ Boolean | ` false ` | any
191138
192139Makes Puppet raise an error when it tries to reference a variable that hasn't
193140been defined (not including variables that have been explicitly set to
@@ -196,15 +143,15 @@ been defined (not including variables that have been explicitly set to
196143#### stringify\_ facts
197144Type | Default | Puppet Version(s)
198145------- | ------- | -----------------
199- Boolean | ` true ` | >= 3.3, 4.x, 5.x
146+ Boolean | ` true ` | any
200147
201148Makes rspec-puppet coerce all the fact values into strings (matching the
202149behaviour of older versions of Puppet).
203150
204151#### enable\_ pathname\_ stubbing
205152Type | Default | Puppet Version(s)
206153------- | ------- | ------------------
207- Boolean |` false ` | 2.x, 3.x, 4.x, 5.x
154+ Boolean |` false ` | any
208155
209156Configures rspec-puppet to stub out ` Pathname#absolute? ` with it's own
210157implementation. This should only be enabled if you're running into an issue
@@ -214,15 +161,15 @@ functions, etc) that use `Pathname#absolute?`.
214161#### setup\_ fixtures
215162Type | Default | Puppet Version(s)
216163------- | ------- | ------------------
217- Boolean | ` true ` | 2.x, 3.x, 4.x, 5.x
164+ Boolean | ` true ` | any
218165
219166Configures rspec-puppet to automatically create a link from the root of your
220167module to ` spec/fixtures/<module name> ` at the beginning of the test run.
221168
222169#### derive\_ node\_ facts\_ from\_ nodename
223170Type | Default | Puppet Version(s)
224171------- | ------- | -----------------
225- Boolean | ` true ` | 2.x, 3.x, 4.x, 5.x
172+ Boolean | ` true ` | any
226173
227174If ` true ` , rspec-puppet will override the ` fdqn ` , ` hostname ` , and ` domain `
228175facts with values that it derives from the node name (specified with
@@ -235,7 +182,7 @@ setting to `false`.
235182#### facter\_ implementation
236183Type | Default | Puppet Version(s)
237184------- | -------- | -----------------
238- String | ` facter ` | 6.25+, 7.12+
185+ String | ` facter ` | any
239186
240187Configures rspec-puppet to use a specific Facter implementation for running
241188unit tests. If the ` rspec ` implementation is set and Puppet does not support
@@ -699,8 +646,6 @@ RSpec.configure do |c|
699646end
700647```
701648
702- ** NOTE** Setting top-scope variables is not supported in Puppet < 3.0.
703-
704649#### Specifying extra code to load (pre-conditions)
705650
706651If the manifest being tested relies on another class or variables to be set, these can be added via
@@ -752,7 +697,7 @@ let(:module_path) { '/path/to/your/module/dir' }
752697
753698#### Specifying trusted facts
754699
755- When testing with Puppet >= 4.3 the trusted facts hash will have the standard trusted fact keys
700+ The trusted facts hash will have the standard trusted fact keys
756701(certname, domain, and hostname) populated based on the node name (as set with ` :node ` ).
757702
758703By default, the test environment contains no custom trusted facts (as usually obtained
777722
778723#### Specifying trusted external data
779724
780- When testing with Puppet >= 6.14, the trusted facts hash will have an additional ` external `
781- key for trusted external data.
725+ The trusted facts hash will have an ` external ` key for trusted external data.
782726
783727By default, the test environment contains no trusted external data (as usually obtained from
784728trusted external commands and found in the ` external ` key). If you need to test against specific
0 commit comments