Update stdlib
[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, /Wrong number of arguments, expects one/) }
6   it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, /Wrong number of arguments, expects one/) }
7   it { is_expected.to run.with_params('one', 'two', 'three').and_raise_error(Puppet::ParseError, /Wrong number of arguments, expects one/) }
8   it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, /Could not find module/) }
9
10   class StubModule
11     attr_reader :path
12     def initialize(path)
13       @path = path
14     end
15   end
16
17   describe 'when locating a module' do
18     let(:modulepath) { "/tmp/does_not_exist" }
19     let(:path_of_module_foo) { StubModule.new("/tmp/does_not_exist/foo") }
20
21     before(:each) { Puppet[:modulepath] = modulepath }
22
23     context 'in the default environment' do
24       before(:each) { Puppet::Module.expects(:find).with('foo', 'rp_env').returns(path_of_module_foo) }
25
26       it { is_expected.to run.with_params('foo').and_return(path_of_module_foo.path) }
27
28       context 'when the modulepath is a list' do
29         before(:each) { Puppet[:modulepath] = modulepath + 'tmp/something_else' }
30
31         it { is_expected.to run.with_params('foo').and_return(path_of_module_foo.path) }
32       end
33     end
34
35     context 'in a non-default default environment' do
36       let(:environment) { 'test' }
37       before(:each) { Puppet::Module.expects(:find).with('foo', 'test').returns(path_of_module_foo) }
38
39       it { is_expected.to run.with_params('foo').and_return(path_of_module_foo.path) }
40
41       context 'when the modulepath is a list' do
42         before(:each) { Puppet[:modulepath] = modulepath + 'tmp/something_else' }
43
44         it { is_expected.to run.with_params('foo').and_return(path_of_module_foo.path) }
45       end
46     end
47   end
48 end