Module: RSpec::Puppet::FunctionExampleGroup

Includes:
FunctionMatchers, ManifestMatchers, Support
Defined in:
lib/rspec-puppet/example/function_example_group.rb

Defined Under Namespace

Classes: V3FunctionWrapper, V4FunctionWrapper

Instance Attribute Summary

Attributes included from Support

#adapter

Instance Method Summary collapse

Methods included from Support

#build_catalog, #build_catalog_without_cache, #build_catalog_without_cache_v2, #build_code, #class_name, #environment, #escape_special_chars, #facts_hash, #find_pretend_platform, #fixture_spec_hiera_conf, #guess_type_from_path, #load_catalogue, #munge_facts, #node_params_hash, #nodename, #param_str, #param_str_from_hash, #post_cond, #pre_cond, #ref, #sanitise_resource_title, #sensitive, #server_facts_hash, #setup_puppet, #site_pp_str, #str_from_value, #stub_facts!, #stub_file_consts, #test_manifest, #trusted_external_data_hash, #trusted_facts_hash, #with_vardir

Methods included from GenericMatchers

#raise_error

Methods included from ManifestMatchers

#have_class_count, #have_resource_count, #method_missing

Methods included from FunctionMatchers

#method_missing

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RSpec::Puppet::ManifestMatchers

Instance Method Details

#call_function(function_name, *args) ⇒ Object



108
109
110
# File 'lib/rspec-puppet/example/function_example_group.rb', line 108

def call_function(function_name, *args)
  scope.call_function(function_name, args)
end

#catalogueObject



116
117
118
# File 'lib/rspec-puppet/example/function_example_group.rb', line 116

def catalogue
  @catalogue ||= compiler.catalog
end

#find_function(function_name = self.class.top_level_description) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/rspec-puppet/example/function_example_group.rb', line 87

def find_function(function_name = self.class.top_level_description)
  with_vardir do
    env = adapter.current_environment

    context_overrides = compiler.context_overrides
    func = nil
    loaders = Puppet.lookup(:loaders)
    Puppet.override(context_overrides, 'rspec-test scope') do
      func = V4FunctionWrapper.new(function_name,
                                   loaders.private_environment_loader.load(:function, function_name), context_overrides)
      @scope = context_overrides[:global_scope]
    end

    return func if func.func

    if Puppet::Parser::Functions.function(function_name)
      V3FunctionWrapper.new(function_name, scope.method(:"function_#{function_name}"))
    end
  end
end

#rspec_puppet_cleanupObject



120
121
122
123
124
125
# File 'lib/rspec-puppet/example/function_example_group.rb', line 120

def rspec_puppet_cleanup
  @subject = nil
  @catalogue = nil
  @compiler = nil
  @scope = nil
end

#scopeObject



112
113
114
# File 'lib/rspec-puppet/example/function_example_group.rb', line 112

def scope
  @scope ||= build_scope(compiler, nodename(:function))
end

#subjectObject

(at least) rspec 3.5 doesn’t seem to memoize ‘subject` when called from a before(:each) hook, so we need to memoize it ourselves.



83
84
85
# File 'lib/rspec-puppet/example/function_example_group.rb', line 83

def subject
  @subject ||= find_function
end