X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Fstdlib%2Fspec%2Ffunctions%2Fdig44_spec.rb;h=e7c6d817c101fd7084da7ec68de68e57233702c2;hb=30caaa85aed7015ca0d77216bff175eebd917eb7;hp=a7b8a3d4c0ff9b8ad83f32f8ef69e63d087f7fa5;hpb=6963202b4b62c2816655ac9532521b018fdf83bd;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/stdlib/spec/functions/dig44_spec.rb b/3rdparty/modules/stdlib/spec/functions/dig44_spec.rb index a7b8a3d4c..e7c6d817c 100644 --- a/3rdparty/modules/stdlib/spec/functions/dig44_spec.rb +++ b/3rdparty/modules/stdlib/spec/functions/dig44_spec.rb @@ -1,130 +1,131 @@ require 'spec_helper' describe 'dig44' do + let(:undef_value) do + (Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0) ? :undef : nil + end let(:data) do { - 'a' => { - 'g' => '2', - 'e' => [ - 'f0', - 'f1', - { - 'x' => { - 'y' => 'z' - } - }, - 'f3', - ] - }, - 'b' => true, - 'c' => false, - 'd' => '1', - 'e' => :undef, - 'f' => nil, + 'a' => { + 'g' => '2', + 'e' => [ + 'f0', + 'f1', + { + 'x' => { + 'y' => 'z', + }, + }, + 'f3', + ], + }, + 'b' => true, + 'c' => false, + 'd' => '1', + 'e' => undef_value, + 'f' => nil, } end let(:utf8_data) do { - 'ẵ' => { - 'в' => [ - '©', - 'ĝ', - 'に', - ] - } + 'ẵ' => { + 'в' => [ + '©', + 'ĝ', + 'に', + ], + }, } end - context 'single values' do - it 'should exist' do + context 'with single values' do + it 'exists' do is_expected.not_to be_nil end - it 'should require two arguments' do - is_expected.to run.with_params().and_raise_error(ArgumentError) + it 'requires two arguments' do + is_expected.to run.with_params.and_raise_error(ArgumentError, %r{Wrong number of arguments}) end - it 'should fail if the data is not a structure' do - is_expected.to run.with_params('test', []).and_raise_error(Puppet::Error) + it 'fails if the data is not a structure' do + is_expected.to run.with_params('test', []).and_raise_error(Puppet::Error, %r{first argument must be a hash or an array}) end - it 'should fail if the path is not an array' do - is_expected.to run.with_params({}, '').and_raise_error(Puppet::Error) + it 'fails if the path is not an array' do + is_expected.to run.with_params({}, '').and_raise_error(Puppet::Error, %r{second argument must be an array}) end - it 'should return the value if the value is string' do + it 'returns the value if the value is string' do is_expected.to run.with_params(data, ['d'], 'default').and_return('1') end - it 'should return true if the value is true' do + it 'returns true if the value is true' do is_expected.to run.with_params(data, ['b'], 'default').and_return(true) end - it 'should return false if the value is false' do + it 'returns false if the value is false' do is_expected.to run.with_params(data, ['c'], 'default').and_return(false) end - it 'should return the default if the value is nil' do + it 'returns the default if the value is nil' do is_expected.to run.with_params(data, ['f'], 'default').and_return('default') end - it 'should return the default if the value is :undef (same as nil)' do + it 'returns the default if the value is :undef (same as nil)' do is_expected.to run.with_params(data, ['e'], 'default').and_return('default') end - it 'should return the default if the path is not found' do + it 'returns the default if the path is not found' do is_expected.to run.with_params(data, ['missing'], 'default').and_return('default') end end - context 'structure values' do - - it 'should be able to extract a deeply nested hash value' do - is_expected.to run.with_params(data, %w(a g), 'default').and_return('2') + context 'with structured values' do + it 'is able to extract a deeply nested hash value' do + is_expected.to run.with_params(data, ['a', 'g'], 'default').and_return('2') end - it 'should return the default value if the path is too long' do - is_expected.to run.with_params(data, %w(a g c d), 'default').and_return('default') + it 'returns the default value if the path is too long' do + is_expected.to run.with_params(data, ['a', 'g', 'c', 'd'], 'default').and_return('default') end - it 'should support an array index (number) in the path' do + it 'supports an array index (number) in the path' do is_expected.to run.with_params(data, ['a', 'e', 1], 'default').and_return('f1') end - it 'should support an array index (string) in the path' do - is_expected.to run.with_params(data, %w(a e 1), 'default').and_return('f1') + it 'supports an array index (string) in the path' do + is_expected.to run.with_params(data, ['a', 'e', '1'], 'default').and_return('f1') end - it 'should return the default value if an array index is not a number' do - is_expected.to run.with_params(data, %w(a b c), 'default').and_return('default') + it 'returns the default value if an array index is not a number' do + is_expected.to run.with_params(data, ['a', 'b', 'c'], 'default').and_return('default') end - it 'should return the default value if and index is out of array length' do - is_expected.to run.with_params(data, %w(a e 5), 'default').and_return('default') + it 'returns the default value if and index is out of array length' do + is_expected.to run.with_params(data, ['a', 'e', '5'], 'default').and_return('default') end - it 'should be able to path though both arrays and hashes' do - is_expected.to run.with_params(data, %w(a e 2 x y), 'default').and_return('z') + it 'is able to path though both arrays and hashes' do + is_expected.to run.with_params(data, ['a', 'e', '2', 'x', 'y'], 'default').and_return('z') end - it 'should return "nil" if value is not found and no default value is provided' do - is_expected.to run.with_params(data, %w(a 1)).and_return(nil) + it 'returns "nil" if value is not found and no default value is provided' do + is_expected.to run.with_params(data, ['a', '1']).and_return(nil) end end - context 'Internationalization (i18N) values' do - - it 'should be able to return a unicode character' do + context 'with internationalization (i18N) values' do + it 'is able to return a unicode character' do is_expected.to run.with_params(utf8_data, ['ẵ', 'в', 0]).and_return('©') end - it 'should be able to return a utf8 character' do + it 'is able to return a utf8 character' do is_expected.to run.with_params(utf8_data, ['ẵ', 'в', 1]).and_return('ĝ') end - it 'should be able to return a double byte character' do + it 'is able to return a double byte character' do is_expected.to run.with_params(utf8_data, ['ẵ', 'в', 2]).and_return('に') end end