From 0c622b2e30333f26103a4440a888d440cf455c9c Mon Sep 17 00:00:00 2001 From: Martin Hellmich Date: Mon, 18 Feb 2013 16:02:15 +0100 Subject: changed .count to .size to support legacy ruby --- lib/puppet/provider/file_line/ruby.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/provider/file_line/ruby.rb b/lib/puppet/provider/file_line/ruby.rb index e21eaa8..a3219d3 100644 --- a/lib/puppet/provider/file_line/ruby.rb +++ b/lib/puppet/provider/file_line/ruby.rb @@ -34,7 +34,7 @@ Puppet::Type.type(:file_line).provide(:ruby) do def handle_create_with_match() regex = resource[:match] ? Regexp.new(resource[:match]) : nil - match_count = lines.select { |l| regex.match(l) }.count + match_count = lines.select { |l| regex.match(l) }.size if match_count > 1 raise Puppet::Error, "More than one line in file '#{resource[:path]}' matches pattern '#{resource[:match]}'" end -- cgit v1.2.3 From 3077d26b00b170ef2c5c808831577d421613b198 Mon Sep 17 00:00:00 2001 From: Martin Hellmich Date: Mon, 22 Apr 2013 23:26:22 +0200 Subject: check if an argument supposed to be merged is empty to pass over undefs without failing --- lib/puppet/parser/functions/merge.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/puppet/parser/functions/merge.rb b/lib/puppet/parser/functions/merge.rb index 6ec085e..54d1c1c 100644 --- a/lib/puppet/parser/functions/merge.rb +++ b/lib/puppet/parser/functions/merge.rb @@ -22,6 +22,7 @@ module Puppet::Parser::Functions accumulator = Hash.new # Merge into the accumulator hash args.each do |arg| + next if arg.empty? # empty string is synonym for puppet's undef unless arg.is_a?(Hash) raise Puppet::ParseError, "merge: unexpected argument type #{arg.class}, only expects hash arguments" end -- cgit v1.2.3 From f496005bf3db8a5202bf9c16daf9a524b178c67a Mon Sep 17 00:00:00 2001 From: Martin Hellmich Date: Wed, 8 May 2013 17:14:28 +0200 Subject: fix in merge.rb: refine the checking if an argument is an empty string --- lib/puppet/parser/functions/merge.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/parser/functions/merge.rb b/lib/puppet/parser/functions/merge.rb index 54d1c1c..1b39f20 100644 --- a/lib/puppet/parser/functions/merge.rb +++ b/lib/puppet/parser/functions/merge.rb @@ -22,7 +22,7 @@ module Puppet::Parser::Functions accumulator = Hash.new # Merge into the accumulator hash args.each do |arg| - next if arg.empty? # empty string is synonym for puppet's undef + next if arg.is_a? String and arg.empty? # empty string is synonym for puppet's undef unless arg.is_a?(Hash) raise Puppet::ParseError, "merge: unexpected argument type #{arg.class}, only expects hash arguments" end -- cgit v1.2.3 From b975bd66aa7345a5eeb54eb79dd0f708934609f8 Mon Sep 17 00:00:00 2001 From: Martin Hellmich Date: Wed, 8 May 2013 18:20:56 +0200 Subject: Added rspec tests for the new behaviour of merge accepting empty strings added test that '' is accepted changed a test that a number is correctly rejected with a type error --- spec/unit/puppet/parser/functions/merge_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/unit/puppet/parser/functions/merge_spec.rb b/spec/unit/puppet/parser/functions/merge_spec.rb index 04169e7..8a170bb 100644 --- a/spec/unit/puppet/parser/functions/merge_spec.rb +++ b/spec/unit/puppet/parser/functions/merge_spec.rb @@ -26,6 +26,11 @@ describe Puppet::Parser::Functions.function(:merge) do describe 'when calling merge on the scope instance' do it 'should require all parameters are hashes' do expect { new_hash = scope.function_merge([{}, '2'])}.to raise_error(Puppet::ParseError, /unexpected argument type String/) + expect { new_hash = scope.function_merge([{}, 2])}.to raise_error(Puppet::ParseError, /unexpected argument type Fixnum/) + end + + it 'should accept empty strings as puppet undef' do + expect { new_hash = scope.function_merge([{}, ''])}.not_to raise_error(Puppet::ParseError, /unexpected argument type String/) end it 'should be able to merge two hashes' do -- cgit v1.2.3