File tree Expand file tree Collapse file tree
lib/puppet/parser/functions
spec/unit/puppet/parser/functions Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55module Puppet ::Parser ::Functions
66 newfunction ( :bool2str , :type => :rvalue , :doc => <<-EOS
77 Converts a boolean to a string.
8- Requires a single boolean or string as an input.
8+ Requires a single boolean as an input.
99 EOS
1010 ) do |arguments |
1111
@@ -15,15 +15,12 @@ module Puppet::Parser::Functions
1515 value = arguments [ 0 ]
1616 klass = value . class
1717
18- # We can have either true or false, or string which resembles boolean ...
19- unless [ FalseClass , TrueClass , String ] . include? ( klass )
20- raise ( Puppet ::ParseError , 'bool2str(): Requires either ' +
21- 'boolean or string to work with' )
18+ # We can have either true or false, and nothing else
19+ unless [ FalseClass , TrueClass ] . include? ( klass )
20+ raise ( Puppet ::ParseError , 'bool2str(): Requires a boolean to work with' )
2221 end
2322
24- result = value . is_a? ( String ) ? value : value . to_s
25-
26- return result
23+ return value . to_s
2724 end
2825end
2926
Original file line number Diff line number Diff line change 3131 result = scope . function_bool2str ( [ false ] )
3232 result . class . should ( eq ( String ) )
3333 end
34+
35+ it "should not accept a string" do
36+ lambda { scope . function_bool2str ( [ "false" ] ) } . should ( raise_error ( Puppet ::ParseError ) )
37+ end
38+
39+ it "should not accept a nil value" do
40+ lambda { scope . function_bool2str ( [ nil ] ) } . should ( raise_error ( Puppet ::ParseError ) )
41+ end
42+
43+ it "should not accept an undef" do
44+ lambda { scope . function_bool2str ( [ :undef ] ) } . should ( raise_error ( Puppet ::ParseError ) )
45+ end
3446end
You can’t perform that action at this time.
0 commit comments