Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/rspec-puppet/example/function_example_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ def find_function(function_name = self.class.top_level_description)
context_overrides = compiler.context_overrides
func = nil
loaders = Puppet.lookup(:loaders)

# allow loading functions from the environment
Puppet.override(context_overrides, "rspec-test scope") do
env_dirs = env.modulepath.map { |r| File.dirname(r) }
dir = env_dirs.find { |r| File.directory?(File.join(r, 'lib')) }
loader = Puppet::Pops::Loader::ModuleLoaders.environment_loader_from(loaders.private_environment_loader, loaders, dir)
func = V4FunctionWrapper.new(function_name, loader.load(:function, function_name), context_overrides)
@scope = context_overrides[:global_scope]
end

return func if func.func

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]
Expand Down Expand Up @@ -124,6 +136,10 @@ def rspec_puppet_cleanup

private

def loader_needs_lib?
!Puppet::Pops::Loader::LoaderPaths::FunctionPath4x::FUNCTION_PATH_4X.start_with?('lib')
end

def compiler
@compiler ||= build_compiler
end
Expand Down
9 changes: 9 additions & 0 deletions spec/fixtures/lib/puppet/functions/environment/upcase.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Puppet::Functions.create_function(:'environment::upcase') do
dispatch :up do
param 'String', :some_string
end

def up(some_string)
some_string.upcase
end
end
5 changes: 5 additions & 0 deletions spec/functions/environment_upcase_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'spec_helper'

describe 'environment::upcase', :if => Puppet.version.to_i >= 4 do
it { should run.with_params('aaa').and_return('AAA') }
end