puppetlabs_spec_helper 0.4.1 → 0.5.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 +7 -0
- data/.gitignore +3 -0
- data/.noexec.yaml +4 -0
- data/CHANGELOG +12 -0
- data/Gemfile +9 -0
- data/README.markdown +186 -0
- data/Rakefile +33 -0
- data/lib/puppetlabs_spec_helper/puppet_spec_helper.rb +0 -7
- data/lib/puppetlabs_spec_helper/rake_tasks.rb +96 -12
- data/lib/puppetlabs_spec_helper/version.rb +5 -0
- data/puppet_spec_helper.rb +5 -0
- data/puppetlabs_spec_helper.gemspec +25 -0
- data/puppetlabs_spec_helper.rb +5 -0
- data/spec/lib/puppet/type/spechelper.rb +6 -0
- data/spec/unit/puppetlabs_spec_helper/puppetlabs_spec/puppet_internals_spec.rb +92 -0
- data/spec/unit/spechelper_spec.rb +43 -0
- data/spec/watchr.rb +79 -0
- metadata +108 -102
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f853c33fa6a79d464edde31b1b1e860145394dfa
|
4
|
+
data.tar.gz: c9e8ce7b36ea0efc45394bf8c1d7f3b0e53761b6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d09259b7c9942c87e2012c41af6771aa8b8d3a3320d9140f814228c86e740baeabb755b29d81416c64abcf7980b434380a5911be0a5cab910134010f399bc7d1
|
7
|
+
data.tar.gz: 9a9f143383c5d85044ac1311b7461f4a15b34021b9a4908cc2083b69fec7d5026a62b997e31d7169cdd39ff78d64c345e21abbd413a3b3ecfb313450baacf77d
|
data/.gitignore
ADDED
data/.noexec.yaml
ADDED
data/CHANGELOG
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
2014-06-06 - Release 0.4.2
|
2
|
+
|
3
|
+
Summary:
|
4
|
+
This release corrects the pinning of rspec for modules which are not rspec 3
|
5
|
+
compatible yet.
|
6
|
+
|
7
|
+
Bugfixes:
|
8
|
+
* Pin to 2.x range for rspec 2
|
9
|
+
* Fix aborting rake task when packaging gem
|
10
|
+
* Fix puppet issue tracker url
|
11
|
+
* Fix issue with running `git reset` in the incorrect dir
|
12
|
+
|
1
13
|
2013-02-08 Puppet Labs <info@puppetlabs.com> - 0.4.1
|
2
14
|
* (#18165) Mark tests pending on broken puppet versions
|
3
15
|
* (#18165) Initialize TestHelper as soon as possible
|
data/Gemfile
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,186 @@
|
|
1
|
+
Puppet Labs Spec Helper
|
2
|
+
=======================
|
3
|
+
|
4
|
+
The Short Version
|
5
|
+
-----------------
|
6
|
+
|
7
|
+
This repository is meant to provide a single source of truth for how to
|
8
|
+
initialize different Puppet versions for spec testing.
|
9
|
+
|
10
|
+
The common use case is a module such as
|
11
|
+
[stdlib](http://forge.puppetlabs.com/puppetlabs/stdlib) that works with many
|
12
|
+
versions of Puppet. The stdlib module should require the spec helper in this
|
13
|
+
repository, which will in turn automatically figure out the version of Puppet
|
14
|
+
being tested against and perform version specific initialization.
|
15
|
+
|
16
|
+
Other "customers" that should use this module are:
|
17
|
+
|
18
|
+
* [Facter](https://github.com/puppetlabs/facter)
|
19
|
+
* [PuppetDB](https://github.com/puppetlabs/puppetdb)
|
20
|
+
* [Mount Providers](https://github.com/puppetlabs/puppetlabs-mount_providers)
|
21
|
+
|
22
|
+
Usage
|
23
|
+
=====
|
24
|
+
|
25
|
+
When developing or testing modules, simply clone this repository and install the
|
26
|
+
gem it contains.
|
27
|
+
|
28
|
+
$ git clone git://github.com/puppetlabs/puppetlabs_spec_helper.git
|
29
|
+
$ cd puppetlabs_spec_helper
|
30
|
+
$ rake package:gem
|
31
|
+
$ gem install pkg/puppetlabs_spec_helper-*.gem
|
32
|
+
|
33
|
+
Add this to your project's spec\_helper.rb:
|
34
|
+
|
35
|
+
require 'puppetlabs_spec_helper/module_spec_helper'
|
36
|
+
|
37
|
+
Add this to your project's Rakefile:
|
38
|
+
|
39
|
+
require 'puppetlabs_spec_helper/rake_tasks'
|
40
|
+
|
41
|
+
And run the spec tests:
|
42
|
+
|
43
|
+
$ cd $modulename
|
44
|
+
$ rake spec
|
45
|
+
|
46
|
+
Issues
|
47
|
+
======
|
48
|
+
|
49
|
+
Please file issues against this project at the [Puppet Labs Issue
|
50
|
+
Tracker](https://tickets.puppetlabs.com/browse/MODULES)
|
51
|
+
|
52
|
+
The Long Version
|
53
|
+
----------------
|
54
|
+
|
55
|
+
Purpose of this Project
|
56
|
+
=======================
|
57
|
+
|
58
|
+
This project is intended to serve two purposes:
|
59
|
+
|
60
|
+
1. To serve as a bridge between external projects and multiple versions of puppet;
|
61
|
+
in other words, if your project has a dependency on puppet, you shouldn't need
|
62
|
+
to need to worry about the details of how to initialize puppet's state for
|
63
|
+
testing, no matter what version of puppet you are testing against.
|
64
|
+
2. To provide some convenience classes / methods for doing things like creating
|
65
|
+
tempfiles, common rspec matchers, etc. These classes are in the puppetlabs\_spec
|
66
|
+
directory.
|
67
|
+
3. To provide a common set of Rake tasks so that the procedure for testing modules
|
68
|
+
is unified.
|
69
|
+
|
70
|
+
To Use this Project
|
71
|
+
===================
|
72
|
+
|
73
|
+
The most common usage scenario is that you will check out the 'master'
|
74
|
+
branch of this project from github, and install it as a rubygem.
|
75
|
+
There should be few or no cases where you would want to have any other
|
76
|
+
branch of this project besides master/HEAD.
|
77
|
+
|
78
|
+
Initializing Puppet for Testing
|
79
|
+
===============================
|
80
|
+
|
81
|
+
In most cases, your project should be able to define a spec\_helper.rb that includes
|
82
|
+
just this one simple line:
|
83
|
+
|
84
|
+
require 'puppetlabs_spec_helper/puppet_spec_helper'
|
85
|
+
|
86
|
+
Then, as long as the gem is installed, you should be all set.
|
87
|
+
|
88
|
+
If you are using rspec-puppet for module testing, you will want to include a different
|
89
|
+
library:
|
90
|
+
|
91
|
+
require 'puppetlabs_spec_helper/module_spec_helper'
|
92
|
+
|
93
|
+
NOTE that this is specifically for initializing Puppet's core. If your project does
|
94
|
+
not have any dependencies on puppet and you just want to use the utility classes,
|
95
|
+
see the next section.
|
96
|
+
|
97
|
+
|
98
|
+
Using Utility Classes
|
99
|
+
=====================
|
100
|
+
If you'd like to use the Utility classes (PuppetlabsSpec::Files,
|
101
|
+
PuppetlabsSpec::Fixtures), you just need to add this to your project's spec\_helper.rb:
|
102
|
+
|
103
|
+
require 'puppetlabs_spec_helper/puppetlabs_spec_helper'
|
104
|
+
|
105
|
+
NOTE that the above line happens automatically if you've required
|
106
|
+
'puppetlabs\_spec\_helper/puppet\_spec\_helper', so you don't need to do both.
|
107
|
+
|
108
|
+
In either case, you'll have all of the functionality of Puppetlabs::Files,
|
109
|
+
Puppetlabs::Fixtures, etc., mixed-in to your rspec context.
|
110
|
+
|
111
|
+
Using Fixtures
|
112
|
+
==============
|
113
|
+
`puppetlabs_spec_helper` has the ability to populate the
|
114
|
+
`spec/fixtures/modules` directory with dependent modules when `rake spec` or
|
115
|
+
`rake spec_prep` is run. To do so, all required modules should be listed in a
|
116
|
+
file named `.fixtures.yml` in the root of the project.
|
117
|
+
|
118
|
+
Fixtures Examples
|
119
|
+
-----------------
|
120
|
+
Basic fixtures that will symlink `spec/fixtures/modules/my_modules` to the
|
121
|
+
project root:
|
122
|
+
|
123
|
+
fixtures:
|
124
|
+
symlinks:
|
125
|
+
my_module: "#{source_dir}"
|
126
|
+
|
127
|
+
|
128
|
+
Add `firewall` and `stdlib` as required module fixtures:
|
129
|
+
|
130
|
+
fixtures:
|
131
|
+
repositories:
|
132
|
+
firewall: "git://github.com/puppetlabs/puppetlabs-firewall"
|
133
|
+
stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib"
|
134
|
+
symlinks:
|
135
|
+
my_module: "#{source_dir}"
|
136
|
+
|
137
|
+
Specify that the git tag `2.4.2` of `stdlib' should be checked out:
|
138
|
+
|
139
|
+
fixtures:
|
140
|
+
repositories:
|
141
|
+
firewall: "git://github.com/puppetlabs/puppetlabs-firewall"
|
142
|
+
stdlib:
|
143
|
+
repo: "git://github.com/puppetlabs/puppetlabs-stdlib"
|
144
|
+
ref: "2.6.0"
|
145
|
+
symlinks:
|
146
|
+
my_module: "#{source_dir}"
|
147
|
+
|
148
|
+
Install modules from Puppet Forge:
|
149
|
+
|
150
|
+
fixtures:
|
151
|
+
forge_modules:
|
152
|
+
firewall: "puppetlabs/firewall"
|
153
|
+
stdlib:
|
154
|
+
repo: "puppetlabs/stdlib"
|
155
|
+
ref: "2.6.0"
|
156
|
+
|
157
|
+
|
158
|
+
Testing Parser Functions
|
159
|
+
========================
|
160
|
+
|
161
|
+
This library provides a consistent way to create a Puppet::Parser::Scope object
|
162
|
+
suitable for use in a testing harness with the intent of testing the expected
|
163
|
+
behavior of parser functions distributed in modules.
|
164
|
+
|
165
|
+
Previously, modules would do something like this:
|
166
|
+
|
167
|
+
describe "split()" do
|
168
|
+
let(:scope) { Puppet::Parser::Scope.new }
|
169
|
+
it "should split 'one;two' on ';' into [ 'one', 'two' ]" do
|
170
|
+
scope.function_split(['one;two', ';']).should == [ 'one', 'two' ]
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
This will not work beyond Puppet 2.7 as we have changed the behavior of the
|
175
|
+
scope initializer in Puppet 3.0. Modules should instead initialize scope
|
176
|
+
instances in a manner decoupled from the internal behavior of Puppet:
|
177
|
+
|
178
|
+
require 'puppetlabs_spec_helper/puppetlabs_spec/puppet_internals'
|
179
|
+
describe "split()" do
|
180
|
+
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
181
|
+
it "should split 'one;two' on ';' into [ 'one', 'two' ]" do
|
182
|
+
scope.function_split(['one;two', ';']).should == [ 'one', 'two' ]
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
EOF
|
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/packagetask'
|
3
|
+
require 'rubygems/package_task'
|
4
|
+
|
5
|
+
task :default do
|
6
|
+
sh %{rake -T}
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'fileutils'
|
10
|
+
|
11
|
+
def version
|
12
|
+
require 'puppetlabs_spec_helper/version'
|
13
|
+
PuppetlabsSpecHelper::Version::STRING
|
14
|
+
end
|
15
|
+
|
16
|
+
namespace :package do
|
17
|
+
desc "Create the gem"
|
18
|
+
task :gem do
|
19
|
+
spec = Gem::Specification.load("puppetlabs_spec_helper.gemspec")
|
20
|
+
Dir.mkdir("pkg") rescue nil
|
21
|
+
if Gem::Version.new(`gem -v`) >= Gem::Version.new("2.0.0.a")
|
22
|
+
Gem::Package.build(spec)
|
23
|
+
else
|
24
|
+
Gem::Builder.new(spec).build
|
25
|
+
end
|
26
|
+
FileUtils.move("puppetlabs_spec_helper-#{version}.gem", "pkg")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
desc "Cleanup pkg directory"
|
31
|
+
task :clean do
|
32
|
+
FileUtils.rm_rf("pkg")
|
33
|
+
end
|
@@ -3,13 +3,8 @@ require 'puppetlabs_spec_helper/puppetlabs_spec_helper'
|
|
3
3
|
# Don't want puppet getting the command line arguments for rake or autotest
|
4
4
|
ARGV.clear
|
5
5
|
|
6
|
-
# This is needed because we're using mocha with rspec instead of Test::Unit or MiniTest
|
7
|
-
ENV['MOCHA_OPTIONS']='skip_integration'
|
8
|
-
|
9
6
|
require 'puppet'
|
10
|
-
gem 'rspec', '>=2.0.0'
|
11
7
|
require 'rspec/expectations'
|
12
|
-
require 'mocha/api'
|
13
8
|
|
14
9
|
require 'pathname'
|
15
10
|
require 'tmpdir'
|
@@ -153,8 +148,6 @@ end
|
|
153
148
|
|
154
149
|
# And here is where we do the main rspec configuration / setup.
|
155
150
|
RSpec.configure do |config|
|
156
|
-
config.mock_with :mocha
|
157
|
-
|
158
151
|
# determine whether we can use the new API or not, and call the appropriate initializer method.
|
159
152
|
if (defined?(Puppet::Test::TestHelper))
|
160
153
|
Puppet::PuppetSpecInitializer.initialize_via_testhelper(config)
|
@@ -7,7 +7,13 @@ task :default => [:help]
|
|
7
7
|
desc "Run spec tests on an existing fixtures directory"
|
8
8
|
RSpec::Core::RakeTask.new(:spec_standalone) do |t|
|
9
9
|
t.rspec_opts = ['--color']
|
10
|
-
t.pattern = 'spec/{classes,defines,unit,functions,hosts}/**/*_spec.rb'
|
10
|
+
t.pattern = 'spec/{classes,defines,unit,functions,hosts,integration}/**/*_spec.rb'
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "Run beaker acceptance tests"
|
14
|
+
RSpec::Core::RakeTask.new(:beaker) do |t|
|
15
|
+
t.rspec_opts = ['--color']
|
16
|
+
t.pattern = 'spec/acceptance'
|
11
17
|
end
|
12
18
|
|
13
19
|
desc "Generate code coverage information"
|
@@ -33,7 +39,7 @@ def fixtures(category)
|
|
33
39
|
end
|
34
40
|
|
35
41
|
result = {}
|
36
|
-
if fixtures.include? category
|
42
|
+
if fixtures.include? category and fixtures[category] != nil
|
37
43
|
fixtures[category].each do |fixture, opts|
|
38
44
|
if opts.instance_of?(String)
|
39
45
|
source = opts
|
@@ -43,33 +49,78 @@ def fixtures(category)
|
|
43
49
|
elsif opts.instance_of?(Hash)
|
44
50
|
target = "spec/fixtures/modules/#{fixture}"
|
45
51
|
real_source = eval('"'+opts["repo"]+'"')
|
46
|
-
result[real_source] = { "target" => target, "ref" => opts["ref"] }
|
52
|
+
result[real_source] = { "target" => target, "ref" => opts["ref"], "scm" => opts["scm"] }
|
47
53
|
end
|
48
54
|
end
|
49
55
|
end
|
50
56
|
return result
|
51
57
|
end
|
52
58
|
|
59
|
+
def clone(scm, remote, target, ref=nil)
|
60
|
+
args = []
|
61
|
+
case scm
|
62
|
+
when 'hg'
|
63
|
+
args.push('clone')
|
64
|
+
args.push('-u', ref) if ref
|
65
|
+
args.push(remote, target)
|
66
|
+
when 'git'
|
67
|
+
args.push('clone', remote, target)
|
68
|
+
else
|
69
|
+
fail "Unfortunately #{scm} is not supported yet"
|
70
|
+
end
|
71
|
+
system("#{scm} #{args.flatten.join ' '}")
|
72
|
+
end
|
73
|
+
|
74
|
+
def revision(scm, target, ref)
|
75
|
+
args = []
|
76
|
+
case scm
|
77
|
+
when 'hg'
|
78
|
+
args.push('update', 'clean', '-r', ref)
|
79
|
+
when 'git'
|
80
|
+
args.push('reset', '--hard', ref)
|
81
|
+
else
|
82
|
+
fail "Unfortunately #{scm} is not supported yet"
|
83
|
+
end
|
84
|
+
system("cd #{target} && #{scm} #{args.flatten.join ' '}")
|
85
|
+
end
|
86
|
+
|
53
87
|
desc "Create the fixtures directory"
|
54
88
|
task :spec_prep do
|
55
89
|
fixtures("repositories").each do |remote, opts|
|
90
|
+
scm = 'git'
|
56
91
|
if opts.instance_of?(String)
|
57
92
|
target = opts
|
58
|
-
ref = "refs/remotes/origin/master"
|
59
93
|
elsif opts.instance_of?(Hash)
|
60
94
|
target = opts["target"]
|
61
95
|
ref = opts["ref"]
|
96
|
+
scm = opts["scm"] if opts["scm"]
|
62
97
|
end
|
63
98
|
|
64
|
-
unless File::exists?(target) ||
|
65
|
-
fail "Failed to clone #{remote} into #{target}"
|
99
|
+
unless File::exists?(target) || clone(scm, remote, target, ref)
|
100
|
+
fail "Failed to clone #{scm} repository #{remote} into #{target}"
|
66
101
|
end
|
67
|
-
|
102
|
+
revision(scm, target, ref) if ref
|
68
103
|
end
|
69
104
|
|
70
105
|
FileUtils::mkdir_p("spec/fixtures/modules")
|
71
106
|
fixtures("symlinks").each do |source, target|
|
72
|
-
File::exists?(target) || FileUtils::
|
107
|
+
File::exists?(target) || FileUtils::ln_sf(source, target)
|
108
|
+
end
|
109
|
+
|
110
|
+
fixtures("forge_modules").each do |remote, opts|
|
111
|
+
if opts.instance_of?(String)
|
112
|
+
target = opts
|
113
|
+
ref = ""
|
114
|
+
elsif opts.instance_of?(Hash)
|
115
|
+
target = opts["target"]
|
116
|
+
ref = "--version #{opts['ref']}"
|
117
|
+
end
|
118
|
+
next if File::exists?(target)
|
119
|
+
unless system("puppet module install " + ref + \
|
120
|
+
" --ignore-dependencies" \
|
121
|
+
" --target-dir spec/fixtures/modules #{remote}")
|
122
|
+
fail "Failed to install module #{remote} to #{target}"
|
123
|
+
end
|
73
124
|
end
|
74
125
|
|
75
126
|
FileUtils::mkdir_p("spec/fixtures/manifests")
|
@@ -87,13 +138,23 @@ task :spec_clean do
|
|
87
138
|
FileUtils::rm_rf(target)
|
88
139
|
end
|
89
140
|
|
141
|
+
fixtures("forge_modules").each do |remote, opts|
|
142
|
+
if opts.instance_of?(String)
|
143
|
+
target = opts
|
144
|
+
elsif opts.instance_of?(Hash)
|
145
|
+
target = opts["target"]
|
146
|
+
end
|
147
|
+
FileUtils::rm_rf(target)
|
148
|
+
end
|
149
|
+
|
90
150
|
fixtures("symlinks").each do |source, target|
|
91
|
-
FileUtils::
|
151
|
+
FileUtils::rm_f(target)
|
92
152
|
end
|
93
|
-
|
94
|
-
if File
|
95
|
-
FileUtils::
|
153
|
+
|
154
|
+
if File.zero?("spec/fixtures/manifests/site.pp")
|
155
|
+
FileUtils::rm_f("spec/fixtures/manifests/site.pp")
|
96
156
|
end
|
157
|
+
|
97
158
|
end
|
98
159
|
|
99
160
|
desc "Run spec tests in a clean fixtures directory"
|
@@ -103,6 +164,14 @@ task :spec do
|
|
103
164
|
Rake::Task[:spec_clean].invoke
|
104
165
|
end
|
105
166
|
|
167
|
+
desc "List available beaker nodesets"
|
168
|
+
task :beaker_nodes do
|
169
|
+
Dir['spec/acceptance/nodesets/*.yml'].sort!.select { |node|
|
170
|
+
node.slice!('.yml')
|
171
|
+
puts File.basename(node)
|
172
|
+
}
|
173
|
+
end
|
174
|
+
|
106
175
|
desc "Build puppet module package"
|
107
176
|
task :build do
|
108
177
|
# This will be deprecated once puppet-module is a face.
|
@@ -123,6 +192,21 @@ end
|
|
123
192
|
desc "Check puppet manifests with puppet-lint"
|
124
193
|
task :lint do
|
125
194
|
require 'puppet-lint/tasks/puppet-lint'
|
195
|
+
PuppetLint.configuration.ignore_paths = ["spec/fixtures/**/*.pp"]
|
196
|
+
end
|
197
|
+
|
198
|
+
desc "Check puppet manifest syntax"
|
199
|
+
task :syntax do
|
200
|
+
require 'puppet/face'
|
201
|
+
parser = Puppet::Face['parser', :current]
|
202
|
+
|
203
|
+
RakeFileUtils.send(:verbose, true) do
|
204
|
+
matched_files = FileList['**/*.pp'].exclude 'spec/fixtures/**/*.pp'
|
205
|
+
|
206
|
+
matched_files.to_a.each do |puppet_file|
|
207
|
+
parser.validate(puppet_file)
|
208
|
+
end
|
209
|
+
end
|
126
210
|
end
|
127
211
|
|
128
212
|
desc "Display the list of available rake tasks"
|
@@ -0,0 +1,5 @@
|
|
1
|
+
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'lib'))
|
2
|
+
|
3
|
+
require 'puppetlabs_spec_helper/puppet_spec_helper'
|
4
|
+
|
5
|
+
puts "Using 'PROJECT_ROOT/puppet_spec_helper' is deprecated, please install as a gem and require 'puppetlabs_spec_helper/puppet_spec_helper' instead"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
3
|
+
require "puppetlabs_spec_helper/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "puppetlabs_spec_helper"
|
7
|
+
s.version = PuppetlabsSpecHelper::Version::STRING
|
8
|
+
s.authors = ["Puppet Labs"]
|
9
|
+
s.email = ["modules-dept@puppetlabs.com"]
|
10
|
+
s.homepage = "http://github.com/puppetlabs/puppetlabs_spec_helper"
|
11
|
+
s.summary = "Standard tasks and configuration for module spec tests"
|
12
|
+
s.description = "Contains rake tasks and a standard spec_helper for running spec tests on puppet modules"
|
13
|
+
s.licenses = 'Apache-2.0'
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
|
19
|
+
# Runtime dependencies, but also probably dependencies of requiring projects
|
20
|
+
s.add_runtime_dependency 'rake'
|
21
|
+
s.add_runtime_dependency 'rspec-puppet'
|
22
|
+
s.add_runtime_dependency 'puppet'
|
23
|
+
s.add_runtime_dependency 'puppet-lint'
|
24
|
+
s.add_runtime_dependency 'rspec'
|
25
|
+
end
|
@@ -0,0 +1,5 @@
|
|
1
|
+
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'lib'))
|
2
|
+
|
3
|
+
require 'puppetlabs_spec_helper/puppetlabs_spec_helper'
|
4
|
+
|
5
|
+
puts "Using 'PROJECT_ROOT/puppetlabs_spec_helper' is deprecated, please install as a gem and require 'puppetlabs_spec_helper/puppetlabs_spec_helper' instead"
|
@@ -0,0 +1,92 @@
|
|
1
|
+
#! /usr/bin/env ruby -S rspec
|
2
|
+
|
3
|
+
require 'puppetlabs_spec_helper/puppet_spec_helper'
|
4
|
+
require 'puppetlabs_spec_helper/puppetlabs_spec/puppet_internals'
|
5
|
+
|
6
|
+
describe PuppetlabsSpec::PuppetInternals do
|
7
|
+
describe ".scope" do
|
8
|
+
it "should return a Puppet::Parser::Scope instance" do
|
9
|
+
subject.scope.should be_a_kind_of Puppet::Parser::Scope
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should be suitable for function testing" do
|
13
|
+
scope = subject.scope
|
14
|
+
scope.function_split(["one;two", ";"]).should == [ 'one', 'two' ]
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should accept a compiler" do
|
18
|
+
compiler = subject.compiler
|
19
|
+
|
20
|
+
scope = subject.scope(:compiler => compiler)
|
21
|
+
|
22
|
+
scope.compiler.should == compiler
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should have a source set" do
|
26
|
+
scope = subject.scope
|
27
|
+
|
28
|
+
scope.source.should_not be_nil
|
29
|
+
scope.source.should_not be_false
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe ".resource" do
|
34
|
+
it "can have a defined type" do
|
35
|
+
subject.resource(:type => :node).type.should == :node
|
36
|
+
end
|
37
|
+
|
38
|
+
it "defaults to a type of hostclass" do
|
39
|
+
subject.resource.type.should == :hostclass
|
40
|
+
end
|
41
|
+
|
42
|
+
it "can have a defined name" do
|
43
|
+
subject.resource(:name => "testingrsrc").name.should == "testingrsrc"
|
44
|
+
end
|
45
|
+
|
46
|
+
it "defaults to a name of testing" do
|
47
|
+
subject.resource.name.should == "testing"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe ".compiler" do
|
52
|
+
let(:node) { subject.node }
|
53
|
+
|
54
|
+
it "can have a defined node" do
|
55
|
+
subject.compiler(:node => node).node.should be node
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe ".node" do
|
60
|
+
it "can have a defined name" do
|
61
|
+
subject.node(:name => "mine").name.should == "mine"
|
62
|
+
end
|
63
|
+
|
64
|
+
it "can have a defined environment" do
|
65
|
+
subject.node(:environment => "mine").environment.name.should == :mine
|
66
|
+
end
|
67
|
+
|
68
|
+
it "defaults to a name of testinghost" do
|
69
|
+
subject.node.name.should == "testinghost"
|
70
|
+
end
|
71
|
+
|
72
|
+
it "accepts facts via options for rspec-puppet" do
|
73
|
+
fact_values = { 'fqdn' => "jeff.puppetlabs.com" }
|
74
|
+
node = subject.node(:options => { :parameters => fact_values })
|
75
|
+
node.parameters.should == fact_values
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe ".function_method" do
|
80
|
+
it "accepts an injected scope" do
|
81
|
+
Puppet::Parser::Functions.expects(:function).with("my_func").returns(true)
|
82
|
+
scope = mock()
|
83
|
+
scope.expects(:method).with(:function_my_func).returns(:fake_method)
|
84
|
+
subject.function_method("my_func", :scope => scope).should == :fake_method
|
85
|
+
end
|
86
|
+
it "returns nil if the function doesn't exist" do
|
87
|
+
Puppet::Parser::Functions.expects(:function).with("my_func").returns(false)
|
88
|
+
scope = mock()
|
89
|
+
subject.function_method("my_func", :scope => scope).should be_nil
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'puppetlabs_spec_helper/puppet_spec_helper'
|
3
|
+
|
4
|
+
# ensure we can access puppet settings outside of any example group
|
5
|
+
Puppet[:confdir]
|
6
|
+
|
7
|
+
# set modulepath from which to load custom type
|
8
|
+
Puppet[:modulepath] = File.join(File.dirname(__FILE__), '..', '..')
|
9
|
+
|
10
|
+
def should_be_able_to_load_types?
|
11
|
+
return true if Puppet::Test::TestHelper.respond_to?(:initialize)
|
12
|
+
|
13
|
+
case Puppet.version
|
14
|
+
when /^2\.7\.20/
|
15
|
+
false
|
16
|
+
when /^3\.0\./
|
17
|
+
false
|
18
|
+
else
|
19
|
+
true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# construct a top-level describe block whose declared_class is a custom type in this module
|
24
|
+
describe Puppet::Type.type(:spechelper) do
|
25
|
+
it "should load the type from the modulepath" do
|
26
|
+
pending("this is only supported on newer versions of puppet", :unless => should_be_able_to_load_types?) do
|
27
|
+
described_class.should be
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should have a doc string" do
|
32
|
+
pending("this is only supported on newer versions of puppet", :unless => should_be_able_to_load_types?) do
|
33
|
+
described_class.doc.should == "This is the spechelper type"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "Setup of settings" do
|
39
|
+
it "sets confdir and vardir to something not meaningful to force tests to make their choice explicit" do
|
40
|
+
Puppet[:confdir].should == "/dev/null"
|
41
|
+
Puppet[:vardir].should == "/dev/null"
|
42
|
+
end
|
43
|
+
end
|
data/spec/watchr.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
ENV['FOG_MOCK'] ||= 'true'
|
2
|
+
ENV['AUTOTEST'] = 'true'
|
3
|
+
ENV['WATCHR'] = '1'
|
4
|
+
|
5
|
+
system 'clear'
|
6
|
+
|
7
|
+
def growl(message)
|
8
|
+
growlnotify = `which growlnotify`.chomp
|
9
|
+
title = "Watchr Test Results"
|
10
|
+
image = case message
|
11
|
+
when /(\d+)\s+?(failure|error)/i
|
12
|
+
($1.to_i == 0) ? "~/.watchr_images/passed.png" : "~/.watchr_images/failed.png"
|
13
|
+
else
|
14
|
+
'~/.watchr_images/unknown.png'
|
15
|
+
end
|
16
|
+
options = "-w -n Watchr --image '#{File.expand_path(image)}' -m '#{message}' '#{title}'"
|
17
|
+
system %(#{growlnotify} #{options} &)
|
18
|
+
end
|
19
|
+
|
20
|
+
def run(cmd)
|
21
|
+
puts(cmd)
|
22
|
+
`#{cmd}`
|
23
|
+
end
|
24
|
+
|
25
|
+
def run_spec_test(file)
|
26
|
+
if File.exist? file
|
27
|
+
result = run "rspec --format p --color #{file}"
|
28
|
+
growl result.split("\n").last
|
29
|
+
puts result
|
30
|
+
else
|
31
|
+
puts "FIXME: No test #{file} [#{Time.now}]"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def filter_rspec(data)
|
36
|
+
data.split("\n").find_all do |l|
|
37
|
+
l =~ /^(\d+)\s+exampl\w+.*?(\d+).*?failur\w+.*?(\d+).*?pending/
|
38
|
+
end.join("\n")
|
39
|
+
end
|
40
|
+
|
41
|
+
def run_all_tests
|
42
|
+
system('clear')
|
43
|
+
files = Dir.glob("spec/**/*_spec.rb").join(" ")
|
44
|
+
result = run "rspec #{files}"
|
45
|
+
growl_results = filter_rspec result
|
46
|
+
growl growl_results
|
47
|
+
puts result
|
48
|
+
puts "GROWL: #{growl_results}"
|
49
|
+
end
|
50
|
+
|
51
|
+
# Ctrl-\
|
52
|
+
Signal.trap 'QUIT' do
|
53
|
+
puts " --- Running all tests ---\n\n"
|
54
|
+
run_all_tests
|
55
|
+
end
|
56
|
+
|
57
|
+
@interrupted = false
|
58
|
+
|
59
|
+
# Ctrl-C
|
60
|
+
Signal.trap 'INT' do
|
61
|
+
if @interrupted then
|
62
|
+
@wants_to_quit = true
|
63
|
+
abort("\n")
|
64
|
+
else
|
65
|
+
puts "Interrupt a second time to quit"
|
66
|
+
@interrupted = true
|
67
|
+
Kernel.sleep 1.5
|
68
|
+
# raise Interrupt, nil # let the run loop catch it
|
69
|
+
run_suite
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
watch( 'spec/.*_spec\.rb' ) do |md|
|
74
|
+
run_all_tests
|
75
|
+
end
|
76
|
+
|
77
|
+
watch( 'lib/.*\.rb' ) do |md|
|
78
|
+
run_all_tests
|
79
|
+
end
|
metadata
CHANGED
@@ -1,94 +1,100 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppetlabs_spec_helper
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 4
|
9
|
-
- 1
|
10
|
-
version: 0.4.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Puppet Labs
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2014-06-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
21
14
|
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
22
21
|
prerelease: false
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec-puppet
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
32
34
|
type: :runtime
|
33
|
-
version_requirements: *id001
|
34
|
-
- !ruby/object:Gem::Dependency
|
35
|
-
name: rspec
|
36
35
|
prerelease: false
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: puppet
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
48
|
type: :runtime
|
49
|
-
version_requirements: *id002
|
50
|
-
- !ruby/object:Gem::Dependency
|
51
|
-
name: mocha
|
52
49
|
prerelease: false
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: puppet-lint
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
64
62
|
type: :runtime
|
65
|
-
version_requirements: *id003
|
66
|
-
- !ruby/object:Gem::Dependency
|
67
|
-
name: rspec-puppet
|
68
63
|
prerelease: false
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
80
76
|
type: :runtime
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
-
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Contains rake tasks and a standard spec_helper for running spec tests
|
84
|
+
on puppet modules
|
85
|
+
email:
|
86
|
+
- modules-dept@puppetlabs.com
|
85
87
|
executables: []
|
86
|
-
|
87
88
|
extensions: []
|
88
|
-
|
89
89
|
extra_rdoc_files: []
|
90
|
-
|
91
|
-
|
90
|
+
files:
|
91
|
+
- .gitignore
|
92
|
+
- .noexec.yaml
|
93
|
+
- CHANGELOG
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE
|
96
|
+
- README.markdown
|
97
|
+
- Rakefile
|
92
98
|
- lib/puppetlabs_spec_helper/module_spec_helper.rb
|
93
99
|
- lib/puppetlabs_spec_helper/puppet_spec_helper.rb
|
94
100
|
- lib/puppetlabs_spec_helper/puppetlabs_spec/files.rb
|
@@ -97,40 +103,40 @@ files:
|
|
97
103
|
- lib/puppetlabs_spec_helper/puppetlabs_spec/puppet_internals.rb
|
98
104
|
- lib/puppetlabs_spec_helper/puppetlabs_spec_helper.rb
|
99
105
|
- lib/puppetlabs_spec_helper/rake_tasks.rb
|
100
|
-
-
|
101
|
-
-
|
106
|
+
- lib/puppetlabs_spec_helper/version.rb
|
107
|
+
- puppet_spec_helper.rb
|
108
|
+
- puppetlabs_spec_helper.gemspec
|
109
|
+
- puppetlabs_spec_helper.rb
|
110
|
+
- spec/lib/puppet/type/spechelper.rb
|
111
|
+
- spec/unit/puppetlabs_spec_helper/puppetlabs_spec/puppet_internals_spec.rb
|
112
|
+
- spec/unit/spechelper_spec.rb
|
113
|
+
- spec/watchr.rb
|
102
114
|
homepage: http://github.com/puppetlabs/puppetlabs_spec_helper
|
103
|
-
licenses:
|
104
|
-
|
115
|
+
licenses:
|
116
|
+
- Apache-2.0
|
117
|
+
metadata: {}
|
105
118
|
post_install_message:
|
106
119
|
rdoc_options: []
|
107
|
-
|
108
|
-
require_paths:
|
120
|
+
require_paths:
|
109
121
|
- lib
|
110
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
none: false
|
121
|
-
requirements:
|
122
|
-
- - ">="
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
hash: 3
|
125
|
-
segments:
|
126
|
-
- 0
|
127
|
-
version: "0"
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
128
132
|
requirements: []
|
129
|
-
|
130
133
|
rubyforge_project:
|
131
|
-
rubygems_version:
|
134
|
+
rubygems_version: 2.0.14
|
132
135
|
signing_key:
|
133
|
-
specification_version:
|
136
|
+
specification_version: 4
|
134
137
|
summary: Standard tasks and configuration for module spec tests
|
135
|
-
test_files:
|
136
|
-
|
138
|
+
test_files:
|
139
|
+
- spec/lib/puppet/type/spechelper.rb
|
140
|
+
- spec/unit/puppetlabs_spec_helper/puppetlabs_spec/puppet_internals_spec.rb
|
141
|
+
- spec/unit/spechelper_spec.rb
|
142
|
+
- spec/watchr.rb
|