Permalink
Browse files

Test cleanup command and remove deprecated calls

  • Loading branch information...
1 parent b4dd1a7 commit b44b2179bdd55175254c7e6d7aaaa004735af3a7 @drbrain drbrain committed May 4, 2011
Showing with 62 additions and 22 deletions.
  1. +1 −4 Manifest.txt
  2. +10 −18 lib/rubygems/commands/cleanup_command.rb
  3. +51 −0 test/rubygems/test_gem_commands_cleanup_command.rb
View
@@ -63,7 +63,6 @@ lib/rubygems/ext/configure_builder.rb
lib/rubygems/ext/ext_conf_builder.rb
lib/rubygems/ext/rake_builder.rb
lib/rubygems/format.rb
-lib/rubygems/fs.rb
lib/rubygems/gem_openssl.rb
lib/rubygems/gem_path_searcher.rb
lib/rubygems/gem_runner.rb
@@ -85,7 +84,6 @@ lib/rubygems/package/tar_reader/entry.rb
lib/rubygems/package/tar_test_case.rb
lib/rubygems/package/tar_writer.rb
lib/rubygems/package_task.rb
-lib/rubygems/path.rb
lib/rubygems/path_support.rb
lib/rubygems/platform.rb
lib/rubygems/remote_fetcher.rb
@@ -130,6 +128,7 @@ test/rubygems/test_gem_command_manager.rb
test/rubygems/test_gem_commands_build_command.rb
test/rubygems/test_gem_commands_cert_command.rb
test/rubygems/test_gem_commands_check_command.rb
+test/rubygems/test_gem_commands_cleanup_command.rb
test/rubygems/test_gem_commands_contents_command.rb
test/rubygems/test_gem_commands_dependency_command.rb
test/rubygems/test_gem_commands_environment_command.rb
@@ -161,7 +160,6 @@ test/rubygems/test_gem_ext_configure_builder.rb
test/rubygems/test_gem_ext_ext_conf_builder.rb
test/rubygems/test_gem_ext_rake_builder.rb
test/rubygems/test_gem_format.rb
-test/rubygems/test_gem_fs.rb
test/rubygems/test_gem_gem_path_searcher.rb
test/rubygems/test_gem_gem_runner.rb
test/rubygems/test_gem_gemcutter_utilities.rb
@@ -176,7 +174,6 @@ test/rubygems/test_gem_package_tar_reader.rb
test/rubygems/test_gem_package_tar_reader_entry.rb
test/rubygems/test_gem_package_tar_writer.rb
test/rubygems/test_gem_package_task.rb
-test/rubygems/test_gem_path.rb
test/rubygems/test_gem_path_support.rb
test/rubygems/test_gem_platform.rb
test/rubygems/test_gem_remote_fetcher.rb
@@ -38,28 +38,20 @@ def execute
say "Cleaning up installed gems..."
primary_gems = {}
- Gem.source_index.each do |name, spec|
+ Gem::Specification.each do |spec|
if primary_gems[spec.name].nil? or
primary_gems[spec.name].version < spec.version then
primary_gems[spec.name] = spec
end
end
- gems_to_cleanup = []
-
- unless options[:args].empty? then
- options[:args].each do |gem_name|
- dep = Gem::Dependency.new gem_name, Gem::Requirement.default
- specs = Gem.source_index.search dep
- specs.each do |spec|
- gems_to_cleanup << spec
- end
- end
- else
- Gem.source_index.each do |name, spec|
- gems_to_cleanup << spec
- end
- end
+ gems_to_cleanup = unless options[:args].empty? then
+ options[:args].map do |gem_name|
+ Gem::Specification.find_all_by_name gem_name
+ end.flatten
+ else
+ Gem::Specification.all
+ end
gems_to_cleanup = gems_to_cleanup.select { |spec|
primary_gems[spec.name].version != spec.version
@@ -83,8 +75,8 @@ def execute
:version => "= #{spec.version}",
}
- if Gem.user_dir == spec.installation_path then
- uninstall_options[:install_dir] = spec.installation_path
+ if Gem.user_dir == spec.base_dir then
+ uninstall_options[:install_dir] = spec.base_dir
end
uninstaller = Gem::Uninstaller.new spec.name, uninstall_options
@@ -0,0 +1,51 @@
+require 'rubygems/test_case'
+require 'rubygems/commands/cleanup_command'
+
+class TestGemCommandsCleanupCommand < Gem::TestCase
+
+ def setup
+ super
+
+ @cmd = Gem::Commands::CleanupCommand.new
+
+ @a_1 = quick_spec 'a', 1
+ @a_2 = quick_spec 'a', 2
+
+ install_gem @a_1
+ install_gem @a_2
+ end
+
+ def test_execute
+ @cmd.options[:args] = %w[a]
+
+ @cmd.execute
+
+ refute_path_exists @a_1.gem_dir
+ end
+
+ def test_execute_all
+ @b_1 = quick_spec 'b', 1
+ @b_2 = quick_spec 'b', 2
+
+ install_gem @b_1
+ install_gem @b_2
+
+ @cmd.options[:args] = []
+
+ @cmd.execute
+
+ refute_path_exists @a_1.gem_dir
+ refute_path_exists @b_1.gem_dir
+ end
+
+ def test_execute_dry_run
+ @cmd.options[:args] = %w[a]
+ @cmd.options[:dryrun] = true
+
+ @cmd.execute
+
+ assert_path_exists @a_1.gem_dir
+ end
+
+end
+

0 comments on commit b44b217

Please sign in to comment.