File tree Expand file tree Collapse file tree 2 files changed +17
-8
lines changed
lib/puppet/parser/functions
spec/unit/puppet/parser/functions Expand file tree Collapse file tree 2 files changed +17
-8
lines changed Original file line number Diff line number Diff line change 5
5
module Puppet ::Parser ::Functions
6
6
newfunction ( :bool2str , :type => :rvalue , :doc => <<-EOS
7
7
Converts a boolean to a string.
8
- Requires a single boolean or string as an input.
8
+ Requires a single boolean as an input.
9
9
EOS
10
10
) do |arguments |
11
11
@@ -15,15 +15,12 @@ module Puppet::Parser::Functions
15
15
value = arguments [ 0 ]
16
16
klass = value . class
17
17
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' )
22
21
end
23
22
24
- result = value . is_a? ( String ) ? value : value . to_s
25
-
26
- return result
23
+ return value . to_s
27
24
end
28
25
end
29
26
Original file line number Diff line number Diff line change 31
31
result = scope . function_bool2str ( [ false ] )
32
32
result . class . should ( eq ( String ) )
33
33
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
34
46
end
You can’t perform that action at this time.
0 commit comments