puppetlabs_spec_helper 2.7.0 → 3.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 +5 -5
- data/.rspec +1 -1
- data/.rubocop.yml +114 -463
- data/.rubocop_todo.yml +119 -0
- data/.travis.yml +17 -16
- data/CHANGELOG.md +212 -5
- data/CODEOWNERS +2 -0
- data/Gemfile +32 -12
- data/HISTORY.md +498 -0
- data/README.md +81 -98
- data/Rakefile +37 -7
- data/lib/puppetlabs_spec_helper/module_spec_helper.rb +41 -0
- data/lib/puppetlabs_spec_helper/puppet_spec_helper.rb +12 -11
- data/lib/puppetlabs_spec_helper/puppetlabs_spec/files.rb +5 -3
- data/lib/puppetlabs_spec_helper/puppetlabs_spec/fixtures.rb +14 -10
- data/lib/puppetlabs_spec_helper/puppetlabs_spec/matchers.rb +12 -13
- data/lib/puppetlabs_spec_helper/puppetlabs_spec/puppet_internals.rb +20 -17
- data/lib/puppetlabs_spec_helper/puppetlabs_spec_helper.rb +3 -1
- data/lib/puppetlabs_spec_helper/rake_tasks.rb +250 -117
- data/lib/puppetlabs_spec_helper/tasks/beaker.rb +20 -16
- data/lib/puppetlabs_spec_helper/tasks/check_symlinks.rb +52 -0
- data/lib/puppetlabs_spec_helper/tasks/fixtures.rb +301 -167
- data/lib/puppetlabs_spec_helper/version.rb +3 -1
- data/puppet_spec_helper.rb +3 -1
- data/puppetlabs_spec_helper.gemspec +24 -22
- data/puppetlabs_spec_helper.rb +3 -1
- metadata +67 -26
data/README.md
CHANGED
|
@@ -59,7 +59,7 @@ Host github.com
|
|
|
59
59
|
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
Note: parallel downloads
|
|
62
|
+
Note: parallel downloads are available for repositories and forge modules.
|
|
63
63
|
|
|
64
64
|
### Parallel tests
|
|
65
65
|
It is also possible to use the `parallel_tests` Gem via the `:parallel_spec` Rake task to run rspec commands in parallel on groups of spec files.
|
|
@@ -79,8 +79,7 @@ And then to run spec tests in parallel:
|
|
|
79
79
|
Issues
|
|
80
80
|
======
|
|
81
81
|
|
|
82
|
-
Please file issues against this project at the [Puppet Labs Issue
|
|
83
|
-
Tracker](https://tickets.puppetlabs.com/browse/MODULES)
|
|
82
|
+
Please file issues against this project at the [Puppet Labs Issue Tracker](https://tickets.puppetlabs.com/browse/MODULES)
|
|
84
83
|
|
|
85
84
|
The Long Version
|
|
86
85
|
----------------
|
|
@@ -142,9 +141,6 @@ A number of the Puppet parser features, controlled via configuration during a
|
|
|
142
141
|
normal puppet run, can be controlled by exporting specific environment
|
|
143
142
|
variables for the spec run. These are:
|
|
144
143
|
|
|
145
|
-
* ``FUTURE_PARSER`` - set to "yes" to enable the [future parser](http://docs.puppetlabs.com/puppet/latest/reference/experiments_future.html),
|
|
146
|
-
the equivalent of setting [parser=future](http://docs.puppetlabs.com/references/latest/configuration.html#parser)
|
|
147
|
-
in puppet.conf.
|
|
148
144
|
* ``STRICT_VARIABLES`` - set to "yes" to enable set to strict variable checking when using Puppet versions between 3.5 and 4.0;
|
|
149
145
|
set to "no" to disable strict variable checking on Puppet versions 4.0, and later.
|
|
150
146
|
See [strict_variables](http://docs.puppetlabs.com/references/latest/configuration.html#strictvariables)
|
|
@@ -153,14 +149,18 @@ variables for the spec run. These are:
|
|
|
153
149
|
to set the order of unrelated resources when applying a catalog. Leave unset for the default
|
|
154
150
|
behavior, currently "random". This is equivalent to setting [ordering](http://docs.puppetlabs.com/references/latest/configuration.html#ordering)
|
|
155
151
|
in puppet.conf.
|
|
156
|
-
*
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
* ``TRUSTED_NODE_DATA`` - set to "yes" to enable [the $facts hash and trusted node data](
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
152
|
+
* The following options only affect Puppet 3.x:
|
|
153
|
+
* ``FUTURE_PARSER`` _(Puppet 3.x, starting with 3.2)_ - set to "yes" to enable the [future parser](https://docs.puppet.com/puppet/3/experiments_future.html),
|
|
154
|
+
the equivalent of setting [parser=future](https://puppet.com/docs/puppet/3.8/configuration.html#parser)
|
|
155
|
+
in puppet.conf.
|
|
156
|
+
* ``TRUSTED_NODE_DATA`` _(Puppet 3.x, starting with 3.4)_ - set to "yes" to enable [the $facts hash and trusted node data](https://puppet.com/docs/puppet/3.8/lang_facts_and_builtin_vars.html#trusted-facts),
|
|
157
|
+
which enabled ``$facts`` and ``$trusted`` hashes. This is equivalent to setting
|
|
158
|
+
[trusted_node_data=true](https://puppet.com/docs/puppet/3.8/configuration.html#trustednodedata)
|
|
159
|
+
in puppet.conf.
|
|
160
|
+
* ``STRINGIFY_FACTS`` _(Puppet 3.x, starting with 3.5)_ - set to "no" to enable [structured facts](http://docs.puppetlabs.com/facter/2.0/fact_overview.html#writing-structured-facts),
|
|
161
|
+
otherwise leave unset to retain the current default behavior. This is equivalent to setting
|
|
162
|
+
[stringify_facts=false](https://puppet.com/docs/puppet/3.8/configuration.html#stringifyfacts)
|
|
163
|
+
in puppet.conf.
|
|
164
164
|
|
|
165
165
|
As an example, to run spec tests with the future parser, strict variable checking,
|
|
166
166
|
and manifest ordering, you would:
|
|
@@ -191,32 +191,40 @@ file named `.fixtures.yml` in the root of the project. You can specify a alterna
|
|
|
191
191
|
You can use the `MODULE_WORKING_DIR` environment variable to specify a diffent location when installing module fixtures via the forge. By default the
|
|
192
192
|
working directory is `<module directory>/spec/fixtures/work-dir`.
|
|
193
193
|
|
|
194
|
-
When specifying the repo source of the fixture you have a few options as to which revision of the codebase you wish to use.
|
|
194
|
+
When specifying the repo source of the fixture you have a few options as to which revision of the codebase you wish to use, and optionally, the puppet versions where the fixture is needed.
|
|
195
195
|
|
|
196
|
-
* repo - the url to the repo
|
|
197
|
-
* scm - options include git or hg. This is an optional step as the helper code will figure out which scm is used.
|
|
196
|
+
* `repo` - the url to the repo
|
|
197
|
+
* `scm` - options include git or hg. This is an optional step as the helper code will figure out which scm is used.
|
|
198
198
|
|
|
199
199
|
```yaml
|
|
200
200
|
scm: git
|
|
201
201
|
scm: hg
|
|
202
202
|
```
|
|
203
203
|
|
|
204
|
-
* target - the directory name to clone the repo into ie. `target: mymodule` defaults to the repo name (Optional)
|
|
205
|
-
* subdir - directory to be removed from the cloned repo. Its contents will be moved to the root directory (Optional)
|
|
206
|
-
* ref - used to specify the tag name like version hash
|
|
204
|
+
* `target` - the directory name to clone the repo into ie. `target: mymodule` defaults to the repo name (Optional)
|
|
205
|
+
* `subdir` - directory to be removed from the cloned repo. Its contents will be moved to the root directory (Optional)
|
|
206
|
+
* `ref` - used to specify the tag name (like version) or commit hash to be checked out (Optional). Branch names should use the `branch` option instead.
|
|
207
207
|
|
|
208
208
|
```yaml
|
|
209
209
|
ref: 1.0.0
|
|
210
210
|
ref: 880fca52c
|
|
211
211
|
```
|
|
212
|
-
* branch - used to specify the branch name you want to use ie. `branch: development`
|
|
213
|
-
* flags - additional flags passed to the module installer (both puppet and scm)
|
|
212
|
+
* `branch` - used to specify the branch name you want to use ie. `branch: development`
|
|
213
|
+
* `flags` - additional flags passed to the module installer (both puppet and scm)
|
|
214
214
|
|
|
215
215
|
```yaml
|
|
216
216
|
flags: --verbose
|
|
217
217
|
```
|
|
218
|
+
* `puppet_version` - versions of puppet for which the fixture should be installed. Ruby version constraints are supported. Only works when the `semantic_puppet` gem is available (shipped with puppet 4.0 and up, by default).
|
|
219
|
+
|
|
220
|
+
```yaml
|
|
221
|
+
puppet_version: '>= 6.0.0'
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
**Notes:**
|
|
218
225
|
|
|
219
|
-
|
|
226
|
+
* `ref` and `branch` can be used together to get a specific revision on a specific branch
|
|
227
|
+
* Top level `defaults` option could be used to set global options
|
|
220
228
|
|
|
221
229
|
Fixtures Examples
|
|
222
230
|
-----------------
|
|
@@ -252,7 +260,7 @@ fixtures:
|
|
|
252
260
|
target: "spec/fixtures/control_repos"
|
|
253
261
|
```
|
|
254
262
|
|
|
255
|
-
Specify that the git tag `2.4.2` of `stdlib
|
|
263
|
+
Specify that the git tag `2.4.2` of `stdlib` should be checked out:
|
|
256
264
|
|
|
257
265
|
```yaml
|
|
258
266
|
fixtures:
|
|
@@ -263,6 +271,16 @@ fixtures:
|
|
|
263
271
|
ref: "2.6.0"
|
|
264
272
|
```
|
|
265
273
|
|
|
274
|
+
Only install the `yumrepo_core` module when testing against Puppet 6 or greater:
|
|
275
|
+
|
|
276
|
+
```yaml
|
|
277
|
+
fixtures:
|
|
278
|
+
repositories:
|
|
279
|
+
yumrepo_core:
|
|
280
|
+
repo: "git://github.com/puppetlabs/puppetlabs-yumrepo_core"
|
|
281
|
+
puppet_version: ">= 6.0.0"
|
|
282
|
+
```
|
|
283
|
+
|
|
266
284
|
Move manifests and siblings to root directory when they are inside a `code` directory:
|
|
267
285
|
|
|
268
286
|
```yaml
|
|
@@ -300,6 +318,27 @@ fixtures:
|
|
|
300
318
|
flags: "--verbose"
|
|
301
319
|
```
|
|
302
320
|
|
|
321
|
+
Use `defaults` to define global parameters:
|
|
322
|
+
|
|
323
|
+
```yaml
|
|
324
|
+
defaults:
|
|
325
|
+
forge_modules:
|
|
326
|
+
flags: "--module_repository https://my_repo.com"
|
|
327
|
+
fixtures:
|
|
328
|
+
forge_modules:
|
|
329
|
+
stdlib:
|
|
330
|
+
repo: "puppetlabs/stdlib"
|
|
331
|
+
ref: "2.6.0"
|
|
332
|
+
repositories:
|
|
333
|
+
firewall:
|
|
334
|
+
repo: "git://github.com/puppetlabs/puppetlabs-firewall"
|
|
335
|
+
ref: "2.6.0"
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
Fixture Loading
|
|
339
|
+
---------------
|
|
340
|
+
Any module that has a `spec/lib` directory will be available on the ruby `LOAD_PATH` for tests to consume. This allows modules to provide additional helper code to be supplied. The [augeasprovider_core](https://github.com/hercules-team/augeasproviders_core) module has [some examples](https://github.com/hercules-team/augeasproviders_core/tree/master/spec/lib).
|
|
341
|
+
|
|
303
342
|
Testing Parser Functions
|
|
304
343
|
========================
|
|
305
344
|
|
|
@@ -347,12 +386,16 @@ remembering to duplicate any existing environment variables:
|
|
|
347
386
|
- FUTURE_PARSER=yes CI_NODE_TOTAL=2 CI_NODE_INDEX=2
|
|
348
387
|
|
|
349
388
|
#### Running tests tagged with test tiers
|
|
350
|
-
To run tests tagged with risk levels set the ``TEST_TIERS`` environment variable to a comma-separated list of
|
|
351
|
-
the appropriate tiers.
|
|
389
|
+
To run tests tagged with risk levels set the ``TEST_TIERS`` environment variable to a comma-separated list of the appropriate tiers.
|
|
352
390
|
|
|
353
391
|
For example: to run tests marked ``tier_high => true`` and ``tier_medium => true`` in the same test run set the
|
|
354
392
|
environment variable``TEST_TIERS=high,medium``
|
|
355
393
|
|
|
394
|
+
By default ``TEST_TIERS`` only accepts low, medium and high as valid tiers. If you would like to use your own keywords to set the environment variable ``TEST_TIERS_ALLOWED``.
|
|
395
|
+
|
|
396
|
+
For example: to use the keywords dev, rnd, staging and production you can set
|
|
397
|
+
``TEST_TIERS_ALLOWED=dev,rnd,staging,production``. Then you would be able to run tests marked ``tier_dev => true``, ``tier_production => true`` with ``TEST_TIERS=dev,production``
|
|
398
|
+
|
|
356
399
|
Note, if the ``TEST_TIERS`` environment variable is set to empty string or nil, all tiers will be executed.
|
|
357
400
|
|
|
358
401
|
|
|
@@ -364,80 +407,20 @@ See the documentation of [RSpec-Puppet](https://github.com/rodjek/rspec-puppet)
|
|
|
364
407
|
for Puppet manifest coverage reports.
|
|
365
408
|
|
|
366
409
|
Starting with Ruby 1.9, the *de facto* standard for Ruby code coverage is
|
|
367
|
-
[SimpleCov](https://github.com/colszowka/simplecov).
|
|
368
|
-
You can add it to your module like this:
|
|
369
|
-
|
|
370
|
-
```Ruby
|
|
371
|
-
# First line of spec/spec_helper.rb
|
|
372
|
-
require 'simplecov'
|
|
373
|
-
|
|
374
|
-
SimpleCov.start do
|
|
375
|
-
add_filter '/spec/'
|
|
376
|
-
# Exclude bundled Gems in `/.vendor/`
|
|
377
|
-
add_filter '/.vendor/'
|
|
378
|
-
end
|
|
410
|
+
[SimpleCov](https://github.com/colszowka/simplecov). It is implemented as a Rake task in this gem.
|
|
379
411
|
|
|
380
|
-
|
|
381
|
-
# Further content
|
|
382
|
-
```
|
|
383
|
-
|
|
384
|
-
The reports will then be generated every time you invoke RSpec, e.g. via `rake spec`,
|
|
385
|
-
and are written to `/coverage/`, which you should add to `.gitignore`.
|
|
386
|
-
|
|
387
|
-
Remember to add `gem 'simplecov', require: false` to your `Gemfile`.
|
|
412
|
+
To run code coverage:
|
|
388
413
|
|
|
389
|
-
|
|
390
|
-
------------------
|
|
414
|
+
$ rake spec:simplecov
|
|
391
415
|
|
|
392
|
-
|
|
416
|
+
Reports are written to `/coverage/`, which you should add to `.gitignore`.
|
|
393
417
|
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
require 'codeclimate-test-reporter'
|
|
397
|
-
|
|
398
|
-
SimpleCov.formatters = [
|
|
399
|
-
SimpleCov::Formatter::HTMLFormatter,
|
|
400
|
-
CodeClimate::TestReporter::Formatter
|
|
401
|
-
]
|
|
402
|
-
|
|
403
|
-
SimpleCov.start do
|
|
404
|
-
add_filter '/spec/'
|
|
405
|
-
# Exclude bundled Gems in `/.vendor/`
|
|
406
|
-
add_filter '/.vendor/'
|
|
407
|
-
end
|
|
418
|
+
The reports can be generated every time you invoke RSpec, e.g. via `rake spec`,
|
|
419
|
+
You can enable it, set the following environment variable:s
|
|
408
420
|
|
|
409
|
-
|
|
410
|
-
# Further content
|
|
411
|
-
```
|
|
412
|
-
|
|
413
|
-
Remember to add `gem 'codeclimate-test-reporter', require: false` to your `Gemfile`.
|
|
414
|
-
|
|
415
|
-
Using Coveralls
|
|
416
|
-
---------------
|
|
417
|
-
|
|
418
|
-
You can also use [Coveralls](https://coveralls.io/) together with SimpleCov:
|
|
419
|
-
|
|
420
|
-
```Ruby
|
|
421
|
-
# First line of spec/spec_helper.rb
|
|
422
|
-
require 'simplecov'
|
|
423
|
-
require 'coveralls'
|
|
424
|
-
|
|
425
|
-
SimpleCov.formatters = [
|
|
426
|
-
SimpleCov::Formatter::HTMLFormatter,
|
|
427
|
-
Coveralls::SimpleCov::Formatter
|
|
428
|
-
]
|
|
429
|
-
|
|
430
|
-
SimpleCov.start do
|
|
431
|
-
add_filter '/spec/'
|
|
432
|
-
# Exclude bundled Gems in `/.vendor/`
|
|
433
|
-
add_filter '/.vendor/'
|
|
434
|
-
end
|
|
435
|
-
|
|
436
|
-
require 'puppetlabs_spec_helper/module_spec_helper'
|
|
437
|
-
# Further content
|
|
438
|
-
```
|
|
421
|
+
``SIMPLECOV=yes``
|
|
439
422
|
|
|
440
|
-
Remember to add
|
|
423
|
+
Remember to add the simplecov-console and codecov gems to your `Gemfile`. If you run `spec:simplecov` on Travis-CI or any of the other supported CI services, reports gets automatically uploaded to https://codecov.io/ .
|
|
441
424
|
|
|
442
425
|
Some Notes for Windows Users
|
|
443
426
|
============================
|
|
@@ -466,7 +449,7 @@ The following links may give you some insight into why...
|
|
|
466
449
|
mock_with
|
|
467
450
|
=========
|
|
468
451
|
|
|
469
|
-
There are two major mocking frameworks in modules test suites today: [mocha](https://rubygems.org/gems/mocha) and [rspec-mocks](https://rubygems.org/gems/rspec-mocks).
|
|
452
|
+
There are two major mocking frameworks in modules test suites today: [mocha](https://rubygems.org/gems/mocha) and [rspec-mocks](https://rubygems.org/gems/rspec-mocks). We recommend that you choose rspec-mocks explicitly by specifying `mock_with`, either in your `spec_helper.rb` like so:
|
|
470
453
|
|
|
471
454
|
```
|
|
472
455
|
RSpec.configure do |c|
|
|
@@ -475,7 +458,7 @@ end
|
|
|
475
458
|
require 'puppetlabs_spec_helper/module_spec_helper'
|
|
476
459
|
```
|
|
477
460
|
|
|
478
|
-
or by using
|
|
461
|
+
or by using Puppet Development Kit's [`mock_with` option in `.sync.yml`](https://github.com/puppetlabs/pdk-templates#specspec_helperrb) and `pdk update`.
|
|
479
462
|
|
|
480
463
|
You can also continue to use mocha by explicitly specifying `:mocha`, following the [mocha documentation](http://gofreerange.com/mocha/docs/).
|
|
481
464
|
|
|
@@ -490,7 +473,7 @@ context.stubs(:some_method).with(arguments).returns('value')
|
|
|
490
473
|
```
|
|
491
474
|
to this:
|
|
492
475
|
```
|
|
493
|
-
allow(context).to receive(:some_method).with(arguments).
|
|
476
|
+
allow(context).to receive(:some_method).with(arguments).and_return('value')
|
|
494
477
|
```
|
|
495
478
|
|
|
496
479
|
Translate all expectations:
|
|
@@ -499,7 +482,7 @@ context.expects(:some_method).with(arguments).returns('value')
|
|
|
499
482
|
```
|
|
500
483
|
to this:
|
|
501
484
|
```
|
|
502
|
-
expect(context).to receive(:some_method).with(arguments).
|
|
485
|
+
expect(context).to receive(:some_method).with(arguments).and_return('value')
|
|
503
486
|
```
|
|
504
487
|
|
|
505
488
|
Rationale
|
data/Rakefile
CHANGED
|
@@ -1,15 +1,45 @@
|
|
|
1
|
-
#
|
|
2
|
-
require "bundler/gem_tasks"
|
|
3
|
-
require "rspec/core/rake_task"
|
|
1
|
+
# frozen_string_literal: true
|
|
4
2
|
|
|
5
|
-
|
|
3
|
+
require 'bundler/gem_tasks'
|
|
4
|
+
require 'rspec/core/rake_task'
|
|
5
|
+
|
|
6
|
+
def gem_present(name)
|
|
7
|
+
!Bundler.rubygems.find_name(name).empty?
|
|
8
|
+
end
|
|
6
9
|
|
|
7
10
|
RSpec::Core::RakeTask.new(:spec) do |spec|
|
|
8
11
|
spec.pattern = FileList['spec/**/*_spec.rb'].exclude('spec/fixtures/**/*_spec.rb')
|
|
9
12
|
end
|
|
10
13
|
|
|
11
|
-
require 'rubocop/rake_task'
|
|
12
|
-
RuboCop::RakeTask.new
|
|
13
|
-
|
|
14
14
|
require 'yard'
|
|
15
15
|
YARD::Rake::YardocTask.new
|
|
16
|
+
|
|
17
|
+
default_tasks = [:spec]
|
|
18
|
+
|
|
19
|
+
if gem_present 'rubocop'
|
|
20
|
+
require 'rubocop/rake_task'
|
|
21
|
+
RuboCop::RakeTask.new
|
|
22
|
+
default_tasks.unshift(:rubocop)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
task default: default_tasks
|
|
26
|
+
|
|
27
|
+
#### CHANGELOG ####
|
|
28
|
+
begin
|
|
29
|
+
require 'github_changelog_generator/task'
|
|
30
|
+
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
|
|
31
|
+
require 'puppetlabs_spec_helper/version'
|
|
32
|
+
config.since_tag = 'v2.8.0'
|
|
33
|
+
config.future_release = "v#{PuppetlabsSpecHelper::VERSION}"
|
|
34
|
+
config.header = "# Changelog\n\n" \
|
|
35
|
+
"All significant changes to this repo will be summarized in this file.\n"
|
|
36
|
+
# config.include_labels = %w[enhancement bug]
|
|
37
|
+
config.user = 'puppetlabs'
|
|
38
|
+
config.project = 'puppetlabs_spec_helper'
|
|
39
|
+
end
|
|
40
|
+
rescue LoadError
|
|
41
|
+
desc 'Install github_changelog_generator to get access to automatic changelog generation'
|
|
42
|
+
task :changelog do
|
|
43
|
+
raise 'Install github_changelog_generator to get access to automatic changelog generation'
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'rspec-puppet'
|
|
2
4
|
require 'puppetlabs_spec_helper/puppet_spec_helper'
|
|
3
5
|
require 'puppetlabs_spec_helper/puppetlabs_spec/puppet_internals'
|
|
@@ -18,6 +20,45 @@ env_module_path = ENV['MODULEPATH']
|
|
|
18
20
|
module_path = File.join(fixture_path, 'modules')
|
|
19
21
|
|
|
20
22
|
module_path = [module_path, env_module_path].join(File::PATH_SEPARATOR) if env_module_path
|
|
23
|
+
if ENV['SIMPLECOV'] == 'yes'
|
|
24
|
+
begin
|
|
25
|
+
require 'simplecov'
|
|
26
|
+
require 'simplecov-console'
|
|
27
|
+
require 'codecov'
|
|
28
|
+
|
|
29
|
+
SimpleCov.formatters = [
|
|
30
|
+
SimpleCov::Formatter::HTMLFormatter,
|
|
31
|
+
SimpleCov::Formatter::Console,
|
|
32
|
+
SimpleCov::Formatter::Codecov,
|
|
33
|
+
]
|
|
34
|
+
SimpleCov.start do
|
|
35
|
+
track_files 'lib/**/*.rb'
|
|
36
|
+
add_filter '/spec'
|
|
37
|
+
|
|
38
|
+
# do not track vendored files
|
|
39
|
+
add_filter '/vendor'
|
|
40
|
+
add_filter '/.vendor'
|
|
41
|
+
|
|
42
|
+
# do not track gitignored files
|
|
43
|
+
# this adds about 4 seconds to the coverage check
|
|
44
|
+
# this could definitely be optimized
|
|
45
|
+
add_filter do |f|
|
|
46
|
+
# system returns true if exit status is 0, which with git-check-ignore means file is ignored
|
|
47
|
+
system("git check-ignore --quiet #{f.filename}")
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
rescue LoadError
|
|
51
|
+
raise 'Add the simplecov, simplecov-console, codecov gems to Gemfile to enable this task'
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Add all spec lib dirs to LOAD_PATH
|
|
56
|
+
components = module_path.split(File::PATH_SEPARATOR).collect do |dir|
|
|
57
|
+
Dir.entries(dir).reject { |f| f =~ %r{^\.} }.collect { |f| File.join(dir, f, 'spec', 'lib') }
|
|
58
|
+
end
|
|
59
|
+
components.flatten.each do |d|
|
|
60
|
+
$LOAD_PATH << d if FileTest.directory?(d) && !$LOAD_PATH.include?(d)
|
|
61
|
+
end
|
|
21
62
|
|
|
22
63
|
RSpec.configure do |c|
|
|
23
64
|
c.environmentpath = spec_path if Puppet.version.to_f >= 4.0
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'puppetlabs_spec_helper/puppetlabs_spec_helper'
|
|
2
4
|
|
|
3
5
|
# Don't want puppet getting the command line arguments for rake or autotest
|
|
@@ -13,7 +15,7 @@ require 'rspec/expectations'
|
|
|
13
15
|
# See also below in RSpec.configure
|
|
14
16
|
if RSpec.configuration.instance_variable_get(:@mock_framework).nil?
|
|
15
17
|
# This is needed because we're using mocha with rspec instead of Test::Unit or MiniTest
|
|
16
|
-
ENV['MOCHA_OPTIONS']='skip_integration'
|
|
18
|
+
ENV['MOCHA_OPTIONS'] = 'skip_integration'
|
|
17
19
|
|
|
18
20
|
# Current versions of RSpec already load this for us, but who knows what's used out there?
|
|
19
21
|
require 'mocha/api'
|
|
@@ -45,7 +47,7 @@ require 'puppetlabs_spec_helper/puppetlabs_spec/files'
|
|
|
45
47
|
# to compatibility mode for older versions of puppet.
|
|
46
48
|
begin
|
|
47
49
|
require 'puppet/test/test_helper'
|
|
48
|
-
rescue LoadError
|
|
50
|
+
rescue LoadError
|
|
49
51
|
end
|
|
50
52
|
|
|
51
53
|
# This is just a utility class to allow us to isolate the various version-specific
|
|
@@ -58,7 +60,7 @@ module Puppet
|
|
|
58
60
|
# Puppet's Settings singleton object, and other fun implementation details
|
|
59
61
|
# that code external to puppet should really never know about.
|
|
60
62
|
def self.initialize_via_fallback_compatibility(config)
|
|
61
|
-
|
|
63
|
+
warn('Warning: you appear to be using an older version of puppet; spec_helper will use fallback compatibility mode.')
|
|
62
64
|
config.before :all do
|
|
63
65
|
# nothing to do for now
|
|
64
66
|
end
|
|
@@ -79,11 +81,11 @@ module Puppet
|
|
|
79
81
|
|
|
80
82
|
# Set the confdir and vardir to gibberish so that tests
|
|
81
83
|
# have to be correctly mocked.
|
|
82
|
-
Puppet[:confdir] =
|
|
83
|
-
Puppet[:vardir] =
|
|
84
|
+
Puppet[:confdir] = '/dev/null'
|
|
85
|
+
Puppet[:vardir] = '/dev/null'
|
|
84
86
|
|
|
85
87
|
# Avoid opening ports to the outside world
|
|
86
|
-
Puppet.settings[:bindaddress] =
|
|
88
|
+
Puppet.settings[:bindaddress] = '127.0.0.1'
|
|
87
89
|
end
|
|
88
90
|
|
|
89
91
|
config.after :each do
|
|
@@ -91,7 +93,7 @@ module Puppet
|
|
|
91
93
|
|
|
92
94
|
Puppet::Node::Environment.clear
|
|
93
95
|
Puppet::Util::Storage.clear
|
|
94
|
-
Puppet::Util::ExecutionStub.reset if Puppet::Util.constants.include?
|
|
96
|
+
Puppet::Util::ExecutionStub.reset if Puppet::Util.constants.include? 'ExecutionStub'
|
|
95
97
|
|
|
96
98
|
PuppetlabsSpec::Files.cleanup
|
|
97
99
|
end
|
|
@@ -100,7 +102,7 @@ module Puppet
|
|
|
100
102
|
end
|
|
101
103
|
|
|
102
104
|
# JJM Hack to make the stdlib tests run in Puppet 2.6 (See puppet commit cf183534)
|
|
103
|
-
|
|
105
|
+
unless Puppet.constants.include? 'Test'
|
|
104
106
|
module Puppet::Test
|
|
105
107
|
class LogCollector
|
|
106
108
|
def initialize(logs)
|
|
@@ -113,7 +115,7 @@ if not Puppet.constants.include? "Test" then
|
|
|
113
115
|
end
|
|
114
116
|
end
|
|
115
117
|
Puppet::Util::Log.newdesttype :log_collector do
|
|
116
|
-
match
|
|
118
|
+
match 'Puppet::Test::LogCollector'
|
|
117
119
|
|
|
118
120
|
def initialize(messages)
|
|
119
121
|
@messages = messages
|
|
@@ -137,7 +139,7 @@ RSpec.configure do |config|
|
|
|
137
139
|
end
|
|
138
140
|
|
|
139
141
|
# determine whether we can use the new API or not, and call the appropriate initializer method.
|
|
140
|
-
if
|
|
142
|
+
if defined?(Puppet::Test::TestHelper)
|
|
141
143
|
# This case is handled by rspec-puppet since v1.0.0 (via 41257b33cb1f9ade4426b044f70be511b0c89112)
|
|
142
144
|
else
|
|
143
145
|
Puppet::PuppetSpecInitializer.initialize_via_fallback_compatibility(config)
|
|
@@ -173,5 +175,4 @@ RSpec.configure do |config|
|
|
|
173
175
|
Puppet::Util::Log.close_all
|
|
174
176
|
Puppet::Util::Log.level = @log_level
|
|
175
177
|
end
|
|
176
|
-
|
|
177
178
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'fileutils'
|
|
2
4
|
require 'tempfile'
|
|
3
5
|
require 'pathname'
|
|
@@ -18,11 +20,11 @@ module PuppetlabsSpec::Files
|
|
|
18
20
|
|
|
19
21
|
def self.cleanup
|
|
20
22
|
$global_tempfiles ||= []
|
|
21
|
-
while path = $global_tempfiles.pop
|
|
22
|
-
|
|
23
|
+
while path = $global_tempfiles.pop
|
|
24
|
+
raise "Not deleting tmpfile #{path} outside regular tmpdir" unless in_tmp(path)
|
|
23
25
|
|
|
24
26
|
begin
|
|
25
|
-
FileUtils.rm_r path, :
|
|
27
|
+
FileUtils.rm_r path, secure: true
|
|
26
28
|
rescue Errno::ENOENT
|
|
27
29
|
# nothing to do
|
|
28
30
|
end
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
# This module provides some helper methods to assist with fixtures. It's
|
|
2
4
|
# methods are designed to help when you have a conforming fixture layout so we
|
|
3
5
|
# get project consistency.
|
|
4
6
|
module PuppetlabsSpec::Fixtures
|
|
5
|
-
|
|
6
7
|
# Returns the joined path of the global FIXTURE_DIR plus any path given to it
|
|
7
8
|
def fixtures(*rest)
|
|
8
9
|
File.join(PuppetlabsSpec::FIXTURE_DIR, *rest)
|
|
@@ -13,21 +14,23 @@ module PuppetlabsSpec::Fixtures
|
|
|
13
14
|
# <project>/spec/fixture/unit/facter/foo
|
|
14
15
|
def my_fixture_dir
|
|
15
16
|
callers = caller
|
|
16
|
-
while line = callers.shift
|
|
17
|
+
while line = callers.shift
|
|
17
18
|
next unless found = line.match(%r{/spec/(.*)_spec\.rb:})
|
|
19
|
+
|
|
18
20
|
return fixtures(found[1])
|
|
19
21
|
end
|
|
20
|
-
|
|
22
|
+
raise "sorry, I couldn't work out your path from the caller stack!"
|
|
21
23
|
end
|
|
22
24
|
|
|
23
25
|
# Given a name, returns the full path of a file from your relative fixture
|
|
24
26
|
# dir as returned by my_fixture_dir.
|
|
25
27
|
def my_fixture(name)
|
|
26
28
|
file = File.join(my_fixture_dir, name)
|
|
27
|
-
unless File.readable? file
|
|
28
|
-
|
|
29
|
+
unless File.readable? file
|
|
30
|
+
raise "fixture '#{name}' for #{my_fixture_dir} is not readable"
|
|
29
31
|
end
|
|
30
|
-
|
|
32
|
+
|
|
33
|
+
file
|
|
31
34
|
end
|
|
32
35
|
|
|
33
36
|
# Return the contents of the file using read when given a name. Uses
|
|
@@ -38,12 +41,13 @@ module PuppetlabsSpec::Fixtures
|
|
|
38
41
|
|
|
39
42
|
# Provides a block mechanism for iterating across the files in your fixture
|
|
40
43
|
# area.
|
|
41
|
-
def my_fixtures(glob = '*', flags = 0)
|
|
44
|
+
def my_fixtures(glob = '*', flags = 0, &block)
|
|
42
45
|
files = Dir.glob(File.join(my_fixture_dir, glob), flags)
|
|
43
|
-
|
|
44
|
-
|
|
46
|
+
if files.empty?
|
|
47
|
+
raise "fixture '#{glob}' for #{my_fixture_dir} had no files!"
|
|
45
48
|
end
|
|
46
|
-
|
|
49
|
+
|
|
50
|
+
block_given? && files.each(&block)
|
|
47
51
|
files
|
|
48
52
|
end
|
|
49
53
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'stringio'
|
|
2
4
|
require 'rspec/expectations'
|
|
3
5
|
|
|
@@ -6,18 +8,17 @@ require 'rspec/expectations'
|
|
|
6
8
|
module RSpec
|
|
7
9
|
module Matchers
|
|
8
10
|
module BlockAliases
|
|
9
|
-
if method_defined? :
|
|
10
|
-
|
|
11
|
+
if method_defined?(:should) && !method_defined?(:to)
|
|
12
|
+
alias to should
|
|
11
13
|
end
|
|
12
14
|
if method_defined? :should_not
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
alias to_not should_not unless method_defined? :to_not
|
|
16
|
+
alias not_to should_not unless method_defined? :not_to
|
|
15
17
|
end
|
|
16
18
|
end
|
|
17
19
|
end
|
|
18
20
|
end
|
|
19
21
|
|
|
20
|
-
|
|
21
22
|
########################################################################
|
|
22
23
|
# Custom matchers...
|
|
23
24
|
RSpec::Matchers.define :have_matching_element do |expected|
|
|
@@ -26,7 +27,6 @@ RSpec::Matchers.define :have_matching_element do |expected|
|
|
|
26
27
|
end
|
|
27
28
|
end
|
|
28
29
|
|
|
29
|
-
|
|
30
30
|
RSpec::Matchers.define :exit_with do |expected|
|
|
31
31
|
actual = nil
|
|
32
32
|
match do |block|
|
|
@@ -35,13 +35,13 @@ RSpec::Matchers.define :exit_with do |expected|
|
|
|
35
35
|
rescue SystemExit => e
|
|
36
36
|
actual = e.status
|
|
37
37
|
end
|
|
38
|
-
actual
|
|
38
|
+
actual && actual == expected
|
|
39
39
|
end
|
|
40
|
-
failure_message_for_should do |
|
|
40
|
+
failure_message_for_should do |_block|
|
|
41
41
|
"expected exit with code #{expected} but " +
|
|
42
|
-
(actual.nil? ?
|
|
42
|
+
(actual.nil? ? ' exit was not called' : "we exited with #{actual} instead")
|
|
43
43
|
end
|
|
44
|
-
failure_message_for_should_not do |
|
|
44
|
+
failure_message_for_should_not do |_block|
|
|
45
45
|
"expected that exit would not be called with #{expected}"
|
|
46
46
|
end
|
|
47
47
|
description do
|
|
@@ -49,7 +49,6 @@ RSpec::Matchers.define :exit_with do |expected|
|
|
|
49
49
|
end
|
|
50
50
|
end
|
|
51
51
|
|
|
52
|
-
|
|
53
52
|
RSpec::Matchers.define :have_printed do |expected|
|
|
54
53
|
match do |block|
|
|
55
54
|
$stderr = $stdout = StringIO.new
|
|
@@ -64,7 +63,7 @@ RSpec::Matchers.define :have_printed do |expected|
|
|
|
64
63
|
$stderr = STDERR
|
|
65
64
|
end
|
|
66
65
|
|
|
67
|
-
if @actual
|
|
66
|
+
if @actual
|
|
68
67
|
case expected
|
|
69
68
|
when String
|
|
70
69
|
@actual.include? expected
|
|
@@ -77,7 +76,7 @@ RSpec::Matchers.define :have_printed do |expected|
|
|
|
77
76
|
end
|
|
78
77
|
|
|
79
78
|
failure_message_for_should do |actual|
|
|
80
|
-
if actual.nil?
|
|
79
|
+
if actual.nil?
|
|
81
80
|
"expected #{expected.inspect}, but nothing was printed"
|
|
82
81
|
else
|
|
83
82
|
"expected #{expected.inspect} to be printed; got:\n#{actual}"
|