40 context 'single values' do
42 is_expected.not_to be_nil
45 it 'should require two arguments' do
46 is_expected.to run.with_params().and_raise_error(ArgumentError)
49 it 'should fail if the data is not a structure' do
50 is_expected.to run.with_params('test', []).and_raise_error(Puppet::Error)
53 it 'should fail if the path is not an array' do
54 is_expected.to run.with_params({}, '').and_raise_error(Puppet::Error)
57 it 'should return the value if the value is string' do
58 is_expected.to run.with_params(data, ['d'], 'default').and_return('1')
61 it 'should return true if the value is true' do
62 is_expected.to run.with_params(data, ['b'], 'default').and_return(true)
65 it 'should return false if the value is false' do
66 is_expected.to run.with_params(data, ['c'], 'default').and_return(false)
69 it 'should return the default if the value is nil' do
70 is_expected.to run.with_params(data, ['f'], 'default').and_return('default')
73 it 'should return the default if the value is :undef (same as nil)' do
74 is_expected.to run.with_params(data, ['e'], 'default').and_return('default')
77 it 'should return the default if the path is not found' do
78 is_expected.to run.with_params(data, ['missing'], 'default').and_return('default')
82 context 'structure values' do
84 it 'should be able to extract a deeply nested hash value' do
85 is_expected.to run.with_params(data, %w(a g), 'default').and_return('2')
88 it 'should return the default value if the path is too long' do
89 is_expected.to run.with_params(data, %w(a g c d), 'default').and_return('default')
92 it 'should support an array index (number) in the path' do
93 is_expected.to run.with_params(data, ['a', 'e', 1], 'default').and_return('f1')
96 it 'should support an array index (string) in the path' do
97 is_expected.to run.with_params(data, %w(a e 1), 'default').and_return('f1')
100 it 'should return the default value if an array index is not a number' do
101 is_expected.to run.with_params(data, %w(a b c), 'default').and_return('default')
104 it 'should return the default value if and index is out of array length' do
105 is_expected.to run.with_params(data, %w(a e 5), 'default').and_return('default')
108 it 'should be able to path though both arrays and hashes' do
109 is_expected.to run.with_params(data, %w(a e 2 x y), 'default').and_return('z')
112 it 'should return "nil" if value is not found and no default value is provided' do
113 is_expected.to run.with_params(data, %w(a 1)).and_return(nil)
117 context 'Internationalization (i18N) values' do
119 it 'should be able to return a unicode character' do
120 is_expected.to run.with_params(utf8_data, ['ẵ', 'в', 0]).and_return('©')
123 it 'should be able to return a utf8 character' do
124 is_expected.to run.with_params(utf8_data, ['ẵ', 'в', 1]).and_return('ĝ')
127 it 'should be able to return a double byte character' do
128 is_expected.to run.with_params(utf8_data, ['ẵ', 'в', 2]).and_return('に')