Skip to content

Commit 3312cc1

Browse files
committed
(MODULES-3829) Make ensure_packages work with < 2.0
Prior to this commit, if a hash was passed in as an argument to the ensure_packages function a method of hash duplication would be used that is not supported with versions of ruby older than 2.0. In order to ensure the method is compatible with older ruby versions, switch to a different method of duplication. Additionally add tests to prevent further regressions.
1 parent 903d94e commit 3312cc1

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

lib/puppet/parser/functions/ensure_packages.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module Puppet::Parser::Functions
2525
end
2626

2727
Puppet::Parser::Functions.function(:ensure_resources)
28-
function_ensure_resources(['package', Hash(arguments[0]), defaults ])
28+
function_ensure_resources(['package', arguments[0].dup, defaults ])
2929
else
3030
packages = Array(arguments[0])
3131

spec/functions/ensure_packages_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,12 @@
3333
it { expect(lambda { catalogue }).to contain_package('facter').with_ensure('present').with_provider("gem") }
3434
end
3535
end
36+
37+
context 'given hash of packages' do
38+
before { subject.call([{"foo" => { "provider" => "rpm" }, "bar" => { "provider" => "gem" }}, { "ensure" => "present"}]) }
39+
40+
# this lambda is required due to strangeness within rspec-puppet's expectation handling
41+
it { expect(lambda { catalogue }).to contain_package('foo').with({'provider' => 'rpm', 'ensure' => 'present'}) }
42+
it { expect(lambda { catalogue }).to contain_package('bar').with({'provider' => 'gem', 'ensure' => 'present'}) }
43+
end
3644
end

0 commit comments

Comments
 (0)