diff options
Diffstat (limited to 'test/rubygems/test_gem_commands_uninstall_command.rb')
-rw-r--r-- | test/rubygems/test_gem_commands_uninstall_command.rb | 76 |
1 files changed, 57 insertions, 19 deletions
diff --git a/test/rubygems/test_gem_commands_uninstall_command.rb b/test/rubygems/test_gem_commands_uninstall_command.rb index 083b831c98..4daa61cb0c 100644 --- a/test/rubygems/test_gem_commands_uninstall_command.rb +++ b/test/rubygems/test_gem_commands_uninstall_command.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "installer_test_case" require "rubygems/commands/uninstall_command" @@ -20,14 +21,9 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase gemhome2 = "#{@gemhome}2" a_4, = util_gem "a", 4 - install_gem a_4, :install_dir => gemhome2 - - Gem::Specification.dirs = [@gemhome, gemhome2] + install_gem a_4, install_dir: gemhome2 - assert_includes Gem::Specification.all_names, "a-1" - assert_includes Gem::Specification.all_names, "a-4" - assert_includes Gem::Specification.all_names, "b-2" - assert_includes Gem::Specification.all_names, "default-1" + assert_gems_presence "a-1", "a-4", "b-2", "default-1", dirs: [@gemhome, gemhome2] @cmd.options[:all] = true @cmd.options[:args] = %w[a] @@ -118,7 +114,7 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase def test_execute_removes_executable initial_install - if win_platform? + if Gem.win_platform? assert File.exist?(@executable) else assert File.symlink?(@executable) @@ -162,7 +158,7 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase @cmd.execute assert_equal false, File.exist?(formatted_executable) - rescue + rescue StandardError Gem::Installer.exec_format = nil end @@ -233,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" @@ -346,11 +362,7 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase a_4, = util_gem "a", 4 install_gem a_4 - Gem::Specification.dirs = [@gemhome, gemhome2] - - assert_includes Gem::Specification.all_names, "a-1" - assert_includes Gem::Specification.all_names, "a-4" - assert_includes Gem::Specification.all_names, "default-1" + assert_gems_presence "a-1", "a-4", "default-1", dirs: [@gemhome, gemhome2] @cmd.options[:all] = true @cmd.options[:args] = [] @@ -369,11 +381,9 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase gemhome2 = "#{@gemhome}2" a_4, = util_gem "a", 4 - install_gem a_4 , :install_dir => gemhome2 + install_gem a_4, install_dir: gemhome2 - Gem::Specification.dirs = [@gemhome, gemhome2] - - assert_includes Gem::Specification.all_names, "a-4" + assert_gems_presence "a-4", dirs: [@gemhome, gemhome2] @cmd.options[:args] = ["a:4"] @@ -386,6 +396,26 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase assert_includes e.message, "a is not installed in GEM_HOME" end + def test_execute_outside_gem_home_when_install_dir_given + gemhome2 = "#{@gemhome}2" + + a_4, = util_gem "a", 4 + install_gem a_4, install_dir: gemhome2 + + assert_gems_presence "a-4", dirs: [@gemhome, gemhome2] + + Gem::Specification.dirs = [@gemhome] + + @cmd.options[:install_dir] = gemhome2 + @cmd.options[:args] = ["a:4"] + + @cmd.execute + + Gem::Specification.dirs = [gemhome2] + + refute_includes Gem::Specification.all_names.sort, "a-4" + end + def test_handle_options @cmd.handle_options %w[] @@ -486,7 +516,7 @@ WARNING: Use your OS package manager to uninstall vendor gems end assert_empty @ui.output - assert_match %r{Error: unable to successfully uninstall '#{@spec.name}'}, @ui.error + assert_match(/Error: unable to successfully uninstall '#{@spec.name}'/, @ui.error) end private @@ -501,4 +531,12 @@ WARNING: Use your OS package manager to uninstall vendor gems end end end + + def assert_gems_presence(*gems, dirs:) + Gem::Specification.dirs = dirs + + gems.each do |full_name| + assert_includes Gem::Specification.all_names, full_name + end + end end |