Skip to content

Commit

Permalink
Clearing sources works for string options
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Burkholder authored and btm committed Mar 27, 2015
1 parent 36f040b commit 312253e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/chef/provider/package/rubygems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions lib/chef/resource/gem_package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 ])
Expand Down
10 changes: 10 additions & 0 deletions spec/unit/provider/package/rubygems_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down

0 comments on commit 312253e

Please sign in to comment.