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:
4430``` ruby
45- # /spec
46- base_dir = File .dirname(File .expand_path(__FILE__ ))
47-
4831RSpec .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' )
32+ c.module_path = File .join(File .dirname(File .expand_path(__FILE__ )), ' fixtures' , ' modules' )
5233 c.environmentpath = File .join(Dir .pwd, ' spec' )
53-
34+ c.manifest = File .join( File .dirname( File .expand_path( __FILE__ )), ' fixtures ' , ' manifests ' , ' site.pp ' )
5435 # Coverage generation
5536 c.after(:suite ) do
5637 RSpec ::Puppet ::Coverage .report!
@@ -69,125 +50,83 @@ RSpec.configure do |c|
6950end
7051```
7152
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-
7953#### module\_ path
8054Type | Default | Puppet Version(s)
8155------ | -------- | ------------------
82- String | Required | 2.x, 3.x, 4.x, 5.x
56+ String | Required | any
8357
8458The path to the directory containing your Puppet modules.
8559
8660#### default\_ facts
8761Type | Default | Puppet Version(s)
8862---- | ------- | ------------------
89- Hash | ` {} ` | 2.x, 3.x, 4.x, 5.x
63+ Hash | ` {} ` | any
9064
9165A hash of default facts that should be used for all the tests.
9266
9367#### hiera\_ config
9468Type | Default | Puppet Version(s)
9569------ | ------------- | -----------------
96- String | ` "/dev/null" ` | 3.x, 4.x, 5.x
70+ String | ` "/dev/null" ` | any
9771
9872The path to your ` hiera.yaml ` file (if used).
9973
10074#### default\_ node\_ params
10175Type | Default | Puppet Version(s)
10276---- | ------- | -----------------
103- Hash | ` {} ` | 4.x, 5.x
77+ Hash | ` {} ` | any
10478
10579A hash of default node parameters that should be used for all the tests.
10680
10781#### default\_ trusted\_ facts
10882Type | Default | Puppet Version(s)
10983---- | ------- | -----------------
110- Hash | ` {} ` | 4.x, 5.x
84+ Hash | ` {} ` | any
11185
11286A 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 ` .
87+ (available in the manifests as the ` $trusted ` hash).
11588
11689#### trusted\_ node\_ data
11790Type | Default | Puppet Version(s)
11891------- | ------- | -----------------
119- Boolean | ` false ` | >=3.4, 4.x, 5.x
92+ Boolean | ` false ` | any
12093
12194Configures rspec-puppet to use the ` $trusted ` hash when compiling the
12295catalogues.
12396
12497#### trusted\_ server\_ facts
12598Type | Default | Puppet Version(s)
12699------- | ------- | -----------------
127- Boolean | ` false ` | >=4.3, 5.x
100+ Boolean | ` false ` | any
128101
129102Configures rspec-puppet to use the ` $server_facts ` hash when compiling the
130103catalogues.
131104
132105#### confdir
133106Type | Default | Puppet Version(s)
134107------ | --------------- | ------------------
135- String | ` "/etc/puppet" ` | 2.x, 3.x, 4.x, 5.x
108+ String | ` "/etc/puppet" ` | any
136109
137110The path to the main Puppet configuration directory.
138111
139112#### config
140113Type | Default | Puppet Version(s)
141114------ | ---------------------- | ------------------
142- String | Puppet's default value | 2.x, 3.x, 4.x, 5.x
115+ String | Puppet's default value | any
143116
144117The path to ` puppet.conf ` .
145118
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-
161119#### environmentpath
162120Type | Default | Puppet Version(s)
163121------ | ------------------------------------- | -----------------
164- String | ` "/etc/puppetlabs/code/environments" ` | 4.x, 5.x
122+ String | ` "/etc/puppetlabs/code/environments" ` | any
165123
166124The search path for environment directories.
167125
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-
187126#### strict\_ variables
188127Type | Default | Puppet Version(s)
189128------- | ------- | -----------------
190- Boolean | ` false ` | >= 3.5, 4.x, 5.x
129+ Boolean | ` false ` | any
191130
192131Makes Puppet raise an error when it tries to reference a variable that hasn't
193132been defined (not including variables that have been explicitly set to
@@ -196,15 +135,15 @@ been defined (not including variables that have been explicitly set to
196135#### stringify\_ facts
197136Type | Default | Puppet Version(s)
198137------- | ------- | -----------------
199- Boolean | ` true ` | >= 3.3, 4.x, 5.x
138+ Boolean | ` true ` | any
200139
201140Makes rspec-puppet coerce all the fact values into strings (matching the
202141behaviour of older versions of Puppet).
203142
204143#### enable\_ pathname\_ stubbing
205144Type | Default | Puppet Version(s)
206145------- | ------- | ------------------
207- Boolean |` false ` | 2.x, 3.x, 4.x, 5.x
146+ Boolean |` false ` | any
208147
209148Configures rspec-puppet to stub out ` Pathname#absolute? ` with it's own
210149implementation. This should only be enabled if you're running into an issue
@@ -214,15 +153,15 @@ functions, etc) that use `Pathname#absolute?`.
214153#### setup\_ fixtures
215154Type | Default | Puppet Version(s)
216155------- | ------- | ------------------
217- Boolean | ` true ` | 2.x, 3.x, 4.x, 5.x
156+ Boolean | ` true ` | any
218157
219158Configures rspec-puppet to automatically create a link from the root of your
220159module to ` spec/fixtures/<module name> ` at the beginning of the test run.
221160
222161#### derive\_ node\_ facts\_ from\_ nodename
223162Type | Default | Puppet Version(s)
224163------- | ------- | -----------------
225- Boolean | ` true ` | 2.x, 3.x, 4.x, 5.x
164+ Boolean | ` true ` | any
226165
227166If ` true ` , rspec-puppet will override the ` fdqn ` , ` hostname ` , and ` domain `
228167facts with values that it derives from the node name (specified with
@@ -235,7 +174,7 @@ setting to `false`.
235174#### facter\_ implementation
236175Type | Default | Puppet Version(s)
237176------- | -------- | -----------------
238- String | ` facter ` | 6.25+, 7.12+
177+ String | ` facter ` | any
239178
240179Configures rspec-puppet to use a specific Facter implementation for running
241180unit tests. If the ` rspec ` implementation is set and Puppet does not support
@@ -699,8 +638,6 @@ RSpec.configure do |c|
699638end
700639```
701640
702- ** NOTE** Setting top-scope variables is not supported in Puppet < 3.0.
703-
704641#### Specifying extra code to load (pre-conditions)
705642
706643If the manifest being tested relies on another class or variables to be set, these can be added via
@@ -752,7 +689,7 @@ let(:module_path) { '/path/to/your/module/dir' }
752689
753690#### Specifying trusted facts
754691
755- When testing with Puppet >= 4.3 the trusted facts hash will have the standard trusted fact keys
692+ The trusted facts hash will have the standard trusted fact keys
756693(certname, domain, and hostname) populated based on the node name (as set with ` :node ` ).
757694
758695By default, the test environment contains no custom trusted facts (as usually obtained
777714
778715#### Specifying trusted external data
779716
780- When testing with Puppet >= 6.14, the trusted facts hash will have an additional ` external `
781- key for trusted external data.
717+ The trusted facts hash will have an ` external ` key for trusted external data.
782718
783719By default, the test environment contains no trusted external data (as usually obtained from
784720trusted external commands and found in the ` external ` key). If you need to test against specific
0 commit comments