X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Fstdlib%2Fspec%2Ffunctions%2Fdeep_merge_spec.rb;fp=3rdparty%2Fmodules%2Fstdlib%2Fspec%2Ffunctions%2Fdeep_merge_spec.rb;h=489bca58e4f3306a7870268c27d2dff2bb733846;hb=131e09855e065be940e104d9ab0f18940cc76257;hp=819e025f0113d11e1edfa87d6d3bcbf291ee54de;hpb=407d322498f4fde815abf381007fbecfe5c10b2b;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/stdlib/spec/functions/deep_merge_spec.rb b/3rdparty/modules/stdlib/spec/functions/deep_merge_spec.rb old mode 100755 new mode 100644 index 819e025f0..489bca58e --- a/3rdparty/modules/stdlib/spec/functions/deep_merge_spec.rb +++ b/3rdparty/modules/stdlib/spec/functions/deep_merge_spec.rb @@ -1,59 +1,58 @@ require 'spec_helper' describe 'deep_merge' do - it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } - it { is_expected.to run.with_params({ 'key' => 'value' }).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } - it { is_expected.to run.with_params({}, '2').and_raise_error(Puppet::ParseError, /unexpected argument type String/) } - it { is_expected.to run.with_params({}, 2).and_raise_error(Puppet::ParseError, /unexpected argument/) } + it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } + it { is_expected.to run.with_params('key' => 'value').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } + it { is_expected.to run.with_params({}, '2').and_raise_error(Puppet::ParseError, %r{unexpected argument type String}) } + it { is_expected.to run.with_params({}, 2).and_raise_error(Puppet::ParseError, %r{unexpected argument}) } it { is_expected.to run.with_params({}, '').and_return({}) } it { is_expected.to run.with_params({}, {}).and_return({}) } it { is_expected.to run.with_params({}, {}, {}).and_return({}) } it { is_expected.to run.with_params({}, {}, {}, {}).and_return({}) } - it { is_expected.to run.with_params({'key' => 'value'}, '').and_return({'key' => 'value'}) } - it { is_expected.to run.with_params({'key1' => 'value1'}, {'key2' => 'value2' }).and_return({'key1' => 'value1', 'key2' => 'value2'}) } + it { is_expected.to run.with_params({ 'key' => 'value' }, '').and_return('key' => 'value') } + it { is_expected.to run.with_params({ 'key1' => 'value1' }, 'key2' => 'value2').and_return('key1' => 'value1', 'key2' => 'value2') } describe 'when arguments have key collisions' do - it 'should prefer values from the last hash' do + it 'prefers values from the last hash' do is_expected.to run \ - .with_params( - {'key1' => 'value1', 'key2' => 'value2' }, - {'key2' => 'replacement_value', 'key3' => 'value3'}) \ - .and_return( - {'key1' => 'value1', 'key2' => 'replacement_value', 'key3' => 'value3'}) + .with_params({ 'key1' => 'value1', 'key2' => 'value2' }, 'key2' => 'replacement_value', 'key3' => 'value3') \ + .and_return('key1' => 'value1', 'key2' => 'replacement_value', 'key3' => 'value3') end - it { is_expected.to run \ - .with_params({'key1' => 'value1'}, {'key1' => 'value2'}, {'key1' => 'value3'}) \ - .and_return({'key1' => 'value3' }) + it { + is_expected.to run \ + .with_params({ 'key1' => 'value1' }, { 'key1' => 'value2' }, 'key1' => 'value3') \ + .and_return('key1' => 'value3') } end describe 'when arguments have subhashes' do - it { is_expected.to run \ - .with_params({'key1' => 'value1'}, {'key2' => 'value2', 'key3' => {'subkey1' => 'value4'}}) \ - .and_return( {'key1' => 'value1', 'key2' => 'value2', 'key3' => {'subkey1' => 'value4'}}) + it { + is_expected.to run \ + .with_params({ 'key1' => 'value1' }, 'key2' => 'value2', 'key3' => { 'subkey1' => 'value4' }) \ + .and_return('key1' => 'value1', 'key2' => 'value2', 'key3' => { 'subkey1' => 'value4' }) } - it { is_expected.to run \ - .with_params({'key1' => {'subkey1' => 'value1'}}, {'key1' => {'subkey2' => 'value2'}}) \ - .and_return( {'key1' => {'subkey1' => 'value1', 'subkey2' => 'value2'}}) + it { + is_expected.to run \ + .with_params({ 'key1' => { 'subkey1' => 'value1' } }, 'key1' => { 'subkey2' => 'value2' }) \ + .and_return('key1' => { 'subkey1' => 'value1', 'subkey2' => 'value2' }) } - it { is_expected.to run \ - .with_params({'key1' => {'subkey1' => {'subsubkey1' => 'value1'}}}, {'key1' => {'subkey1' => {'subsubkey1' => 'value2'}}}) \ - .and_return( {'key1' => {'subkey1' => {'subsubkey1' => 'value2'}}}) + it { + is_expected.to run \ + .with_params({ 'key1' => { 'subkey1' => { 'subsubkey1' => 'value1' } } }, 'key1' => { 'subkey1' => { 'subsubkey1' => 'value2' } }) \ + .and_return('key1' => { 'subkey1' => { 'subsubkey1' => 'value2' } }) } end - it 'should not change the original hashes' do - argument1 = { 'key1' => 'value1' } - original1 = argument1.dup - argument2 = { 'key2' => 'value2' } - original2 = argument2.dup - - subject.call([argument1, argument2]) - expect(argument1).to eq(original1) - expect(argument2).to eq(original2) + arguments = { 'key1' => 'value1' }, { 'key2' => 'value2' } + originals = [arguments[0].dup, arguments[1].dup] + it 'does not change the original hashes' do + subject.execute(arguments[0], arguments[1]) + arguments.each_with_index do |argument, index| + expect(argument).to eq(originals[index]) + end end - context 'should run with UTF8 and double byte characters' do - it { is_expected.to run.with_params({'ĸέỹ1' => 'ϋǻļủë1'}, {'この文字列' => '万' }).and_return({'ĸέỹ1' => 'ϋǻļủë1', 'この文字列' => '万'}) } + context 'with UTF8 and double byte characters' do + it { is_expected.to run.with_params({ 'ĸέỹ1' => 'ϋǻļủë1' }, 'この文字列' => '万').and_return('ĸέỹ1' => 'ϋǻļủë1', 'この文字列' => '万') } end end