1 #!/usr/bin/env ruby -S rspec
4 describe "the pick_default function" do
5 let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
8 expect(Puppet::Parser::Functions.function("pick_default")).to eq("function_pick_default")
11 it 'should return the correct value' do
12 expect(scope.function_pick_default(['first', 'second'])).to eq('first')
15 it 'should return the correct value if the first value is empty' do
16 expect(scope.function_pick_default(['', 'second'])).to eq('second')
19 it 'should skip empty string values' do
20 expect(scope.function_pick_default(['', 'first'])).to eq('first')
23 it 'should skip :undef values' do
24 expect(scope.function_pick_default([:undef, 'first'])).to eq('first')
27 it 'should skip :undefined values' do
28 expect(scope.function_pick_default([:undefined, 'first'])).to eq('first')
31 it 'should return the empty string if it is the last possibility' do
32 expect(scope.function_pick_default([:undef, :undefined, ''])).to eq('')
35 it 'should return :undef if it is the last possibility' do
36 expect(scope.function_pick_default(['', :undefined, :undef])).to eq(:undef)
39 it 'should return :undefined if it is the last possibility' do
40 expect(scope.function_pick_default([:undef, '', :undefined])).to eq(:undefined)
43 it 'should return the empty string if it is the only possibility' do
44 expect(scope.function_pick_default([''])).to eq('')
47 it 'should return :undef if it is the only possibility' do
48 expect(scope.function_pick_default([:undef])).to eq(:undef)
51 it 'should return :undefined if it is the only possibility' do
52 expect(scope.function_pick_default([:undefined])).to eq(:undefined)
55 it 'should error if no values are passed' do
56 expect { scope.function_pick_default([]) }.to raise_error(Puppet::Error, /Must receive at least one argument./)