diff --git a/lib/rubygems/commands/uninstall_command.rb b/lib/rubygems/commands/uninstall_command.rb index c66bbe42e1..7f6d5a4bb7 100644 --- a/lib/rubygems/commands/uninstall_command.rb +++ b/lib/rubygems/commands/uninstall_command.rb @@ -168,10 +168,10 @@ that is a dependency of an existing gem. You can use the gems_to_uninstall = {} deps.each do |dep| - next if gems_to_uninstall[dep.name] - gems_to_uninstall[dep.name] = true - - unless original_gem_version[dep.name] == Gem::Requirement.default + if original_gem_version[dep.name] == Gem::Requirement.default + next if gems_to_uninstall[dep.name] + gems_to_uninstall[dep.name] = true + else options[:version] = dep.version end diff --git a/test/rubygems/test_gem_commands_uninstall_command.rb b/test/rubygems/test_gem_commands_uninstall_command.rb index 48c5cadaed..5dd10a4c00 100644 --- a/test/rubygems/test_gem_commands_uninstall_command.rb +++ b/test/rubygems/test_gem_commands_uninstall_command.rb @@ -229,6 +229,26 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase assert File.exist? File.join(@gemhome, "bin", "executable") end + def test_execute_with_multiple_version_specified_as_colon + initial_install + + ui = Gem::MockGemUi.new "y\n" + + util_make_gems + + assert_equal 3, Gem::Specification.find_all_by_name("a").length + + @cmd.options[:force] = true + @cmd.options[:args] = ["a:1", "a:2"] + + use_ui ui do + @cmd.execute + end + + assert_equal 1, Gem::Specification.find_all_by_name("a").length + assert_equal Gem::Version.new("3.a"), Gem::Specification.find_by_name("a").version + end + def test_uninstall_selection ui = Gem::MockGemUi.new "1\n"