]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
Check for numeric values as empty fails on those
authorRoman Mueller <roman.mueller@gmail.com>
Tue, 22 Sep 2015 16:05:37 +0000 (18:05 +0200)
committerHelen Campbell <helen@puppetlabs.com>
Mon, 28 Sep 2015 15:01:11 +0000 (16:01 +0100)
lib/puppet/parser/functions/empty.rb
spec/functions/empty_spec.rb

index cca620fae12a5311d672774263a9f65161c66db8..b5a3cdea46e121607ce387de7cb7a515aef35006 100644 (file)
@@ -13,14 +13,18 @@ Returns true if the variable is empty.
 
     value = arguments[0]
 
-    unless value.is_a?(Array) || value.is_a?(Hash) || value.is_a?(String)
+    unless value.is_a?(Array) || value.is_a?(Hash) || value.is_a?(String) || value.is_a?(Numeric)
       raise(Puppet::ParseError, 'empty(): Requires either ' +
-        'array, hash or string to work with')
+        'array, hash, string or integer to work with')
     end
 
-    result = value.empty?
+    if value.is_a?(Numeric)
+      return false
+    else
+      result = value.empty?
 
-    return result
+      return result
+    end
   end
 end
 
index 94b1c6856bd71a53f52ca258321ef7900e63eac7..a3a25d6a00186039d27b67e1cef482dfb21dbb70 100755 (executable)
@@ -3,11 +3,11 @@ require 'spec_helper'
 describe 'empty' do
   it { is_expected.not_to eq(nil) }
   it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError) }
-  it { is_expected.to run.with_params(0).and_raise_error(Puppet::ParseError) }
   it {
     pending("Current implementation ignores parameters after the first.")
     is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError)
   }
+  it { is_expected.to run.with_params(0).and_return(false) }
   it { is_expected.to run.with_params('').and_return(true) }
   it { is_expected.to run.with_params('one').and_return(false) }