1 #! /usr/bin/env ruby -S rspec
4 describe Puppet::Parser::Functions.function(:get_module_path) do
5 Internals = PuppetlabsSpec::PuppetInternals
13 def scope(environment = "production")
14 Internals.scope(:compiler => Internals.compiler(:node => Internals.node(:environment => environment)))
17 it 'should only allow one argument' do
18 expect { scope.function_get_module_path([]) }.to raise_error(Puppet::ParseError, /Wrong number of arguments, expects one/)
19 expect { scope.function_get_module_path(['1','2','3']) }.to raise_error(Puppet::ParseError, /Wrong number of arguments, expects one/)
21 it 'should raise an exception when the module cannot be found' do
22 expect { scope.function_get_module_path(['foo']) }.to raise_error(Puppet::ParseError, /Could not find module/)
24 describe 'when locating a module' do
25 let(:modulepath) { "/tmp/does_not_exist" }
26 let(:path_of_module_foo) { StubModule.new("/tmp/does_not_exist/foo") }
28 before(:each) { Puppet[:modulepath] = modulepath }
30 it 'should be able to find module paths from the modulepath setting' do
31 Puppet::Module.expects(:find).with('foo', 'production').returns(path_of_module_foo)
32 expect(scope.function_get_module_path(['foo'])).to eq(path_of_module_foo.path)
34 it 'should be able to find module paths when the modulepath is a list' do
35 Puppet[:modulepath] = modulepath + ":/tmp"
36 Puppet::Module.expects(:find).with('foo', 'production').returns(path_of_module_foo)
37 expect(scope.function_get_module_path(['foo'])).to eq(path_of_module_foo.path)
39 it 'should respect the environment' do
40 skip("Disabled on Puppet 2.6.x") if Puppet.version =~ /^2\.6\b/
41 Puppet.settings[:environment] = 'danstestenv'
42 Puppet::Module.expects(:find).with('foo', 'danstestenv').returns(path_of_module_foo)
43 expect(scope('danstestenv').function_get_module_path(['foo'])).to eq(path_of_module_foo.path)