]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
Enable num2bool to accept numeric input
authorSteve Huff <shuff@vecna.org>
Fri, 29 Mar 2013 14:04:05 +0000 (10:04 -0400)
committerSteve Huff <shuff@vecna.org>
Fri, 29 Mar 2013 16:53:56 +0000 (12:53 -0400)
Also ignore rspec fixtures directory

.gitignore
lib/puppet/parser/functions/num2bool.rb
spec/unit/puppet/parser/functions/num2bool_spec.rb

index 416889c8919bf2bd227b4dcc23244ca521233518..2e3ca630fcc7ff13f8dfb0d18e4fc1cd9b558e96 100644 (file)
@@ -2,6 +2,7 @@ pkg/
 .DS_Store
 metadata.json
 coverage/
+spec/fixtures/
 Gemfile.lock
 .bundle/
 vendor/bundle/
index 874db226e673b25cf1027f7b10b84211f58b1407..638f6931699903a25116b152c86992459d310ae4 100644 (file)
@@ -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+$/)
index 640c68985794bc975cd660cac83c88231c3a1ef2..e51ee45b75976efa35725276341a44c27737097a 100644 (file)
@@ -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