summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Mueller <roman.mueller@gmail.com>2015-09-22 18:05:37 +0200
committerHelen Campbell <helen@puppetlabs.com>2015-09-28 16:01:11 +0100
commit6f1d164da6fca26d41d5962c575900dfc792f004 (patch)
treebb6ebdf6272e70d90f50d8c96bc4635cf7b9f560
parent48b658fc1c948103eaf04cd10671dd1a6fd61b8c (diff)
downloadpuppet-stdlib-6f1d164da6fca26d41d5962c575900dfc792f004.tar.gz
puppet-stdlib-6f1d164da6fca26d41d5962c575900dfc792f004.tar.bz2
Check for numeric values as empty fails on those
-rw-r--r--lib/puppet/parser/functions/empty.rb12
-rwxr-xr-xspec/functions/empty_spec.rb2
2 files changed, 9 insertions, 5 deletions
diff --git a/lib/puppet/parser/functions/empty.rb b/lib/puppet/parser/functions/empty.rb
index cca620f..b5a3cde 100644
--- a/lib/puppet/parser/functions/empty.rb
+++ b/lib/puppet/parser/functions/empty.rb
@@ -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
diff --git a/spec/functions/empty_spec.rb b/spec/functions/empty_spec.rb
index 94b1c68..a3a25d6 100755
--- a/spec/functions/empty_spec.rb
+++ b/spec/functions/empty_spec.rb
@@ -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) }