summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/chef/provider/package/rubygems.rb10
-rw-r--r--lib/chef/resource/gem_package.rb8
-rw-r--r--spec/unit/provider/package/rubygems_spec.rb45
-rw-r--r--spec/unit/resource/gem_package_spec.rb38
4 files changed, 54 insertions, 47 deletions
diff --git a/lib/chef/provider/package/rubygems.rb b/lib/chef/provider/package/rubygems.rb
index 512baf6014..cda2c623e6 100644
--- a/lib/chef/provider/package/rubygems.rb
+++ b/lib/chef/provider/package/rubygems.rb
@@ -550,12 +550,20 @@ class Chef
new_resource.gem_binary || "gem"
end
+ def clear_sources?
+ if new_resource.clear_sources.nil?
+ !!new_resource.source
+ else
+ new_resource.clear_sources
+ end
+ end
+
def install_via_gem_command(name, version)
src = []
if new_resource.source.is_a?(String) && new_resource.source =~ /\.gem$/i
name = new_resource.source
else
- src << "--clear-sources" if new_resource.clear_sources?
+ src << "--clear-sources" if clear_sources?
src += gem_sources.map { |s| "--source=#{s}" }
end
src_str = src.empty? ? "" : " #{src.join(" ")}"
diff --git a/lib/chef/resource/gem_package.rb b/lib/chef/resource/gem_package.rb
index 09ce39266e..80eb257fa1 100644
--- a/lib/chef/resource/gem_package.rb
+++ b/lib/chef/resource/gem_package.rb
@@ -55,14 +55,6 @@ class Chef
property :options, [ String, Hash, Array, nil ],
description: "Options for the gem install, either a Hash or a String. When a hash is given, the options are passed to Gem::DependencyInstaller.new, and the gem will be installed via the gems API. When a String is given, the gem will be installed by shelling out to the gem command. Using a Hash of options with an explicit gem_binary will result in undefined behavior.",
desired_state: false
-
- def clear_sources?
- if clear_sources.nil?
- !!source
- else
- clear_sources
- end
- end
end
end
end
diff --git a/spec/unit/provider/package/rubygems_spec.rb b/spec/unit/provider/package/rubygems_spec.rb
index 1ef76c05c3..295e5f9bf9 100644
--- a/spec/unit/provider/package/rubygems_spec.rb
+++ b/spec/unit/provider/package/rubygems_spec.rb
@@ -992,3 +992,48 @@ describe Chef::Provider::Package::Rubygems do
end
end
end
+
+describe Chef::Provider::Package::Rubygems, "clear_sources?" do
+ let(:new_resource) do
+ Chef::Resource::GemPackage.new("foo")
+ end
+
+ let(:provider) do
+ run_context = Chef::RunContext.new(Chef::Node.new, {}, Chef::EventDispatch::Dispatcher.new)
+ Chef::Provider::Package::Rubygems.new(new_resource, run_context)
+ end
+
+ it "is false when clear_sources is unset" do
+ expect(provider.clear_sources?).to be false
+ end
+
+ it "is false when clear_sources is set false" do
+ new_resource.clear_sources(false)
+ expect(provider.clear_sources?).to be false
+ end
+
+ it "is true when clear_sources is set true" do
+ new_resource.clear_sources(true)
+ expect(provider.clear_sources?).to be true
+ end
+
+ context "when a source is set" do
+ before do
+ new_resource.source("http://mirror.ops.rhcloud.com/mirror/ruby")
+ end
+
+ it "is true when clear_sources is unset" do
+ expect(provider.clear_sources?).to be true
+ end
+
+ it "is false when clear_sources is set false" do
+ new_resource.clear_sources(false)
+ expect(provider.clear_sources?).to be false
+ end
+
+ it "is true when clear_sources is set true" do
+ new_resource.clear_sources(true)
+ expect(provider.clear_sources?).to be true
+ end
+ end
+end
diff --git a/spec/unit/resource/gem_package_spec.rb b/spec/unit/resource/gem_package_spec.rb
index 5ecc2f46ca..b572fd0d40 100644
--- a/spec/unit/resource/gem_package_spec.rb
+++ b/spec/unit/resource/gem_package_spec.rb
@@ -65,41 +65,3 @@ describe Chef::Resource::GemPackage, "clear_sources" do
expect(resource.clear_sources).to be true
end
end
-
-describe Chef::Resource::GemPackage, "clear_sources?" do
- let(:resource) { Chef::Resource::GemPackage.new("foo") }
-
- it "is false when clear_sources is unset" do
- expect(resource.clear_sources?).to be false
- end
-
- it "is false when clear_sources is set false" do
- resource.clear_sources(false)
- expect(resource.clear_sources?).to be false
- end
-
- it "is true when clear_sources is set true" do
- resource.clear_sources(true)
- expect(resource.clear_sources?).to be true
- end
-
- context "when a source is set" do
- before do
- resource.source("http://mirror.ops.rhcloud.com/mirror/ruby")
- end
-
- it "is true when clear_sources is unset" do
- expect(resource.clear_sources?).to be true
- end
-
- it "is false when clear_sources is set false" do
- resource.clear_sources(false)
- expect(resource.clear_sources?).to be false
- end
-
- it "is true when clear_sources is set true" do
- resource.clear_sources(true)
- expect(resource.clear_sources?).to be true
- end
- end
-end