Skip to content

Commit 0cda858

Browse files
author
Ashley Penney
committed
Merge pull request #258 from mckern/enhancement/master/camelcasedembools
(MODULES-905) Narrow the confinement in bool2str
2 parents 645de3c + 557d38b commit 0cda858

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

lib/puppet/parser/functions/bool2str.rb

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
module 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
2825
end
2926

spec/unit/puppet/parser/functions/bool2str_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,16 @@
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
3446
end

0 commit comments

Comments
 (0)