1 #! /usr/bin/env ruby -S rspec
5 describe Puppet::Parser::Functions.function(:merge) do
6 let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
8 describe 'when calling merge from puppet' do
9 it "should not compile when no arguments are passed" do
10 skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
11 Puppet[:code] = '$x = merge()'
13 scope.compiler.compile
14 }.to raise_error(Puppet::ParseError, /wrong number of arguments/)
17 it "should not compile when 1 argument is passed" do
18 skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
19 Puppet[:code] = "$my_hash={'one' => 1}\n$x = merge($my_hash)"
21 scope.compiler.compile
22 }.to raise_error(Puppet::ParseError, /wrong number of arguments/)
26 describe 'when calling merge on the scope instance' do
27 it 'should require all parameters are hashes' do
28 expect { new_hash = scope.function_merge([{}, '2'])}.to raise_error(Puppet::ParseError, /unexpected argument type String/)
29 expect { new_hash = scope.function_merge([{}, 2])}.to raise_error(Puppet::ParseError, /unexpected argument type Fixnum/)
32 it 'should accept empty strings as puppet undef' do
33 expect { new_hash = scope.function_merge([{}, ''])}.not_to raise_error
36 it 'should be able to merge two hashes' do
37 new_hash = scope.function_merge([{'one' => '1', 'two' => '1'}, {'two' => '2', 'three' => '2'}])
38 expect(new_hash['one']).to eq('1')
39 expect(new_hash['two']).to eq('2')
40 expect(new_hash['three']).to eq('2')
43 it 'should merge multiple hashes' do
44 hash = scope.function_merge([{'one' => 1}, {'one' => '2'}, {'one' => '3'}])
45 expect(hash['one']).to eq('3')
48 it 'should accept empty hashes' do
49 expect(scope.function_merge([{},{},{}])).to eq({})