diff options
author | Ole Claussen <claussen.ole@gmail.com> | 2017-05-22 14:43:02 +0200 |
---|---|---|
committer | Ole Claussen <claussen.ole@gmail.com> | 2017-05-29 10:51:32 +0200 |
commit | 922c9f931396d16da6984bd31f767ade6495355e (patch) | |
tree | 133c4f0ec67528e4179c5a46077e3bf260d782ca | |
parent | 6b9ebb11c68d2a03a78644ffc2134941c46a15ed (diff) | |
download | chef-922c9f931396d16da6984bd31f767ade6495355e.tar.gz |
Generate a valid Gemfile, even multiple gem declaration with keyword arguments exist.
Previously, keyword argemunts to the gem declarations would just be appended, resulting in invalid Gemfiles. Now, keyword arguments are merged together. In case of conflict, the last declaration will win.
Signed-off-by: Ole Claussen <claussen.ole@gmail.com>
-rw-r--r-- | lib/chef/cookbook/gem_installer.rb | 7 | ||||
-rw-r--r-- | spec/unit/cookbook/gem_installer_spec.rb | 9 |
2 files changed, 15 insertions, 1 deletions
diff --git a/lib/chef/cookbook/gem_installer.rb b/lib/chef/cookbook/gem_installer.rb index 5b1426e4e8..71e513a86b 100644 --- a/lib/chef/cookbook/gem_installer.rb +++ b/lib/chef/cookbook/gem_installer.rb @@ -40,6 +40,13 @@ class Chef cookbook_collection.each do |cookbook_name, cookbook_version| cookbook_version.metadata.gems.each do |args| + if cookbook_gems[args.first].last.is_a?(Hash) + args << {} unless args.last.is_a?(Hash) + args.last.merge!(cookbook_gems[args.first].pop) do |key, v1, v2| + Chef::Log.warn "Conflicting requirements for gem '#{args.first}', will use #{key.inspect} => #{v2.inspect}" if v1 != v2 + v2 + end + end cookbook_gems[args.first] += args[1..-1] end end diff --git a/spec/unit/cookbook/gem_installer_spec.rb b/spec/unit/cookbook/gem_installer_spec.rb index 91e6959331..b7c8db514a 100644 --- a/spec/unit/cookbook/gem_installer_spec.rb +++ b/spec/unit/cookbook/gem_installer_spec.rb @@ -22,7 +22,14 @@ describe Chef::Cookbook::GemInstaller do :cookbook, metadata: double( :metadata, - gems: [["httpclient", ">= 1.0"]] + gems: [["httpclient", ">= 1.0", { "git" => "https://github.com/nahi/httpclient" }]] + ) + ), + test4: double( + :cookbook, + metadata: double( + :metadata, + gems: [["httpclient", { "path" => "./gems/httpclient" }]] ) ), } |