1 #!/usr/bin/env ruby -S rspec
4 describe "the pick function" do
5 let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
8 expect(Puppet::Parser::Functions.function("pick")).to eq("function_pick")
11 it 'should return the correct value' do
12 expect(scope.function_pick(['first', 'second'])).to eq('first')
15 it 'should return the correct value if the first value is empty' do
16 expect(scope.function_pick(['', 'second'])).to eq('second')
19 it 'should remove empty string values' do
20 expect(scope.function_pick(['', 'first'])).to eq('first')
23 it 'should remove :undef values' do
24 expect(scope.function_pick([:undef, 'first'])).to eq('first')
27 it 'should remove :undefined values' do
28 expect(scope.function_pick([:undefined, 'first'])).to eq('first')
31 it 'should error if no values are passed' do
32 expect { scope.function_pick([]) }.to( raise_error(Puppet::ParseError, "pick(): must receive at least one non empty value"))