aboutsummaryrefslogtreecommitdiffstats
path: root/test/rubygems/test_gem_doctor.rb
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-23 00:35:09 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-23 00:35:09 +0000
commit6fe32d72667945605ef710395706e04491bfd86a (patch)
tree7fe4b8f779ff75067b45f48502864fb05787cee7 /test/rubygems/test_gem_doctor.rb
parentc47c095b9740e7c19d6fdca29ab661c1089221d4 (diff)
downloadruby-6fe32d72667945605ef710395706e04491bfd86a.tar.gz
* lib/rubygems/commands/check_command.rb: Added --doctor and --dry-run
options to clean up after failed uninstallation. * test/rubygems/test_gem_commands_check_command.rb: Test for above. * lib/rubygems/commands/push_command.rb: Allow pushes from RubyGems 2.0.0.preview3 * lib/rubygems/commands/update_command.rb: Use Gem.ruby_version * lib/rubygems/dependency.rb: Update style. * lib/rubygems/installer.rb: Ensure installed gem specifications will be useable. Refactor. * test/rubygems/test_gem_installer.rb: ditto. * lib/rubygems/validator.rb: Fixed bug with unreadable files. * lib/rubygems.rb: Fixed broken methods. * test/rubygems/test_gem.rb: Test for above. * test/rubygems/test_gem_commands_push_command.rb: Fixed overridden Gem.latest_rubygems_version git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38564 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/rubygems/test_gem_doctor.rb')
-rw-r--r--test/rubygems/test_gem_doctor.rb168
1 files changed, 168 insertions, 0 deletions
diff --git a/test/rubygems/test_gem_doctor.rb b/test/rubygems/test_gem_doctor.rb
new file mode 100644
index 0000000000..ef702bcd67
--- /dev/null
+++ b/test/rubygems/test_gem_doctor.rb
@@ -0,0 +1,168 @@
+require 'rubygems/test_case'
+require 'rubygems/doctor'
+
+class TestGemDoctor < Gem::TestCase
+
+ def gem name
+ spec = quick_gem name do |gem|
+ gem.files = %W[lib/#{name}.rb Rakefile]
+ end
+
+ write_file File.join(*%W[gems #{spec.full_name} lib #{name}.rb])
+ write_file File.join(*%W[gems #{spec.full_name} Rakefile])
+
+ spec
+ end
+
+ def test_doctor
+ a = gem 'a'
+ b = gem 'b'
+ c = gem 'c'
+
+ Gem.use_paths @userhome, @gemhome
+
+ FileUtils.rm b.spec_file
+
+ open c.spec_file, 'w' do |io|
+ io.write 'this will raise an exception when evaluated.'
+ end
+
+ assert_path_exists File.join(a.gem_dir, 'Rakefile')
+ assert_path_exists File.join(a.gem_dir, 'lib', 'a.rb')
+
+ assert_path_exists b.gem_dir
+ refute_path_exists b.spec_file
+
+ assert_path_exists c.gem_dir
+ assert_path_exists c.spec_file
+
+ doctor = Gem::Doctor.new @gemhome
+
+ capture_io do
+ use_ui @ui do
+ doctor.doctor
+ end
+ end
+
+ assert_path_exists File.join(a.gem_dir, 'Rakefile')
+ assert_path_exists File.join(a.gem_dir, 'lib', 'a.rb')
+
+ refute_path_exists b.gem_dir
+ refute_path_exists b.spec_file
+
+ refute_path_exists c.gem_dir
+ refute_path_exists c.spec_file
+
+ expected = <<-OUTPUT
+Checking #{@gemhome}
+Removed directory gems/b-2
+Removed directory gems/c-2
+Removed file specifications/c-2.gemspec
+
+ OUTPUT
+
+ assert_equal expected, @ui.output
+
+ assert_equal Gem.dir, @userhome
+ assert_equal Gem.path, [@gemhome, @userhome]
+ end
+
+ def test_doctor_dry_run
+ a = gem 'a'
+ b = gem 'b'
+ c = gem 'c'
+
+ Gem.use_paths @userhome, @gemhome
+
+ FileUtils.rm b.spec_file
+
+ open c.spec_file, 'w' do |io|
+ io.write 'this will raise an exception when evaluated.'
+ end
+
+ assert_path_exists File.join(a.gem_dir, 'Rakefile')
+ assert_path_exists File.join(a.gem_dir, 'lib', 'a.rb')
+
+ assert_path_exists b.gem_dir
+ refute_path_exists b.spec_file
+
+ assert_path_exists c.gem_dir
+ assert_path_exists c.spec_file
+
+ doctor = Gem::Doctor.new @gemhome, true
+
+ capture_io do
+ use_ui @ui do
+ doctor.doctor
+ end
+ end
+
+ assert_path_exists File.join(a.gem_dir, 'Rakefile')
+ assert_path_exists File.join(a.gem_dir, 'lib', 'a.rb')
+
+ assert_path_exists b.gem_dir
+ refute_path_exists b.spec_file
+
+ assert_path_exists c.gem_dir
+ assert_path_exists c.spec_file
+
+ expected = <<-OUTPUT
+Checking #{@gemhome}
+Extra directory gems/b-2
+Extra directory gems/c-2
+Extra file specifications/c-2.gemspec
+
+ OUTPUT
+
+ assert_equal expected, @ui.output
+
+ assert_equal Gem.dir, @userhome
+ assert_equal Gem.path, [@gemhome, @userhome]
+ end
+
+ def test_doctor_non_gem_home
+ other_dir = File.join @tempdir, 'other', 'dir'
+
+ FileUtils.mkdir_p other_dir
+
+ doctor = Gem::Doctor.new @tempdir
+
+ capture_io do
+ use_ui @ui do
+ doctor.doctor
+ end
+ end
+
+ assert_path_exists other_dir
+
+ expected = <<-OUTPUT
+Checking #{@tempdir}
+This directory does not appear to be a RubyGems repository, skipping
+
+ OUTPUT
+
+ assert_equal expected, @ui.output
+ end
+
+ def test_doctor_child_missing
+ doctor = Gem::Doctor.new @gemhome
+
+ doctor.doctor_child 'missing', ''
+
+ assert true # count
+ end
+
+ def test_gem_repository_eh
+ doctor = Gem::Doctor.new @gemhome
+
+ refute doctor.gem_repository?, 'no gems installed'
+
+ quick_spec 'a'
+
+ doctor = Gem::Doctor.new @gemhome
+
+ assert doctor.gem_repository?, 'gems installed'
+ end
+
+end
+