]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/spec/functions/pick_default_spec.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / pick_default_spec.rb
1 #!/usr/bin/env ruby -S rspec
2 require 'spec_helper'
3
4 describe "the pick_default function" do
5   let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6
7   it "should exist" do
8     expect(Puppet::Parser::Functions.function("pick_default")).to eq("function_pick_default")
9   end
10
11   it 'should return the correct value' do
12     expect(scope.function_pick_default(['first', 'second'])).to eq('first')
13   end
14
15   it 'should return the correct value if the first value is empty' do
16     expect(scope.function_pick_default(['', 'second'])).to eq('second')
17   end
18
19   it 'should skip empty string values' do
20     expect(scope.function_pick_default(['', 'first'])).to eq('first')
21   end
22
23   it 'should skip :undef values' do
24     expect(scope.function_pick_default([:undef, 'first'])).to eq('first')
25   end
26
27   it 'should skip :undefined values' do
28     expect(scope.function_pick_default([:undefined, 'first'])).to eq('first')
29   end
30
31   it 'should return the empty string if it is the last possibility' do
32     expect(scope.function_pick_default([:undef, :undefined, ''])).to eq('')
33   end
34
35   it 'should return :undef if it is the last possibility' do
36     expect(scope.function_pick_default(['', :undefined, :undef])).to eq(:undef)
37   end
38
39   it 'should return :undefined if it is the last possibility' do
40     expect(scope.function_pick_default([:undef, '', :undefined])).to eq(:undefined)
41   end
42
43   it 'should return the empty string if it is the only possibility' do
44     expect(scope.function_pick_default([''])).to eq('')
45   end
46
47   it 'should return :undef if it is the only possibility' do
48     expect(scope.function_pick_default([:undef])).to eq(:undef)
49   end
50
51   it 'should return :undefined if it is the only possibility' do
52     expect(scope.function_pick_default([:undefined])).to eq(:undefined)
53   end
54
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./)
57   end
58 end