puppet-retrospec 0.7.3 → 0.8.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 +17 -0
- data/Gemfile +4 -4
- data/README.md +63 -81
- data/VERSION +1 -1
- data/bin/retrospec +8 -4
- data/lib/retrospec.rb +40 -9
- data/lib/retrospec/helpers.rb +36 -2
- data/lib/retrospec/puppet_module.rb +3 -1
- data/lib/retrospec/templates/clone-hook +39 -0
- data/lib/retrospec/version.rb +1 -1
- data/puppet-retrospec.gemspec +3 -44
- data/spec/unit/puppet-retrospec_spec.rb +4 -65
- metadata +3 -100
- data/lib/retrospec/templates/acceptance_spec_test.erb +0 -24
- data/lib/retrospec/templates/module_files/.fixtures.yml +0 -8
- data/lib/retrospec/templates/module_files/.gitignore.erb +0 -8
- data/lib/retrospec/templates/module_files/.travis.yml +0 -14
- data/lib/retrospec/templates/module_files/Gemfile +0 -27
- data/lib/retrospec/templates/module_files/README.markdown +0 -75
- data/lib/retrospec/templates/module_files/Rakefile +0 -72
- data/lib/retrospec/templates/module_files/Vagrantfile +0 -95
- data/lib/retrospec/templates/module_files/spec/acceptance/nodesets/centos-59-x64.yml +0 -10
- data/lib/retrospec/templates/module_files/spec/acceptance/nodesets/centos-64-x64-pe.yml +0 -12
- data/lib/retrospec/templates/module_files/spec/acceptance/nodesets/centos-64-x64.yml +0 -11
- data/lib/retrospec/templates/module_files/spec/acceptance/nodesets/centos-66-x64.yml +0 -11
- data/lib/retrospec/templates/module_files/spec/acceptance/nodesets/debian-607-x64.yml +0 -11
- data/lib/retrospec/templates/module_files/spec/acceptance/nodesets/debian-70rc1-x64.yml +0 -11
- data/lib/retrospec/templates/module_files/spec/acceptance/nodesets/debian-73-i386.yml +0 -11
- data/lib/retrospec/templates/module_files/spec/acceptance/nodesets/debian-73-x64.yml +0 -11
- data/lib/retrospec/templates/module_files/spec/acceptance/nodesets/default.yml +0 -11
- data/lib/retrospec/templates/module_files/spec/acceptance/nodesets/fedora-18-x64.yml +0 -11
- data/lib/retrospec/templates/module_files/spec/acceptance/nodesets/sles-11sp1-x64.yml +0 -11
- data/lib/retrospec/templates/module_files/spec/acceptance/nodesets/ubuntu-server-10044-x64.yml +0 -10
- data/lib/retrospec/templates/module_files/spec/acceptance/nodesets/ubuntu-server-12042-x64.yml +0 -10
- data/lib/retrospec/templates/module_files/spec/acceptance/nodesets/ubuntu-server-1310-x64.yml +0 -11
- data/lib/retrospec/templates/module_files/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml +0 -11
- data/lib/retrospec/templates/module_files/spec/shared_contexts.rb +0 -45
- data/lib/retrospec/templates/module_files/spec/spec_helper.rb +0 -11
- data/lib/retrospec/templates/module_files/spec/spec_helper_acceptance.rb +0 -33
- data/lib/retrospec/templates/resource_spec_file.erb +0 -45
- data/vendor/gems/puppet-3.7.3/COMMITTERS.md +0 -244
- data/vendor/gems/puppet-3.7.3/CONTRIBUTING.md +0 -91
- data/vendor/gems/puppet-3.7.3/README.md +0 -76
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07921b5d09c92738440e643b20afbfee2aeaabbc
|
4
|
+
data.tar.gz: 9ff24e7a36e206e02cc7408cd5a21ce3e3838af3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad162892e3d4cf46c505bcd99878ece7e9a49dd3933fc4ea5fc75dddc1d21797e69d1b36f34ca292cac92c442c8dec198ca67835c7d644da58920e91d999f961
|
7
|
+
data.tar.gz: e405d614efa59d18dc2b90408c9ade1ad30861b35e48c0754765a196fcd85742aa42ec16078cf1cfb0e65531626dbf06ba89704c879c5172be6b15a2416dbcc4
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
## 0.8.0
|
2
|
+
* enable broader support for future parser
|
3
|
+
* remove hiera and facter dependencies
|
4
|
+
* added support for running pre and post hooks gh-27
|
5
|
+
* added support for running a hook to clone external templates
|
6
|
+
* externalized the templates into their own repo gh-26
|
7
|
+
* handle symlinks in the templates directory correctly gh-28
|
8
|
+
|
9
|
+
## 0.7.3
|
10
|
+
* added hiera data helper to fill in all the auto bindable class params in shared_contexts
|
11
|
+
* updated hiera data gem to newer fork that works with puppet 3.5+
|
12
|
+
* minor fixes in templates
|
13
|
+
* added vagrantfile for easier manual integration testing
|
14
|
+
|
15
|
+
## 0.7.2
|
16
|
+
* vendor the puppet gem
|
17
|
+
|
1
18
|
## 0.7.0
|
2
19
|
* gh-18 puppet 4 code syntax does not work
|
3
20
|
* gh-10 safe file creation should use colors
|
data/Gemfile
CHANGED
@@ -2,16 +2,16 @@ source "http://rubygems.org"
|
|
2
2
|
|
3
3
|
# while retrospec does not use facter or hiera,
|
4
4
|
# we vendor the puppet gem 3.7.3 which also requires facter and hiera
|
5
|
-
gem 'facter', '< 3', '> 1.6'
|
6
|
-
gem 'hiera', '~> 1.0'
|
5
|
+
#gem 'facter', '< 3', '> 1.6'
|
6
|
+
#gem 'hiera', '~> 1.0'
|
7
7
|
|
8
8
|
gem 'trollop'
|
9
9
|
# Include everything needed to run rake, tests, features, etc.
|
10
10
|
group :development do
|
11
11
|
gem "rspec", "~> 2.14"
|
12
12
|
gem 'puppet', '3.7.3', :path => 'vendor/gems/puppet-3.7.3'
|
13
|
-
gem 'facter', '< 3', '> 1.6'
|
14
|
-
gem 'hiera', '~> 1.0'
|
13
|
+
#gem 'facter', '< 3', '> 1.6'
|
14
|
+
#gem 'hiera', '~> 1.0'
|
15
15
|
gem "yard", "~> 0.7"
|
16
16
|
gem "rdoc", "~> 3.12"
|
17
17
|
gem "bundler", "~> 1.0"
|
data/README.md
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
Puppet-Retrospec
|
2
2
|
================
|
3
3
|
|
4
|
-
Generates puppet rspec test code based on the classes and defines inside the manifests directory.
|
4
|
+
Generates puppet rspec test code based on the classes and defines inside the manifests directory.
|
5
|
+
Aims to reduce most of the boilerplate coding with default test patterns and module setup.
|
5
6
|
|
6
|
-
Retrospec makes it dead simple to get started with puppet unit testing.
|
7
|
-
and actually write some very basic rspec-puppet test code.
|
8
|
-
with everything needed to get going with puppet unit testing.
|
7
|
+
Retrospec makes it dead simple to get started with puppet module development and puppet unit testing.
|
8
|
+
When you run retrospec, retrospec will scan you puppet manifests and actually write some very basic rspec-puppet test code.
|
9
|
+
Thus this gem will retrofit your existing puppet module with everything needed to get going with puppet unit testing.
|
10
|
+
Additionally, retrospec will outfit your module with any file you can think of. Say goodbye to repetitive module setup.
|
9
11
|
|
10
12
|
The project was named retrospec because there are many times when you need to retrofit your module with spec tests.
|
11
13
|
|
@@ -29,7 +31,7 @@ Table of Contents
|
|
29
31
|
* [Future Parser Support](#future-parser-support)
|
30
32
|
* [Support](#support)
|
31
33
|
|
32
|
-
Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc)
|
34
|
+
TOC Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc)
|
33
35
|
|
34
36
|
Build Status
|
35
37
|
============
|
@@ -38,9 +40,8 @@ Build Status
|
|
38
40
|
|
39
41
|
Dependency
|
40
42
|
============
|
41
|
-
Retrospec relies heavily on the puppet 3.7.x codebase. Because of this hard dependency the puppet gem is vendored into
|
42
|
-
not be conflicts with your existing puppet gem.
|
43
|
-
loading facter or hiera then we may need to also vendor the facter and hiera gems as well.
|
43
|
+
Retrospec relies heavily on the puppet 3.7.x codebase. Because of this hard dependency the puppet gem is vendored into
|
44
|
+
the library so there should not be conflicts with your existing puppet gem.
|
44
45
|
|
45
46
|
Install
|
46
47
|
=============
|
@@ -52,12 +53,16 @@ How to use
|
|
52
53
|
Run from the command line
|
53
54
|
```
|
54
55
|
$ retrospec -h
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
56
|
+
Generates puppet rspec test code based on the classes and defines inside the manifests directory.
|
57
|
+
-m, --module-path=<s> The path (relative or absolute) to the module directory (Defaults to current directory)
|
58
|
+
-t, --template-dir=<s> Path to templates directory (only for overriding Retrospec templates) (default: /Users/user1/.retrospec_templates)
|
59
|
+
-s, --scm-url=<s> SCM url for retrospec templates
|
60
|
+
-b, --branch=<s> Branch you want to use for the retrospec template repo
|
61
|
+
-e, --enable-beaker-tests Enable the creation of beaker tests
|
62
|
+
-n, --enable-future-parser Enables the future parser only during validation
|
63
|
+
-v, --version Print version and exit
|
64
|
+
-h, --help Show this message
|
65
|
+
|
61
66
|
|
62
67
|
retrospec -m ~/projects/puppet_modules/apache
|
63
68
|
```
|
@@ -68,7 +73,8 @@ Example
|
|
68
73
|
Below you can see that it creates files for every resource in the tomcat module in addition to other files
|
69
74
|
that you need for unit testing puppet code. Rspec-puppet best practices says to put definitions in a defines folder
|
70
75
|
and classes in a classes folder since it infers what kind of resource it is based on this convention. Retrospec sets up
|
71
|
-
this scaffolding for you.
|
76
|
+
this scaffolding for you. Don't like the files that came with your module? Simply delete the files and re-generate them
|
77
|
+
with retrospec.
|
72
78
|
|
73
79
|
```shell
|
74
80
|
$ pwd
|
@@ -85,21 +91,6 @@ $ retrospec
|
|
85
91
|
+ /Users/cosman/github/puppetlabs-apache/spec/classes/
|
86
92
|
+ /Users/cosman/github/puppetlabs-apache/spec/classes/default_mods_spec.rb
|
87
93
|
+ /Users/cosman/github/puppetlabs-apache/spec/classes/dev_spec.rb
|
88
|
-
+ /Users/cosman/github/puppetlabs-apache/spec/classes/apache_spec.rb
|
89
|
-
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/
|
90
|
-
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/alias_spec.rb
|
91
|
-
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/auth_basic_spec.rb
|
92
|
-
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/auth_kerb_spec.rb
|
93
|
-
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/autoindex_spec.rb
|
94
|
-
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/cache_spec.rb
|
95
|
-
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/cgi_spec.rb
|
96
|
-
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/cgid_spec.rb
|
97
|
-
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/dav_spec.rb
|
98
|
-
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/dav_fs_spec.rb
|
99
|
-
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/dav_svn_spec.rb
|
100
|
-
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/deflate_spec.rb
|
101
|
-
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/dev_spec.rb
|
102
|
-
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/dir_spec.rb
|
103
94
|
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/disk_cache_spec.rb
|
104
95
|
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/fcgid_spec.rb
|
105
96
|
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/headers_spec.rb
|
@@ -107,30 +98,6 @@ $ retrospec
|
|
107
98
|
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/itk_spec.rb
|
108
99
|
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/ldap_spec.rb
|
109
100
|
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/mime_spec.rb
|
110
|
-
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/mime_magic_spec.rb
|
111
|
-
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/mpm_event_spec.rb
|
112
|
-
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/negotiation_spec.rb
|
113
|
-
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/passenger_spec.rb
|
114
|
-
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/perl_spec.rb
|
115
|
-
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/php_spec.rb
|
116
|
-
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/prefork_spec.rb
|
117
|
-
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/proxy_spec.rb
|
118
|
-
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/proxy_balancer_spec.rb
|
119
|
-
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/proxy_html_spec.rb
|
120
|
-
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/proxy_http_spec.rb
|
121
|
-
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/python_spec.rb
|
122
|
-
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/reqtimeout_spec.rb
|
123
|
-
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/rewrite_spec.rb
|
124
|
-
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/setenvif_spec.rb
|
125
|
-
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/ssl_spec.rb
|
126
|
-
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/status_spec.rb
|
127
|
-
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/suphp_spec.rb
|
128
|
-
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/userdir_spec.rb
|
129
|
-
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/vhost_alias_spec.rb
|
130
|
-
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/worker_spec.rb
|
131
|
-
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/wsgi_spec.rb
|
132
|
-
+ /Users/cosman/github/puppetlabs-apache/spec/classes/mod/xsendfile_spec.rb
|
133
|
-
+ /Users/cosman/github/puppetlabs-apache/spec/classes/params_spec.rb
|
134
101
|
+ /Users/cosman/github/puppetlabs-apache/spec/classes/php_spec.rb
|
135
102
|
+ /Users/cosman/github/puppetlabs-apache/spec/classes/proxy_spec.rb
|
136
103
|
+ /Users/cosman/github/puppetlabs-apache/spec/classes/python_spec.rb
|
@@ -148,11 +115,12 @@ $ retrospec
|
|
148
115
|
|
149
116
|
```
|
150
117
|
|
151
|
-
Looking at the file we can see that it did a lot of work for us. Retrospec
|
118
|
+
Looking at the file we can see that it did a lot of work for us. Retrospec generated many tests automatically.
|
152
119
|
However the variable resolution isn't perfect so you will need to manually resolve some variables. This doesn't produce
|
153
120
|
100% coverage but all you did was pressed enter to produce all this anyways.
|
154
121
|
Below is the classes/apache_spec.rb file. Notice that while Retrospec created all these files, you still need to do more work.
|
155
122
|
Retrospec is only here to setup your module for testing, which might save you several hours each time you create a module.
|
123
|
+
Below I'll go through the different parts of automation that you can use in your testing.
|
156
124
|
|
157
125
|
|
158
126
|
```ruby
|
@@ -356,34 +324,37 @@ For now you will probably want to read up on the following documentation:
|
|
356
324
|
How Does it do this
|
357
325
|
=======================
|
358
326
|
Basically Retrospec uses the puppet lexer and parser to scan your code in order to fill out some basic templates that will retrofit
|
359
|
-
your puppet module with unit tests. Currently I rely on the old AST parser to generate all this. This is why
|
327
|
+
your puppet module with unit tests. Currently I rely on the old AST parser to generate all this. This is why puppet 3.7
|
328
|
+
is vendored into the gem.
|
360
329
|
|
361
|
-
Overriding the
|
330
|
+
Overriding the Templates
|
362
331
|
=======================
|
363
332
|
There may be a time when you want to override the default templates used to generate the rspec related files.
|
364
|
-
|
333
|
+
By default retrospec will clone these [templates](https://github.com/nwops/retrospec-templates)
|
334
|
+
and place inside the default or specified template directory. Previously the templates were kept inside the gem
|
335
|
+
and cloning was not required. However, after using retrospec for a few months it makes more sense to keep these templates
|
336
|
+
versioned controlled in their own repo and update them before each retrospec use. This also makes it easy for team
|
337
|
+
contributions to be spread to other team members quickly.
|
365
338
|
|
366
339
|
```shell
|
367
|
-
|
368
|
-
|
340
|
+
-t, --template-dir=<s> Path to templates directory (only for overriding Retrospec templates) (default: /Users/user1/.retrospec_templates)
|
341
|
+
-s, --scm-url=<s> SCM url for retrospec templates
|
342
|
+
-b, --branch=<s> Branch you want to use for the retrospec template repo
|
369
343
|
|
370
344
|
```
|
371
345
|
|
372
|
-
|
373
|
-
or specified templates path.
|
374
|
-
If you have already created the erb file in the templates location, then puppet-retrospec will not overwrite the file.
|
375
|
-
You can set multiple template paths if you use them for different projects so just be sure the set the correct
|
376
|
-
template option when running retrospec.
|
377
|
-
|
378
|
-
Setting the `--enable-user-templates` option will tell retrospec to use the default user template location and will
|
379
|
-
copy over all the default templates that came with the gem.
|
346
|
+
### Environment variables to set template defaults
|
380
347
|
|
381
|
-
|
348
|
+
RETROSPEC_SCM_URL # set this to auto set your scm url to the templates
|
349
|
+
RETROSPEC_SCM_BRANCH # set this to auto checkout a particular branch (only works upon initial checkout)
|
382
350
|
|
383
|
-
|
384
|
-
|
351
|
+
After running retrospec, retrospec will clone the templates from the default template url or from whatever you set to the templates path.
|
352
|
+
If you have already created the erb file in the templates location, then retrospec will not overwrite the file as there will
|
353
|
+
be a SCM conflict.
|
354
|
+
You can use multiple template paths if you use them for different projects so just be sure the set the correct
|
355
|
+
template option when running retrospec. `retrospec -t`
|
385
356
|
|
386
|
-
|
357
|
+
The default user location for the templates when not using `retrospec -t` variable is ~/.retrospec_templates
|
387
358
|
|
388
359
|
Example:
|
389
360
|
`--template-dir=~/my_templates`
|
@@ -417,9 +388,10 @@ Adding New Templates
|
|
417
388
|
Should you ever need to add new templates or normal files of any kind retrospec will automatically render and copy the template file
|
418
389
|
to the module path if you place a file inside the `template_path/module_files` directory. The cool thing about this feature
|
419
390
|
is that retrospec will recursively create the same directory structure you make inside the `module_files` directory inside your
|
420
|
-
module. Files do not need to end in .erb will still be rendered as a erb template.
|
391
|
+
module. Files do not need to end in .erb will still be rendered as a erb template. Symlinks will be preserved and not
|
392
|
+
dereferenced.
|
421
393
|
|
422
|
-
This
|
394
|
+
This follows the convention over configuration pattern so no directory name or filename is required when running retrospec.
|
423
395
|
Just put the template file in the directory where you want it (under module_files) and name it exactly how you want it to appear in the module and retrospec
|
424
396
|
will take care of the rest. Please note that any file ending in .erb will have this extension automatically removed.
|
425
397
|
|
@@ -427,10 +399,10 @@ Example:
|
|
427
399
|
So lets say you want to add a .gitlab-ci.yaml file to all of your modules in your modules directory.
|
428
400
|
|
429
401
|
```shell
|
430
|
-
touch ~/.
|
402
|
+
touch ~/.retrospec_templates/module_files/.gitlab-ci.yaml
|
431
403
|
|
432
|
-
tree ~/.
|
433
|
-
./.
|
404
|
+
tree ~/.retrospec_templates -a
|
405
|
+
./.retrospec_templates
|
434
406
|
├── acceptance_spec_test.erb
|
435
407
|
├── module_files
|
436
408
|
│ ├── .fixtures.yml
|
@@ -489,7 +461,7 @@ See [fixtures doc](https://github.com/puppetlabs/puppetlabs_spec_helper#using-fi
|
|
489
461
|
```
|
490
462
|
|
491
463
|
If you see something like the following, this means your current module is using a much older version of Rspec. Retrospec
|
492
|
-
|
464
|
+
uses Rspec 3 syntax so you need to update your rspec version. If you have tests that using older rspec syntax, take a look
|
493
465
|
at [transpec](https://github.com/yujinakayama/transpec)
|
494
466
|
|
495
467
|
```shell
|
@@ -500,7 +472,12 @@ at [transpec](https://github.com/yujinakayama/transpec)
|
|
500
472
|
# ./spec/defines/vhost_spec.rb:103:in `block (2 levels) in <top (required)>'
|
501
473
|
|
502
474
|
```
|
503
|
-
|
475
|
+
|
476
|
+
If your tests will not run after running retrospec. Your spec_helper, Rakefile and Gemfile may not be compatible
|
477
|
+
with the pre-defined templates. Just delete these files and re-run retrospec to recreate them. Add back any modifications
|
478
|
+
you might have had.
|
479
|
+
|
480
|
+
Running Retrospec Tests
|
504
481
|
=============
|
505
482
|
Puppet-retrospec tests its code against real modules downloaded directly from puppet forge.
|
506
483
|
We also do a little mocking as well but for the majority of the tests we download are 'fixtures'.
|
@@ -531,7 +508,7 @@ Future Parser Support
|
|
531
508
|
==============
|
532
509
|
Currently Retrospec uses the old/current AST parser for code parsing. If your code contains future parser syntax
|
533
510
|
the current parser will fail to render some resource definitions but will still render the spec file template without parameters
|
534
|
-
and resource tests that are contained in your manifest.
|
511
|
+
and resource tests that are contained in your manifest. Retrospec is still extremely useful with Puppet 4.
|
535
512
|
Since Puppet 4 introduces many new things and breaks many other things I am not sure
|
536
513
|
which side of the grass is greener at this time. What I do know is that most people are using Puppet 3 and it may take
|
537
514
|
time to move to Puppet 4. I would suspect Retrospec would be more valuable for those moving to Puppet 4
|
@@ -553,6 +530,11 @@ Todo
|
|
553
530
|
- Auto add dependencies to fixtures file
|
554
531
|
- Show a diff of the test file when retrospec is run multiple times and the test file is already created.
|
555
532
|
|
556
|
-
Support
|
533
|
+
Ruby Support
|
557
534
|
============
|
558
535
|
Currently this library only supports ruby >= 1.9.3. It might work on 1.8.7 but I won't support if it fails.
|
536
|
+
|
537
|
+
Paid Support
|
538
|
+
============
|
539
|
+
Want to see new features developed much faster? Contact me about a support contract so I can develop this tool during
|
540
|
+
the day instead of after work. contact: sales@logicminds.biz
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.8.0
|
data/bin/retrospec
CHANGED
@@ -4,7 +4,7 @@ require 'trollop'
|
|
4
4
|
require 'retrospec'
|
5
5
|
|
6
6
|
opts = Trollop::options do
|
7
|
-
version "0.
|
7
|
+
version "0.8.0 (c) Corey Osman"
|
8
8
|
banner <<-EOS
|
9
9
|
Generates puppet rspec test code based on the classes and defines inside the manifests directory.
|
10
10
|
|
@@ -13,13 +13,17 @@ Generates puppet rspec test code based on the classes and defines inside the man
|
|
13
13
|
opt :module_path, "The path (relative or absolute) to the module directory (Defaults to current directory) " ,
|
14
14
|
:type => :string, :required => false, :default => nil
|
15
15
|
opt :template_dir, "Path to templates directory (only for overriding Retrospec templates)", :type => :string,
|
16
|
-
:required => false, :default =>
|
17
|
-
opt :
|
18
|
-
:
|
16
|
+
:required => false, :default => File.expand_path('~/.retrospec_templates')
|
17
|
+
opt :scm_url, "SCM url for retrospec templates", :type => :string, :required => false,
|
18
|
+
:default => ENV['RETROSPEC_SCM_URL']
|
19
|
+
opt :branch, "Branch you want to use for the retrospec template repo", :type => :string, :required => false,
|
20
|
+
:default => ENV['RETROSPEC_SCM_BRANCH']
|
19
21
|
opt :enable_beaker_tests, "Enable the creation of beaker tests", :require => false, :type => :boolean
|
20
22
|
opt :enable_future_parser, "Enables the future parser only during validation", :require => false, :type => :boolean
|
21
23
|
end
|
22
24
|
include Puppet_Retrospec
|
23
25
|
|
24
26
|
retro = Retrospec.new(opts[:module_path], opts)
|
27
|
+
retro.run_pre_hook
|
25
28
|
retro.create_files
|
29
|
+
retro.run_post_hook
|
data/lib/retrospec.rb
CHANGED
@@ -10,6 +10,7 @@ require 'retrospec/puppet_module'
|
|
10
10
|
require 'retrospec/spec_object'
|
11
11
|
require 'retrospec/exceptions'
|
12
12
|
require 'retrospec/version'
|
13
|
+
require 'find'
|
13
14
|
|
14
15
|
class Retrospec
|
15
16
|
|
@@ -25,12 +26,7 @@ class Retrospec
|
|
25
26
|
def initialize(supplied_module_path=nil,opts={})
|
26
27
|
Utilities::PuppetModule.instance.future_parser = opts[:enable_future_parser]
|
27
28
|
# user supplied a template path or user wants to use local templates
|
28
|
-
|
29
|
-
@template_dir = Helpers.setup_user_template_dir(opts[:template_dir])
|
30
|
-
else
|
31
|
-
# if user doesn't supply template directory we assume we should use the templates in this gem
|
32
|
-
@template_dir = Helpers.gem_template_dir
|
33
|
-
end
|
29
|
+
@template_dir = Helpers.setup_user_template_dir(opts[:template_dir], opts[:scm_url], opts[:branch])
|
34
30
|
begin
|
35
31
|
Utilities::PuppetModule.instance.module_path = supplied_module_path
|
36
32
|
Utilities::PuppetModule.create_tmp_module_path # this is required to finish initialization
|
@@ -40,6 +36,37 @@ class Retrospec
|
|
40
36
|
end
|
41
37
|
end
|
42
38
|
|
39
|
+
# runs a user defined hook called pre-hook
|
40
|
+
def run_pre_hook
|
41
|
+
hook_file = File.join(template_dir,'pre-hook')
|
42
|
+
if File.exists?(hook_file)
|
43
|
+
output = `#{hook_file} #{module_path}`
|
44
|
+
if $?.success?
|
45
|
+
puts "Successfully ran hook: #{hook_file}".info
|
46
|
+
puts output.info
|
47
|
+
else
|
48
|
+
puts "Error running hook: #{hook_file}".fatal
|
49
|
+
puts output.fatal
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# runs a user defined hook called post-hook
|
55
|
+
def run_post_hook
|
56
|
+
hook_file = File.join(template_dir,'post-hook')
|
57
|
+
if File.exists?(hook_file)
|
58
|
+
output = `#{hook_file} #{module_path}`
|
59
|
+
if $?.success?
|
60
|
+
puts "Successfully ran hook: #{hook_file}".info
|
61
|
+
puts output.info
|
62
|
+
else
|
63
|
+
puts "Error running hook: #{hook_file}".fatal
|
64
|
+
puts output.fatal
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# this is the method that performs all the magic and creates all the files
|
43
70
|
def create_files
|
44
71
|
types = spec_object.types
|
45
72
|
safe_create_module_files
|
@@ -57,19 +84,23 @@ class Retrospec
|
|
57
84
|
end
|
58
85
|
|
59
86
|
# creates any file that is contained in the templates/modules_files directory structure
|
60
|
-
# loops through the directory looking for erb files
|
87
|
+
# loops through the directory looking for erb files or other files.
|
61
88
|
# strips the erb extension and renders the template to the current module path
|
62
89
|
# filenames must named how they would appear in the normal module path. The directory
|
63
90
|
# structure where the file is contained
|
64
91
|
def safe_create_module_files
|
65
|
-
templates =
|
92
|
+
templates = Find.find(File.join(template_dir,'module_files')).find_all {|f| !File.directory?(f)}.sort
|
66
93
|
templates.each do |template|
|
67
94
|
# need to remove the erb extension and rework the destination path
|
68
95
|
if template =~ /nodesets|spec_helper_acceptance/ and !spec_object.enable_beaker_tests?
|
69
96
|
next
|
70
97
|
else
|
71
98
|
dest = template.gsub(File.join(template_dir,'module_files'), module_path).gsub('.erb', '')
|
72
|
-
|
99
|
+
if File.symlink?(template)
|
100
|
+
Helpers.safe_create_symlink(template, dest)
|
101
|
+
else
|
102
|
+
safe_create_template_file(dest, template)
|
103
|
+
end
|
73
104
|
end
|
74
105
|
end
|
75
106
|
end
|
data/lib/retrospec/helpers.rb
CHANGED
@@ -65,11 +65,36 @@ class Helpers
|
|
65
65
|
|
66
66
|
# creates and syncs the specifed user template diretory
|
67
67
|
# returns: user_template_dir
|
68
|
-
def self.setup_user_template_dir(user_template_directory=nil)
|
68
|
+
def self.setup_user_template_dir(user_template_directory=nil, git_url=nil, branch=nil)
|
69
69
|
if user_template_directory.nil?
|
70
70
|
user_template_directory = default_user_template_dir
|
71
71
|
end
|
72
|
-
|
72
|
+
template_dir = create_user_template_dir(user_template_directory)
|
73
|
+
run_clone_hook(user_template_directory, git_url, branch)
|
74
|
+
template_dir
|
75
|
+
end
|
76
|
+
|
77
|
+
# runs the clone hook file
|
78
|
+
# the intention of this method and hook is to download the templates
|
79
|
+
# from an external repo. Because templates are updated frequently
|
80
|
+
# and users will sometimes have client specific templates I wanted to
|
81
|
+
# externalize them for easier management.
|
82
|
+
def self.run_clone_hook(template_dir, git_url=nil, branch=nil)
|
83
|
+
if File.exists?(File.join(template_dir,'clone-hook'))
|
84
|
+
hook_file = File.join(template_dir,'clone-hook')
|
85
|
+
else
|
86
|
+
hook_file = File.join(gem_template_dir, 'clone-hook')
|
87
|
+
end
|
88
|
+
if File.exists?(hook_file)
|
89
|
+
output = `#{hook_file} #{template_dir} #{git_url} #{branch}`
|
90
|
+
if $?.success?
|
91
|
+
puts "Successfully ran hook: #{hook_file}".info
|
92
|
+
puts output.info
|
93
|
+
else
|
94
|
+
puts "Error running hook: #{hook_file}".fatal
|
95
|
+
puts output.fatal
|
96
|
+
end
|
97
|
+
end
|
73
98
|
end
|
74
99
|
|
75
100
|
def self.default_user_template_dir
|
@@ -80,6 +105,15 @@ class Helpers
|
|
80
105
|
File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
81
106
|
end
|
82
107
|
|
108
|
+
def self.safe_create_symlink(src,dest)
|
109
|
+
if File.exists? dest
|
110
|
+
$stderr.puts "!! #{dest} already exists and differs from template".warning
|
111
|
+
else
|
112
|
+
FileUtils.copy_entry(src,dest)
|
113
|
+
puts " + #{dest}".info
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
83
117
|
def self.safe_copy_file(src, dest)
|
84
118
|
if File.exists?(dest) and not File.zero?(dest)
|
85
119
|
$stderr.puts "!! #{dest} already exists".warning
|