Skip to content

Commit

Permalink
Clean up gem update --system (perform regular gem install slimgems) a…
Browse files Browse the repository at this point in the history
…nd fix

broken tests
  • Loading branch information
lsegal committed May 14, 2011
1 parent 44f3b91 commit 785ad69
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 46 deletions.
31 changes: 4 additions & 27 deletions lib/rubygems/commands/update_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,36 +156,13 @@ def update_rubygems
gems_to_update = which_to_update hig, options[:args]

if gems_to_update.empty? then
say "Latest version currently installed. Aborting."
say "#{Gem::NAME} is already up-to-date (#{Gem::VERSION})"
terminate_interaction
end

update_gem gems_to_update.first, requirement

Gem.source_index.refresh!

installed_gems = Gem.source_index.find_name 'slimgems', requirement
version = installed_gems.last.version

args = []
args << '--prefix' << Gem.prefix if Gem.prefix
args << '--no-rdoc' unless options[:generate_rdoc]
args << '--no-ri' unless options[:generate_ri]
args << '--no-format-executable' if options[:no_format_executable]

update_dir = File.join Gem.dir, 'gems', "slimgems-#{version}"

Dir.chdir update_dir do
say "Installing RubyGems #{version}"
setup_cmd = "#{Gem.ruby} setup.rb #{args.join ' '}"

# Make sure old rubygems isn't loaded
old = ENV["RUBYOPT"]
ENV.delete("RUBYOPT") if old
installed = system setup_cmd
say "#{Gem::NAME} system software updated" if installed
ENV["RUBYOPT"] = old if old
end
update_gem(gems_to_update.first, requirement)
spec = @updated.last
say "#{Gem::NAME} system software updated (#{spec.version})" if spec
end

def which_to_update(highest_installed_gems, gem_names)
Expand Down
15 changes: 13 additions & 2 deletions lib/rubygems/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,16 @@ def install
FileUtils.cp @gem, File.join(@gem_home, "cache")
end

say @spec.post_install_message unless @spec.post_install_message.nil?
unless @spec.post_install_message.nil?
# Only for slimgems
if @spec.name == 'slimgems'
lines = @spec.post_install_message.split("\n")
lines.shift if lines.include?("Upgraded from RubyGems")
say lines.join("\n")
else
say @spec.post_install_message
end
end

@spec.loaded_from = File.join(@gem_home, 'specifications', @spec.spec_name)

Expand Down Expand Up @@ -483,7 +492,9 @@ def windows_stub_script(bindir, bin_file_name)

def build_extensions
return if @spec.extensions.empty?
say "Building native extensions. This could take a while..."
unless @spec.name == 'slimgems'
say "Building native extensions. This could take a while..."
end
start_dir = Dir.pwd
dest_path = File.join @gem_dir, @spec.require_paths.first
ran_rake = false # only run rake once
Expand Down
1 change: 0 additions & 1 deletion slimgems.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ Gem::Specification.new do |s|
s.extensions = ['bootstrap/Rakefile']
s.test_files = Dir.glob('test/**/*.rb')
s.required_ruby_version = '> 1.8.3'
s.add_runtime_dependency 'rake'
end
39 changes: 23 additions & 16 deletions test/test_gem_commands_update_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ class TestGemCommandsUpdateCommand < RubyGemTestCase

def setup
super

@oldpath = Dir.pwd
Dir.chdir(File.dirname(__FILE__))

@cmd = Gem::Commands::UpdateCommand.new

Expand All @@ -23,7 +26,12 @@ def setup
@fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] =
read_binary @a2_path
end


def teardown
super
Dir.chdir(@oldpath)
end

def test_execute
util_clear_gems

Expand All @@ -47,7 +55,7 @@ def test_execute
end

def util_setup_rubygem version
gem = quick_gem('rubygems-update', version.to_s) do |s|
gem = quick_gem('slimgems', version.to_s) do |s|
s.files = %w[setup.rb]
end
write_file File.join(*%W[gems #{gem.original_name} setup.rb])
Expand Down Expand Up @@ -93,10 +101,9 @@ def test_execute_system
end

out = @ui.output.split "\n"
assert_equal "Updating rubygems-update", out.shift
assert_equal "Successfully installed rubygems-update-9", out.shift
assert_equal "Installing RubyGems 9", out.shift
assert_equal "RubyGems system software updated", out.shift
assert_equal "Updating slimgems", out.shift
assert_equal "Successfully installed slimgems-9", out.shift
assert_equal "#{Gem::NAME} system software updated (9)", out.shift

assert_empty out
end
Expand All @@ -119,7 +126,7 @@ def test_execute_system_at_latest
end

out = @ui.output.split "\n"
assert_equal "Latest version currently installed. Aborting.", out.shift
assert_equal "#{Gem::NAME} is already up-to-date (#{Gem::VERSION})", out.shift
assert_empty out
end

Expand All @@ -140,10 +147,9 @@ def test_execute_system_multiple
end

out = @ui.output.split "\n"
assert_equal "Updating rubygems-update", out.shift
assert_equal "Successfully installed rubygems-update-9", out.shift
assert_equal "Installing RubyGems 9", out.shift
assert_equal "RubyGems system software updated", out.shift
assert_equal "Updating slimgems", out.shift
assert_equal "Successfully installed slimgems-9", out.shift
assert_equal "#{Gem::NAME} system software updated (9)", out.shift

assert_empty out
end
Expand All @@ -165,10 +171,9 @@ def test_execute_system_specific
end

out = @ui.output.split "\n"
assert_equal "Updating rubygems-update", out.shift
assert_equal "Successfully installed rubygems-update-8", out.shift
assert_equal "Installing RubyGems 8", out.shift
assert_equal "RubyGems system software updated", out.shift
assert_equal "Updating slimgems", out.shift
assert_equal "Successfully installed slimgems-8", out.shift
assert_equal "#{Gem::NAME} system software updated (8)", out.shift

assert_empty out
end
Expand All @@ -179,7 +184,7 @@ def test_execute_system_with_gems
@cmd.options[:generate_rdoc] = false
@cmd.options[:generate_ri] = false

assert_raises Gem::MockGemUi::TermError do
assert_raises MockGemUi::TermError do
use_ui @ui do
@cmd.execute
end
Expand Down Expand Up @@ -318,6 +323,7 @@ def test_handle_options_system
:force => false,
:args => [],
:generate_rdoc => true,
:test => false,
}

assert_equal expected, @cmd.options
Expand All @@ -338,6 +344,7 @@ def test_handle_options_system_specific
:force => false,
:args => [],
:generate_rdoc => true,
:test => false,
}

assert_equal expected, @cmd.options
Expand Down

0 comments on commit 785ad69

Please sign in to comment.