Skip to content

Commit

Permalink
Check for numeric values as empty fails on those
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-mueller authored and Helen Campbell committed Sep 28, 2015
1 parent 48b658f commit 6f1d164
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions lib/puppet/parser/functions/empty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@ module Puppet::Parser::Functions

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

Expand Down
2 changes: 1 addition & 1 deletion spec/functions/empty_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
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) }

Expand Down

0 comments on commit 6f1d164

Please sign in to comment.