From 312253ebfd88ac57b8433c2f859690068fe7cb14 Mon Sep 17 00:00:00 2001 From: Peter Burkholder Date: Tue, 24 Mar 2015 11:13:22 -0400 Subject: [PATCH] Clearing sources works for string options --- lib/chef/provider/package/rubygems.rb | 5 +++-- lib/chef/resource/gem_package.rb | 5 +++++ spec/unit/provider/package/rubygems_spec.rb | 10 ++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/chef/provider/package/rubygems.rb b/lib/chef/provider/package/rubygems.rb index d152db1926e..c53aa8934a1 100644 --- a/lib/chef/provider/package/rubygems.rb +++ b/lib/chef/provider/package/rubygems.rb @@ -538,8 +538,9 @@ def gem_binary_path def install_via_gem_command(name, version) if @new_resource.source =~ /\.gem$/i name = @new_resource.source -# elsif source_is_remote? -# src = @new_resource.source && " --source=#{@new_resource.source}" + elsif @new_resource.clear_sources + src = ' --clear-sources' + src << (@new_resource.source && " --source=#{@new_resource.source}" || '') else src = @new_resource.source && " --source=#{@new_resource.source} --source=https://rubygems.org" end diff --git a/lib/chef/resource/gem_package.rb b/lib/chef/resource/gem_package.rb index 631aa13f56b..0e838ca0407 100644 --- a/lib/chef/resource/gem_package.rb +++ b/lib/chef/resource/gem_package.rb @@ -27,12 +27,17 @@ class GemPackage < Chef::Resource::Package def initialize(name, run_context=nil) super @resource_name = :gem_package + @clear_sources = false end def source(arg=nil) set_or_return(:source, arg, :kind_of => [ String, Array ]) end + def clear_sources(arg=nil) + set_or_return(:clear_sources, arg, :kind_of => [ TrueClass, FalseClass ]) + end + # Sets a custom gem_binary to run for gem commands. def gem_binary(gem_cmd=nil) set_or_return(:gem_binary,gem_cmd,:kind_of => [ String ]) diff --git a/spec/unit/provider/package/rubygems_spec.rb b/spec/unit/provider/package/rubygems_spec.rb index b2ec482541a..380572499c2 100644 --- a/spec/unit/provider/package/rubygems_spec.rb +++ b/spec/unit/provider/package/rubygems_spec.rb @@ -556,6 +556,16 @@ def gemspec(name, version) expect(@new_resource).to be_updated_by_last_action end + it "installs the gem with cleared sources and explict source when specified" do + @new_resource.gem_binary('/foo/bar') + @new_resource.source('http://mirror.ops.rhcloud.com/mirror/ruby') + @new_resource.clear_sources(true) + expected ="/foo/bar install rspec-core -q --no-rdoc --no-ri -v \"#{@spec_version}\" --clear-sources --source=#{@new_resource.source}" + expect(@provider).to receive(:shell_out!).with(expected, :env => nil) + @provider.run_action(:install) + expect(@new_resource).to be_updated_by_last_action + end + context "when no version is given" do let(:target_version) { nil }