summaryrefslogtreecommitdiff
path: root/test/rubygems/test_gem_uninstaller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/rubygems/test_gem_uninstaller.rb')
-rw-r--r--test/rubygems/test_gem_uninstaller.rb66
1 files changed, 41 insertions, 25 deletions
diff --git a/test/rubygems/test_gem_uninstaller.rb b/test/rubygems/test_gem_uninstaller.rb
index 0c08f42..93a6f65 100644
--- a/test/rubygems/test_gem_uninstaller.rb
+++ b/test/rubygems/test_gem_uninstaller.rb
@@ -14,26 +14,15 @@ class TestGemUninstaller < Gem::InstallerTestCase
@user_spec.executables = ["executable"]
- # HACK util_make_exec
- user_bin_dir = File.join Gem.user_dir, 'gems', @user_spec.full_name, 'bin'
- FileUtils.mkdir_p user_bin_dir
- exec_path = File.join user_bin_dir, "executable"
- open exec_path, 'w' do |f|
- f.puts "#!/usr/bin/ruby"
- end
-
- user_bin_dir = File.join Gem.user_dir, 'bin'
- FileUtils.mkdir_p user_bin_dir
- exec_path = File.join user_bin_dir, "executable"
- open exec_path, 'w' do |f|
- f.puts "#!/usr/bin/ruby"
- end
-
build_rake_in do
use_ui ui do
@installer.install
@user_installer.install
- Gem::Uninstaller.new(@user_spec.name, :executables => false).uninstall
+
+ Gem.use_paths @gemhome, Gem.user_dir
+
+ @spec = Gem::Specification.find_by_name 'a'
+ @user_spec = Gem::Specification.find_by_name 'b'
end
end
end
@@ -44,6 +33,18 @@ class TestGemUninstaller < Gem::InstallerTestCase
assert_match %r|/foo/bar$|, uninstaller.instance_variable_get(:@gem_home)
end
+ def test_remove_all
+ uninstaller = Gem::Uninstaller.new nil
+
+ ui = Gem::MockGemUi.new "y\n"
+
+ use_ui ui do
+ uninstaller.remove_all [@spec]
+ end
+
+ refute_path_exists @spec.gem_dir
+ end
+
def test_remove_executables_force_keep
uninstaller = Gem::Uninstaller.new nil, :executables => false
@@ -114,14 +115,13 @@ class TestGemUninstaller < Gem::InstallerTestCase
end
exec_path = File.join Gem.user_dir, 'bin', 'executable'
- assert_equal false, File.exist?(exec_path), 'removed exec from bin dir'
+ refute File.exist?(exec_path), 'removed exec from bin dir'
assert_equal "Removing executable\n", @ui.output
ensure
Gem::Installer.exec_format = nil
end
-
def test_path_ok_eh
uninstaller = Gem::Uninstaller.new nil
@@ -131,7 +131,7 @@ class TestGemUninstaller < Gem::InstallerTestCase
def test_path_ok_eh_legacy
uninstaller = Gem::Uninstaller.new nil
- @spec.loaded_from.gsub! @spec.full_name, '\&-legacy'
+ @spec.loaded_from = @spec.loaded_from.gsub @spec.full_name, '\&-legacy'
@spec.platform = 'legacy'
assert_equal true, uninstaller.path_ok?(@gemhome, @spec)
@@ -190,26 +190,42 @@ class TestGemUninstaller < Gem::InstallerTestCase
end
def test_uninstall_user
- uninstaller = Gem::Uninstaller.new @user_spec.name, :executables => true,
- :user_install => true
+ @user_spec = Gem::Specification.find_by_name 'b'
+
+ uninstaller = Gem::Uninstaller.new(@user_spec.name,
+ :executables => true,
+ :user_install => true)
gem_dir = File.join Gem.user_dir, 'gems', @user_spec.full_name
Gem.pre_uninstall do
- assert File.exist?(gem_dir), 'gem_dir should exist'
+ assert_path_exists gem_dir
end
Gem.post_uninstall do
- refute File.exist?(gem_dir), 'gem_dir should not exist'
+ refute_path_exists gem_dir
end
uninstaller.uninstall
- refute File.exist?(gem_dir)
+ refute_path_exists gem_dir
assert_same uninstaller, @pre_uninstall_hook_arg
assert_same uninstaller, @post_uninstall_hook_arg
end
-end
+ def test_uninstall_selection_greater_than_one
+ util_make_gems
+
+ list = Gem::Specification.find_all_by_name('a')
+
+ uninstaller = Gem::Uninstaller.new('a')
+
+ use_ui Gem::MockGemUi.new("2\n") do
+ uninstaller.uninstall
+ end
+ updated_list = Gem::Specification.find_all_by_name('a')
+ assert_equal list.length - 1, updated_list.length
+ end
+end