puppetlabs-stdlib/spec/unit/puppet/parser/functions/pick_spec.rb
Leonardo Rodrigues de Mello 30e994fb6e enhanced the error message of pick function.
When pick function fail return a better error message like
the other stdlib functions, indicating that the error
is on function pick.

This would help people that see the error to identity it is
related to a incorrect use of stdlib function pick, instead of having
to grep all puppet libraries and manifests source for the old message.

I had also changed the spec test.

pick function change spec  as suggested GH-179

Fix the spec test to use expect {}.to instead of lambda {}.should
as explained by Adrienthebo.

"Using expect { }.to is preferred over lambda { }.should.
 In addition it's best practice to do a string match against the
error message to ensure that we're catching the right error,
instead of any error of the right type."

Also fixed a typo on the error message, it was missing one space.

pick function stylish fix as suggested on GH179
2013-09-16 10:03:20 -03:00

34 lines
1,005 B
Ruby

#!/usr/bin/env ruby -S rspec
require 'spec_helper'
describe "the pick function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
Puppet::Parser::Functions.function("pick").should == "function_pick"
end
it 'should return the correct value' do
scope.function_pick(['first', 'second']).should == 'first'
end
it 'should return the correct value if the first value is empty' do
scope.function_pick(['', 'second']).should == 'second'
end
it 'should remove empty string values' do
scope.function_pick(['', 'first']).should == 'first'
end
it 'should remove :undef values' do
scope.function_pick([:undef, 'first']).should == 'first'
end
it 'should remove :undefined values' do
scope.function_pick([:undefined, 'first']).should == 'first'
end
it 'should error if no values are passed' do
expect { scope.function_pick([]) }.to( raise_error(Puppet::ParseError, "pick(): must receive at last one non empty value"))
end
end