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 Method Summary collapse

Instance Method Details

#call_function(function_name, *args) ⇒ Object



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

def call_function(function_name, *args)
#      function = find_function(function_name)
#      function.execute(*args)
 scope.call_function(function_name, args)
end

#catalogueObject



114
115
116
# File 'lib/rspec-puppet/example/function_example_group.rb', line 114

def catalogue
  @catalogue ||= compiler.catalog
end

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



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

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

    if Puppet.version.to_f >= 4.0
      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
    end

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

#rspec_puppet_cleanupObject



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

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

#scopeObject



110
111
112
# File 'lib/rspec-puppet/example/function_example_group.rb', line 110

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.



78
79
80
# File 'lib/rspec-puppet/example/function_example_group.rb', line 78

def subject
  @subject ||= find_function
end