summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-07-16 10:19:34 -0700
committerGitHub <noreply@github.com>2018-07-16 10:19:34 -0700
commit1b8c24a83a2ba2d7d3c76ebe5c885187948b9fac (patch)
tree8a305a1e25b902e2dc281d23655e860b032bbf2d
parentd30645d1b05af5c472b1e2d505603a19ed4ddf5c (diff)
parentbcf5474410be6198bd0bf04d1ea7a636962194e2 (diff)
downloadchef-1b8c24a83a2ba2d7d3c76ebe5c885187948b9fac.tar.gz
Merge pull request #6168 from oclaussen/generate_valid_gemfile
Make gem_installer generate a valid Gemfile
-rw-r--r--lib/chef/cookbook/gem_installer.rb7
-rw-r--r--lib/chef/exceptions.rb6
-rw-r--r--spec/unit/cookbook/gem_installer_spec.rb9
3 files changed, 21 insertions, 1 deletions
diff --git a/lib/chef/cookbook/gem_installer.rb b/lib/chef/cookbook/gem_installer.rb
index deac48ff78..79b62f7a72 100644
--- a/lib/chef/cookbook/gem_installer.rb
+++ b/lib/chef/cookbook/gem_installer.rb
@@ -40,6 +40,13 @@ class Chef
cookbook_collection.each_value do |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|
+ raise Chef::Exceptions::GemRequirementConflict.new(args.first, key, v1, v2) if v1 != v2
+ v2
+ end
+ end
cookbook_gems[args.first] += args[1..-1]
end
end
diff --git a/lib/chef/exceptions.rb b/lib/chef/exceptions.rb
index ca388d33cd..dafd445d2d 100644
--- a/lib/chef/exceptions.rb
+++ b/lib/chef/exceptions.rb
@@ -521,5 +521,11 @@ class Chef
# exception specific to invalid usage of 'dsc_resource' resource
class DSCModuleNameMissing < ArgumentError; end
+
+ class GemRequirementConflict < RuntimeError
+ def initialize(gem_name, option, value1, value2)
+ super "Conflicting requirements for gem '#{gem_name}': Both #{value1.inspect} and #{value2.inspect} given for option #{option.inspect}"
+ end
+ end
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" }]]
)
),
}