rspec-puppet 2.2.0 → 2.3.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 +43 -0
- data/README.md +195 -39
- data/lib/rspec-puppet/cache.rb +30 -0
- data/lib/rspec-puppet/coverage.rb +76 -47
- data/lib/rspec-puppet/errors.rb +11 -3
- data/lib/rspec-puppet/example/class_example_group.rb +4 -0
- data/lib/rspec-puppet/example/define_example_group.rb +4 -0
- data/lib/rspec-puppet/example/function_example_group.rb +33 -1
- data/lib/rspec-puppet/example/host_example_group.rb +4 -0
- data/lib/rspec-puppet/example/provider_example_group.rb +4 -0
- data/lib/rspec-puppet/example/type_example_group.rb +26 -0
- data/lib/rspec-puppet/example.rb +16 -1
- data/lib/rspec-puppet/matchers/compile.rb +14 -3
- data/lib/rspec-puppet/matchers/create_generic.rb +72 -16
- data/lib/rspec-puppet/matchers/dynamic_matchers.rb +7 -0
- data/lib/rspec-puppet/matchers/include_class.rb +1 -1
- data/lib/rspec-puppet/matchers/run.rb +3 -2
- data/lib/rspec-puppet/matchers/type_matchers.rb +161 -0
- data/lib/rspec-puppet/matchers.rb +1 -0
- data/lib/rspec-puppet/rake_task.rb +20 -0
- data/lib/rspec-puppet/setup.rb +7 -34
- data/lib/rspec-puppet/spec_helper.rb +9 -0
- data/lib/rspec-puppet/support.rb +55 -60
- data/lib/rspec-puppet.rb +1 -1
- metadata +17 -11
data/lib/rspec-puppet/support.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
+
require 'rspec-puppet/cache'
|
1
2
|
module RSpec::Puppet
|
2
3
|
module Support
|
3
4
|
|
4
|
-
@@cache =
|
5
|
+
@@cache = RSpec::Puppet::Cache.new
|
5
6
|
|
6
7
|
def subject
|
7
8
|
lambda { catalogue }
|
@@ -35,22 +36,25 @@ module RSpec::Puppet
|
|
35
36
|
end
|
36
37
|
|
37
38
|
def import_str
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
39
|
+
import_str = ""
|
40
|
+
Puppet[:modulepath].split(File::PATH_SEPARATOR).each { |d|
|
41
|
+
if File.exists?(File.join(d, 'manifests', 'init.pp'))
|
42
|
+
path_to_manifest = File.join([
|
43
|
+
d,
|
44
|
+
'manifests',
|
45
|
+
class_name.split('::')[1..-1]
|
46
|
+
].flatten)
|
47
|
+
import_str = [
|
48
|
+
"import '#{d}/manifests/init.pp'",
|
49
|
+
"import '#{path_to_manifest}.pp'",
|
50
|
+
'',
|
51
|
+
].join("\n")
|
52
|
+
break
|
53
|
+
elsif File.exists?(d)
|
54
|
+
import_str = "import '#{Puppet[:manifest]}'\n"
|
55
|
+
break
|
56
|
+
end
|
57
|
+
}
|
54
58
|
|
55
59
|
import_str
|
56
60
|
end
|
@@ -118,8 +122,13 @@ module RSpec::Puppet
|
|
118
122
|
|
119
123
|
def param_str
|
120
124
|
params.keys.map do |r|
|
121
|
-
param_val =
|
122
|
-
|
125
|
+
param_val = params[r]
|
126
|
+
param_val_str = if param_val == :undef
|
127
|
+
'undef' # verbatim undef keyword
|
128
|
+
else
|
129
|
+
escape_special_chars(param_val.inspect)
|
130
|
+
end
|
131
|
+
"#{r.to_s} => #{param_val_str}"
|
123
132
|
end.join(', ')
|
124
133
|
end
|
125
134
|
|
@@ -170,7 +179,9 @@ module RSpec::Puppet
|
|
170
179
|
end
|
171
180
|
end
|
172
181
|
|
173
|
-
|
182
|
+
Puppet[:modulepath].split(File::PATH_SEPARATOR).map do |d|
|
183
|
+
Dir["#{d}/*/lib"].entries
|
184
|
+
end.flatten.each do |lib|
|
174
185
|
$LOAD_PATH << lib
|
175
186
|
end
|
176
187
|
|
@@ -192,20 +203,17 @@ module RSpec::Puppet
|
|
192
203
|
|
193
204
|
stub_facts! facts_val
|
194
205
|
|
195
|
-
|
206
|
+
node_facts = Puppet::Node::Facts.new(nodename, facts_val.dup)
|
196
207
|
|
197
|
-
node_obj.
|
208
|
+
node_obj = Puppet::Node.new(nodename, { :parameters => facts_val, :facts => node_facts })
|
198
209
|
|
199
210
|
# trying to be compatible with 2.7 as well as 2.6
|
200
211
|
if Puppet::Resource::Catalog.respond_to? :find
|
201
212
|
Puppet::Resource::Catalog.find(node_obj.name, :use_node => node_obj)
|
202
213
|
elsif Puppet.version.to_f >= 4.0
|
203
|
-
env =
|
204
|
-
environment,
|
205
|
-
[File.join(Puppet[:environmentpath],'fixtures','modules')],
|
206
|
-
File.join(Puppet[:environmentpath],'fixtures','manifests'))
|
214
|
+
env = build_4x_environment(environment)
|
207
215
|
loader = Puppet::Environments::Static.new(env)
|
208
|
-
Puppet.override({:environments => loader}, '
|
216
|
+
Puppet.override({:environments => loader}, 'Setup test environment') do
|
209
217
|
node_obj.environment = env
|
210
218
|
Puppet::Resource::Catalog.indirection.find(node_obj.name, :use_node => node_obj)
|
211
219
|
end
|
@@ -219,13 +227,23 @@ module RSpec::Puppet
|
|
219
227
|
end
|
220
228
|
|
221
229
|
def build_catalog(*args)
|
222
|
-
@@cache
|
230
|
+
@@cache.get(*args) do |*args|
|
231
|
+
build_catalog_without_cache(*args)
|
232
|
+
end
|
223
233
|
end
|
224
234
|
|
235
|
+
# Facter currently supports lower case facts. Bug FACT-777 has been submitted to support case sensitive
|
236
|
+
# facts.
|
225
237
|
def munge_facts(facts)
|
226
|
-
|
227
|
-
|
228
|
-
|
238
|
+
return facts.reduce({}) do | memo, (k, v)|
|
239
|
+
memo.tap { |m| m[k.to_s.downcase] = munge_facts(v) }
|
240
|
+
end if facts.is_a? Hash
|
241
|
+
|
242
|
+
return facts.reduce([]) do |memo, v|
|
243
|
+
memo << munge_facts(v); memo
|
244
|
+
end if facts.is_a? Array
|
245
|
+
|
246
|
+
facts
|
229
247
|
end
|
230
248
|
|
231
249
|
def escape_special_chars(string)
|
@@ -233,35 +251,6 @@ module RSpec::Puppet
|
|
233
251
|
string
|
234
252
|
end
|
235
253
|
|
236
|
-
def build_scope(compiler, node_name)
|
237
|
-
if Puppet.version =~ /^2\.[67]/
|
238
|
-
# loadall should only be necessary prior to 3.x
|
239
|
-
# Please note, loadall needs to happen first when creating a scope, otherwise
|
240
|
-
# you might receive undefined method `function_*' errors
|
241
|
-
Puppet::Parser::Functions.autoloader.loadall
|
242
|
-
scope = Puppet::Parser::Scope.new(:compiler => compiler)
|
243
|
-
else
|
244
|
-
scope = Puppet::Parser::Scope.new(compiler)
|
245
|
-
end
|
246
|
-
|
247
|
-
scope.source = Puppet::Resource::Type.new(:node, node_name)
|
248
|
-
scope.parent = compiler.topscope
|
249
|
-
scope
|
250
|
-
end
|
251
|
-
|
252
|
-
def build_node(name, opts = {})
|
253
|
-
if Puppet.version.to_f >= 4.0
|
254
|
-
node_environment = Puppet::Node::Environment.create(
|
255
|
-
environment,
|
256
|
-
[File.join(Puppet[:environmentpath],'fixtures','modules')],
|
257
|
-
File.join(Puppet[:environmentpath],'fixtures','manifests'))
|
258
|
-
else
|
259
|
-
node_environment = Puppet::Node::Environment.new(environment)
|
260
|
-
end
|
261
|
-
opts.merge!({:environment => node_environment})
|
262
|
-
Puppet::Node.new(name, opts)
|
263
|
-
end
|
264
|
-
|
265
254
|
def rspec_compatibility
|
266
255
|
if RSpec::Version::STRING < '3'
|
267
256
|
# RSpec 2 compatibility:
|
@@ -269,5 +258,11 @@ module RSpec::Puppet
|
|
269
258
|
alias_method :failure_message_for_should_not, :failure_message_when_negated
|
270
259
|
end
|
271
260
|
end
|
261
|
+
|
262
|
+
def build_4x_environment(name)
|
263
|
+
modulepath = RSpec.configuration.module_path || File.join(Puppet[:environmentpath], 'fixtures', 'modules')
|
264
|
+
manifest = RSpec.configuration.manifest || File.join(Puppet[:environmentpath], 'fixtures', 'manifests')
|
265
|
+
Puppet::Node::Environment.create(name, [modulepath], manifest)
|
266
|
+
end
|
272
267
|
end
|
273
268
|
end
|
data/lib/rspec-puppet.rb
CHANGED
@@ -15,7 +15,7 @@ end
|
|
15
15
|
|
16
16
|
RSpec.configure do |c|
|
17
17
|
c.add_setting :environmentpath, :default => '/etc/puppetlabs/code/environments'
|
18
|
-
c.add_setting :module_path, :default =>
|
18
|
+
c.add_setting :module_path, :default => nil
|
19
19
|
c.add_setting :manifest_dir, :default => nil
|
20
20
|
c.add_setting :manifest, :default => nil
|
21
21
|
c.add_setting :template_dir, :default => nil
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-puppet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Sharpe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
description: RSpec tests for your Puppet manifests
|
@@ -33,16 +33,16 @@ extra_rdoc_files: []
|
|
33
33
|
files:
|
34
34
|
- CHANGELOG.md
|
35
35
|
- README.md
|
36
|
-
-
|
37
|
-
- lib/rspec-puppet.rb
|
36
|
+
- lib/rspec-puppet/cache.rb
|
38
37
|
- lib/rspec-puppet/coverage.rb
|
39
38
|
- lib/rspec-puppet/errors.rb
|
40
|
-
- lib/rspec-puppet/example.rb
|
41
39
|
- lib/rspec-puppet/example/class_example_group.rb
|
42
40
|
- lib/rspec-puppet/example/define_example_group.rb
|
43
41
|
- lib/rspec-puppet/example/function_example_group.rb
|
44
42
|
- lib/rspec-puppet/example/host_example_group.rb
|
45
|
-
- lib/rspec-puppet/
|
43
|
+
- lib/rspec-puppet/example/provider_example_group.rb
|
44
|
+
- lib/rspec-puppet/example/type_example_group.rb
|
45
|
+
- lib/rspec-puppet/example.rb
|
46
46
|
- lib/rspec-puppet/matchers/compile.rb
|
47
47
|
- lib/rspec-puppet/matchers/count_generic.rb
|
48
48
|
- lib/rspec-puppet/matchers/create_generic.rb
|
@@ -50,8 +50,14 @@ files:
|
|
50
50
|
- lib/rspec-puppet/matchers/include_class.rb
|
51
51
|
- lib/rspec-puppet/matchers/parameter_matcher.rb
|
52
52
|
- lib/rspec-puppet/matchers/run.rb
|
53
|
+
- lib/rspec-puppet/matchers/type_matchers.rb
|
54
|
+
- lib/rspec-puppet/matchers.rb
|
55
|
+
- lib/rspec-puppet/rake_task.rb
|
53
56
|
- lib/rspec-puppet/setup.rb
|
57
|
+
- lib/rspec-puppet/spec_helper.rb
|
54
58
|
- lib/rspec-puppet/support.rb
|
59
|
+
- lib/rspec-puppet.rb
|
60
|
+
- bin/rspec-puppet-init
|
55
61
|
homepage: https://github.com/rodjek/rspec-puppet/
|
56
62
|
licenses:
|
57
63
|
- MIT
|
@@ -62,17 +68,17 @@ require_paths:
|
|
62
68
|
- lib
|
63
69
|
required_ruby_version: !ruby/object:Gem::Requirement
|
64
70
|
requirements:
|
65
|
-
- -
|
71
|
+
- - '>='
|
66
72
|
- !ruby/object:Gem::Version
|
67
73
|
version: '0'
|
68
74
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
75
|
requirements:
|
70
|
-
- -
|
76
|
+
- - '>='
|
71
77
|
- !ruby/object:Gem::Version
|
72
78
|
version: '0'
|
73
79
|
requirements: []
|
74
80
|
rubyforge_project:
|
75
|
-
rubygems_version: 2.
|
81
|
+
rubygems_version: 2.0.14
|
76
82
|
signing_key:
|
77
83
|
specification_version: 4
|
78
84
|
summary: RSpec tests for your Puppet manifests
|