77# PuppetInternals provides a set of methods that interface
88# with internal puppet implementations.
99module PuppetlabsSpec ::PuppetInternals
10- # parser_scope is intended to return a Puppet::Parser::Scope
11- # instance suitable for placing in a test harness with the intent of
12- # testing parser functions from modules.
13- def scope ( parts = { } )
14- RSpec . deprecate ( 'scope' , replacement : 'rspec-puppet 2.2.0 provides a scope property' )
15-
16- if %r{^2\. [67]} . match? ( Puppet . version )
17- # loadall should only be necessary prior to 3.x
18- # Please note, loadall needs to happen first when creating a scope, otherwise
19- # you might receive undefined method `function_*' errors
20- Puppet ::Parser ::Functions . autoloader . loadall
21- end
22-
23- scope_compiler = parts [ :compiler ] || compiler
24- scope_parent = parts [ :parent ] || scope_compiler . topscope
25-
26- scope = if %r{^2\. [67]} . match? ( Puppet . version )
27- Puppet ::Parser ::Scope . new ( compiler : scope_compiler )
28- else
29- Puppet ::Parser ::Scope . new ( scope_compiler )
30- end
31-
32- scope . source = Puppet ::Resource ::Type . new ( :node , 'foo' )
33- scope . parent = scope_parent
34- scope
35- end
36- module_function :scope
37-
3810 def resource ( parts = { } )
3911 resource_type = parts [ :type ] || :hostclass
4012 resource_name = parts [ :name ] || 'testing'
@@ -51,11 +23,7 @@ def compiler(parts = {})
5123 def node ( parts = { } )
5224 node_name = parts [ :name ] || 'testinghost'
5325 options = parts [ :options ] || { }
54- node_environment = if Puppet . version . to_f >= 4.0
55- Puppet ::Node ::Environment . create ( parts [ :environment ] || 'test' , [ ] )
56- else
57- Puppet ::Node ::Environment . new ( parts [ :environment ] || 'test' )
58- end
26+ node_environment = Puppet ::Node ::Environment . create ( parts [ :environment ] || 'test' , [ ] )
5927 options [ :environment ] = node_environment
6028 Puppet ::Node . new ( node_name , options )
6129 end
0 commit comments