3 describe 'deep_merge' do
4 it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
5 it { is_expected.to run.with_params('key' => 'value').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
6 it { is_expected.to run.with_params({}, '2').and_raise_error(Puppet::ParseError, %r{unexpected argument type String}) }
7 it { is_expected.to run.with_params({}, 2).and_raise_error(Puppet::ParseError, %r{unexpected argument}) }
8 it { is_expected.to run.with_params({}, '').and_return({}) }
9 it { is_expected.to run.with_params({}, {}).and_return({}) }
10 it { is_expected.to run.with_params({}, {}, {}).and_return({}) }
11 it { is_expected.to run.with_params({}, {}, {}, {}).and_return({}) }
12 it { is_expected.to run.with_params({ 'key' => 'value' }, '').and_return('key' => 'value') }
13 it { is_expected.to run.with_params({ 'key1' => 'value1' }, 'key2' => 'value2').and_return('key1' => 'value1', 'key2' => 'value2') }
15 describe 'when arguments have key collisions' do
16 it 'prefers values from the last hash' do
18 .with_params({ 'key1' => 'value1', 'key2' => 'value2' }, 'key2' => 'replacement_value', 'key3' => 'value3') \
19 .and_return('key1' => 'value1', 'key2' => 'replacement_value', 'key3' => 'value3')
23 .with_params({ 'key1' => 'value1' }, { 'key1' => 'value2' }, 'key1' => 'value3') \
24 .and_return('key1' => 'value3')
28 describe 'when arguments have subhashes' do
31 .with_params({ 'key1' => 'value1' }, 'key2' => 'value2', 'key3' => { 'subkey1' => 'value4' }) \
32 .and_return('key1' => 'value1', 'key2' => 'value2', 'key3' => { 'subkey1' => 'value4' })
36 .with_params({ 'key1' => { 'subkey1' => 'value1' } }, 'key1' => { 'subkey2' => 'value2' }) \
37 .and_return('key1' => { 'subkey1' => 'value1', 'subkey2' => 'value2' })
41 .with_params({ 'key1' => { 'subkey1' => { 'subsubkey1' => 'value1' } } }, 'key1' => { 'subkey1' => { 'subsubkey1' => 'value2' } }) \
42 .and_return('key1' => { 'subkey1' => { 'subsubkey1' => 'value2' } })
46 arguments = { 'key1' => 'value1' }, { 'key2' => 'value2' }
47 originals = [arguments[0].dup, arguments[1].dup]
48 it 'does not change the original hashes' do
49 subject.execute(arguments[0], arguments[1])
50 arguments.each_with_index do |argument, index|
51 expect(argument).to eq(originals[index])
55 context 'with UTF8 and double byte characters' do
56 it { is_expected.to run.with_params({ 'ĸέỹ1' => 'ϋǻļủë1' }, 'この文字列' => '万').and_return('ĸέỹ1' => 'ϋǻļủë1', 'この文字列' => '万') }