Module: PuppetlabsSpec::PuppetInternals
- Defined in:
- lib/puppetlabs_spec_helper/puppetlabs_spec/puppet_internals.rb
Overview
PuppetInternals provides a set of methods that interface with internal puppet implementations.
Class Method Summary collapse
- .compiler(parts = {}) ⇒ Object
-
.function_method(name, parts = {}) ⇒ Object
Return a method instance for a given function.
- .node(parts = {}) ⇒ Object
- .resource(parts = {}) ⇒ Object
Class Method Details
.compiler(parts = {}) ⇒ Object
18 19 20 21 |
# File 'lib/puppetlabs_spec_helper/puppetlabs_spec/puppet_internals.rb', line 18 def compiler(parts = {}) compiler_node = parts[:node] || node Puppet::Parser::Compiler.new(compiler_node) end |
.function_method(name, parts = {}) ⇒ Object
Return a method instance for a given function. This is primarily useful for rspec-puppet
35 36 37 38 39 40 41 42 43 |
# File 'lib/puppetlabs_spec_helper/puppetlabs_spec/puppet_internals.rb', line 35 def function_method(name, parts = {}) scope = parts[:scope] || scope() # Ensure the method instance is defined by side-effect of checking if it # exists. This is a hack, but at least it's a hidden hack and not an # exposed hack. return nil unless Puppet::Parser::Functions.function(name) scope.method(:"function_#{name}") end |
.node(parts = {}) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/puppetlabs_spec_helper/puppetlabs_spec/puppet_internals.rb', line 24 def node(parts = {}) node_name = parts[:name] || 'testinghost' = parts[:options] || {} node_environment = Puppet::Node::Environment.create(parts[:environment] || 'test', []) [:environment] = node_environment Puppet::Node.new(node_name, ) end |
.resource(parts = {}) ⇒ Object
11 12 13 14 15 |
# File 'lib/puppetlabs_spec_helper/puppetlabs_spec/puppet_internals.rb', line 11 def resource(parts = {}) resource_type = parts[:type] || :hostclass resource_name = parts[:name] || 'testing' Puppet::Resource::Type.new(resource_type, resource_name) end |