Update puppetlabs/stdlib module
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / get_module_path_spec.rb
1 require 'spec_helper'
2
3 describe 'get_module_path' do
4   it { is_expected.not_to eq(nil) }
5   it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{Wrong number of arguments, expects one}) }
6   it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, %r{Wrong number of arguments, expects one}) }
7   it { is_expected.to run.with_params('one', 'two', 'three').and_raise_error(Puppet::ParseError, %r{Wrong number of arguments, expects one}) }
8   it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, %r{Could not find module}) }
9
10   # class Stubmodule
11   class StubModule
12     attr_reader :path
13     def initialize(path)
14       @path = path
15     end
16   end
17
18   describe 'when locating a module' do
19     let(:modulepath) { '/tmp/does_not_exist' }
20     let(:path_of_module_foo) { StubModule.new('/tmp/does_not_exist/foo') }
21
22     before(:each) do
23       Puppet[:modulepath] = modulepath
24     end
25
26     context 'when in the default environment' do
27       before(:each) do
28         allow(Puppet::Module).to receive(:find).with('foo', 'rp_env').and_return(path_of_module_foo)
29       end
30       it 'runs against foo' do
31         is_expected.to run.with_params('foo').and_return(path_of_module_foo.path)
32       end
33
34       it 'when the modulepath is a list' do
35         Puppet[:modulepath] = modulepath + 'tmp/something_else'
36
37         is_expected.to run.with_params('foo').and_return(path_of_module_foo.path)
38       end
39     end
40
41     context 'when in a non-default default environment' do
42       let(:environment) { 'test' }
43
44       before(:each) do
45         allow(Puppet::Module).to receive(:find).with('foo', 'test').and_return(path_of_module_foo)
46       end
47       it 'runs against foo' do
48         is_expected.to run.with_params('foo').and_return(path_of_module_foo.path)
49       end
50
51       it 'when the modulepath is a list' do
52         Puppet[:modulepath] = modulepath + 'tmp/something_else'
53         is_expected.to run.with_params('foo').and_return(path_of_module_foo.path)
54       end
55     end
56   end
57 end