Enable num2bool to accept numeric input
Also ignore rspec fixtures directory
This commit is contained in:
parent
4078a6ff44
commit
e6916f83fd
3 changed files with 25 additions and 3 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,6 +2,7 @@ pkg/
|
|||
.DS_Store
|
||||
metadata.json
|
||||
coverage/
|
||||
spec/fixtures/
|
||||
Gemfile.lock
|
||||
.bundle/
|
||||
vendor/bundle/
|
||||
|
|
|
@ -14,7 +14,8 @@ higher then 0 become true.
|
|||
raise(Puppet::ParseError, "num2bool(): Wrong number of arguments " +
|
||||
"given (#{arguments.size} for 1)") if arguments.size < 1
|
||||
|
||||
number = arguments[0]
|
||||
# Since we're matching against a regex, coerce to String
|
||||
number = arguments[0].to_s
|
||||
|
||||
# Only numbers allowed ...
|
||||
unless number.match(/^\-?\d+$/)
|
||||
|
|
|
@ -12,13 +12,33 @@ describe "the num2bool function" do
|
|||
lambda { scope.function_num2bool([]) }.should( raise_error(Puppet::ParseError))
|
||||
end
|
||||
|
||||
it "should return true if 1" do
|
||||
it "should return true if passed string 1" do
|
||||
result = scope.function_num2bool(["1"])
|
||||
result.should(be_true)
|
||||
end
|
||||
|
||||
it "should return false if 0" do
|
||||
it "should return true if passed number 1" do
|
||||
result = scope.function_num2bool([1])
|
||||
result.should(be_true)
|
||||
end
|
||||
|
||||
it "should return false if passed string 0" do
|
||||
result = scope.function_num2bool(["0"])
|
||||
result.should(be_false)
|
||||
end
|
||||
|
||||
it "should return false if passed number 0" do
|
||||
result = scope.function_num2bool([0])
|
||||
result.should(be_false)
|
||||
end
|
||||
|
||||
it "should return false if passed string -1" do
|
||||
result = scope.function_num2bool(["-1"])
|
||||
result.should(be_false)
|
||||
end
|
||||
|
||||
it "should return false if passed number -1" do
|
||||
result = scope.function_num2bool([-1])
|
||||
result.should(be_false)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue