]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/spec/functions/get_module_path_spec.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / get_module_path_spec.rb
1 #! /usr/bin/env ruby -S rspec
2 require 'spec_helper'
3
4 describe Puppet::Parser::Functions.function(:get_module_path) do
5   Internals = PuppetlabsSpec::PuppetInternals
6   class StubModule
7     attr_reader :path
8     def initialize(path)
9       @path = path
10     end
11   end
12
13   def scope(environment = "production")
14     Internals.scope(:compiler => Internals.compiler(:node => Internals.node(:environment => environment)))
15   end
16
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/)
20   end
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/)
23   end
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") }
27
28     before(:each) { Puppet[:modulepath] = modulepath }
29
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)
33     end
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)
38     end
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)
44     end
45   end
46 end