Update stdlib
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / getvar_spec.rb
1 require 'spec_helper'
2
3 describe 'getvar' 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/i) }
6   it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
7   it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
8
9   it { is_expected.to run.with_params('$::foo').and_return(nil) }
10
11   context 'given variables in namespaces' do
12     let(:pre_condition) {
13       <<-'ENDofPUPPETcode'
14       class site::data { $foo = 'baz' }
15       include site::data
16       ENDofPUPPETcode
17     }
18
19     it { is_expected.to run.with_params('site::data::foo').and_return('baz') }
20     it { is_expected.to run.with_params('::site::data::foo').and_return('baz') }
21     it { is_expected.to run.with_params('::site::data::bar').and_return(nil) }
22   end
23
24   context 'given variables in namespaces' do
25     let(:pre_condition) {
26       <<-'ENDofPUPPETcode'
27       class site::info { $lock = 'ŧҺîš íš ắ śţřĭŋĝ' }
28       class site::new { $item = '万Ü€‰' }
29       include site::info
30       include site::new
31       ENDofPUPPETcode
32     }
33
34     it { is_expected.to run.with_params('site::info::lock').and_return('ŧҺîš íš ắ śţřĭŋĝ') }
35     it { is_expected.to run.with_params('::site::new::item').and_return('万Ü€‰') }
36   end
37 end
38