summaryrefslogtreecommitdiff
path: root/test/rubygems
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
parentc47c095b9740e7c19d6fdca29ab661c1089221d4 (diff)
* 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')
-rw-r--r--test/rubygems/test_gem.rb39
-rw-r--r--test/rubygems/test_gem_commands_check_command.rb50
-rw-r--r--test/rubygems/test_gem_commands_push_command.rb25
-rw-r--r--test/rubygems/test_gem_doctor.rb168
-rw-r--r--test/rubygems/test_gem_installer.rb209
5 files changed, 406 insertions, 85 deletions
diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb
index 20e411a7e4..9efb056546 100644
--- a/test/rubygems/test_gem.rb
+++ b/test/rubygems/test_gem.rb
@@ -774,6 +774,45 @@ class TestGem < Gem::TestCase
assert_equal cwd, $LOAD_PATH.shift
end
+ def test_self_latest_spec_for
+ a1 = quick_spec 'a', 1
+ a2 = quick_spec 'a', 2
+ a3a = quick_spec 'a', '3.a'
+
+ util_setup_fake_fetcher
+ util_setup_spec_fetcher a1, a2, a3a
+
+ spec = Gem.latest_spec_for 'a'
+
+ assert_equal a2, spec
+ end
+
+ def test_self_latest_rubygems_version
+ r1 = quick_spec 'rubygems-update', '1.8.23'
+ r2 = quick_spec 'rubygems-update', '1.8.24'
+ r3 = quick_spec 'rubygems-update', '2.0.0.preview3'
+
+ util_setup_fake_fetcher
+ util_setup_spec_fetcher r1, r2, r3
+
+ version = Gem.latest_rubygems_version
+
+ assert_equal Gem::Version.new('1.8.24'), version
+ end
+
+ def test_self_latest_version_for
+ a1 = quick_spec 'a', 1
+ a2 = quick_spec 'a', 2
+ a3a = quick_spec 'a', '3.a'
+
+ util_setup_fake_fetcher
+ util_setup_spec_fetcher a1, a2, a3a
+
+ version = Gem.latest_version_for 'a'
+
+ assert_equal Gem::Version.new(2), version
+ end
+
def test_self_loaded_specs
foo = quick_spec 'foo'
install_gem foo
diff --git a/test/rubygems/test_gem_commands_check_command.rb b/test/rubygems/test_gem_commands_check_command.rb
index a71c1ebb92..b28748623e 100644
--- a/test/rubygems/test_gem_commands_check_command.rb
+++ b/test/rubygems/test_gem_commands_check_command.rb
@@ -9,10 +9,60 @@ class TestGemCommandsCheckCommand < Gem::TestCase
@cmd = Gem::Commands::CheckCommand.new
end
+ 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_initialize
assert_equal "check", @cmd.command
assert_equal "gem check", @cmd.program_name
assert_match(/Check/, @cmd.summary)
end
+ def test_handle_options
+ @cmd.handle_options %w[--no-alien --no-gems --doctor --dry-run]
+
+ assert @cmd.options[:doctor]
+ refute @cmd.options[:alien]
+ assert @cmd.options[:dry_run]
+ refute @cmd.options[:gems]
+ end
+
+ def test_handle_options_defaults
+ @cmd.handle_options []
+
+ assert @cmd.options[:alien]
+ assert @cmd.options[:gems]
+ refute @cmd.options[:doctor]
+ refute @cmd.options[:dry_run]
+ end
+
+ def test_doctor
+ a = gem 'a'
+ b = gem 'b'
+
+ FileUtils.rm b.spec_file
+
+ assert_path_exists b.gem_dir
+ refute_path_exists b.spec_file
+
+ Gem.use_paths @gemhome
+
+ capture_io do
+ use_ui @ui do
+ @cmd.doctor
+ end
+ end
+
+ refute_path_exists b.gem_dir
+ refute_path_exists b.spec_file
+ end
+
end
diff --git a/test/rubygems/test_gem_commands_push_command.rb b/test/rubygems/test_gem_commands_push_command.rb
index 5ff940bf42..41324b524e 100644
--- a/test/rubygems/test_gem_commands_push_command.rb
+++ b/test/rubygems/test_gem_commands_push_command.rb
@@ -1,14 +1,6 @@
require 'rubygems/test_case'
require 'rubygems/commands/push_command'
-module Gem
- class << self; remove_method :latest_rubygems_version; end
-
- def self.latest_rubygems_version
- Gem::Version.new Gem::VERSION
- end
-end
-
class TestGemCommandsPushCommand < Gem::TestCase
def setup
@@ -33,6 +25,23 @@ class TestGemCommandsPushCommand < Gem::TestCase
Gem::RemoteFetcher.fetcher = @fetcher
@cmd = Gem::Commands::PushCommand.new
+
+ class << Gem
+ alias_method :orig_latest_rubygems_version, :latest_rubygems_version
+
+ def latest_rubygems_version
+ Gem.rubygems_version
+ end
+ end
+ end
+
+ def teardown
+ super
+
+ class << Gem
+ remove_method :latest_rubygems_version
+ alias_method :latest_rubygems_version, :orig_latest_rubygems_version
+ end
end
def send_battery
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
+
diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb
index 0683001f33..98f1878dfb 100644
--- a/test/rubygems/test_gem_installer.rb
+++ b/test/rubygems/test_gem_installer.rb
@@ -245,6 +245,34 @@ load Gem.bin_path('a', 'executable', version)
assert_equal 'a requires b (> 2)', e.message
end
+ def test_ensure_loadable_spec
+ a, a_gem = util_gem 'a', 2 do |s|
+ s.add_dependency 'garbage ~> 5'
+ end
+
+ installer = Gem::Installer.new a_gem
+
+ e = assert_raises Gem::InstallError do
+ installer.ensure_loadable_spec
+ end
+
+ assert_equal "The specification for #{a.full_name} is corrupt " +
+ "(SyntaxError)", e.message
+ end
+
+ def test_ensure_loadable_spec_security_policy
+ a, a_gem = util_gem 'a', 2 do |s|
+ s.add_dependency 'garbage ~> 5'
+ end
+
+ policy = Gem::Security::HighSecurity
+ installer = Gem::Installer.new a_gem, :security_policy => policy
+
+ assert_raises Gem::Security::Exception do
+ installer.ensure_loadable_spec
+ end
+ end
+
def test_extract_files
@installer.extract_files
@@ -818,45 +846,6 @@ load Gem.bin_path('a', 'executable', version)
"code.rb from prior install of same gem shouldn't remain here")
end
- def test_install_check_dependencies
- @spec.add_dependency 'b', '> 5'
- util_setup_gem
-
- use_ui @ui do
- assert_raises Gem::InstallError do
- @installer.install
- end
- end
- end
-
- def test_install_check_dependencies_install_dir
- gemhome2 = "#{@gemhome}2"
- @spec.add_dependency 'd'
-
- quick_gem 'd', 2
-
- FileUtils.mv @gemhome, gemhome2
-
- # Don't leak any already activated gems into the installer, require
- # that it work everything out on it's own.
- Gem::Specification.reset
-
- util_setup_gem
-
- @installer = Gem::Installer.new @gem, :install_dir => gemhome2
-
- gem_home = Gem.dir
-
- build_rake_in do
- use_ui @ui do
- @installer.install
- end
- end
-
- assert File.exist?(File.join(gemhome2, 'gems', @spec.full_name))
- assert_equal gem_home, Gem.dir
- end
-
def test_install_force
use_ui @ui do
installer = Gem::Installer.new old_ruby_required, :force => true
@@ -867,30 +856,6 @@ load Gem.bin_path('a', 'executable', version)
assert File.exist?(gem_dir)
end
- def test_install_ignore_dependencies
- Dir.mkdir util_inst_bindir
- @spec.add_dependency 'b', '> 5'
- util_setup_gem
- @installer.ignore_dependencies = true
-
- build_rake_in do
- use_ui @ui do
- assert_equal @spec, @installer.install
- end
- end
-
- gemdir = File.join @gemhome, 'gems', @spec.full_name
- assert File.exist?(gemdir)
-
- exe = File.join(gemdir, 'bin', 'executable')
- assert File.exist?(exe)
- exe_mode = File.stat(exe).mode & 0111
- assert_equal 0111, exe_mode, "0%o" % exe_mode unless win_platform?
- assert File.exist?(File.join(gemdir, 'lib', 'code.rb'))
-
- assert File.exist?(File.join(@gemhome, 'specifications', @spec.spec_name))
- end
-
def test_install_missing_dirs
FileUtils.rm_f File.join(Gem.dir, 'cache')
FileUtils.rm_f File.join(Gem.dir, 'docs')
@@ -999,18 +964,78 @@ load Gem.bin_path('a', 'executable', version)
assert_match %r|I am a shiny gem!|, @ui.output
end
- def test_install_wrong_ruby_version
+ def test_installation_satisfies_dependency_eh
+ quick_spec 'a'
+
+ dep = Gem::Dependency.new 'a', '>= 2'
+ assert @installer.installation_satisfies_dependency?(dep)
+
+ dep = Gem::Dependency.new 'a', '> 2'
+ refute @installer.installation_satisfies_dependency?(dep)
+ end
+
+ def test_pre_install_checks_dependencies
+ @spec.add_dependency 'b', '> 5'
+ util_setup_gem
+
+ use_ui @ui do
+ assert_raises Gem::InstallError do
+ @installer.install
+ end
+ end
+ end
+
+ def test_pre_install_checks_dependencies_ignore
+ @spec.add_dependency 'b', '> 5'
+ @installer.ignore_dependencies = true
+
+ build_rake_in do
+ use_ui @ui do
+ assert @installer.pre_install_checks
+ end
+ end
+ end
+
+ def test_pre_install_checks_dependencies_install_dir
+ gemhome2 = "#{@gemhome}2"
+ @spec.add_dependency 'd'
+
+ quick_gem 'd', 2
+
+ gem = File.join @gemhome, @spec.file_name
+
+ FileUtils.mv @gemhome, gemhome2
+ FileUtils.mkdir @gemhome
+
+ FileUtils.mv File.join(gemhome2, 'cache', @spec.file_name), gem
+
+ # Don't leak any already activated gems into the installer, require
+ # that it work everything out on it's own.
+ Gem::Specification.reset
+
+ installer = Gem::Installer.new gem, :install_dir => gemhome2
+
+ gem_home = Gem.dir
+
+ build_rake_in do
+ use_ui @ui do
+ assert installer.pre_install_checks
+ end
+ end
+ end
+
+ def test_pre_install_checks_ruby_version
use_ui @ui do
installer = Gem::Installer.new old_ruby_required
e = assert_raises Gem::InstallError do
- installer.install
+ installer.pre_install_checks
end
assert_equal 'old_ruby_required requires Ruby version = 1.4.6.',
e.message
end
end
- def test_install_wrong_rubygems_version
+ def test_pre_install_checks_wrong_rubygems_version
spec = quick_spec 'old_rubygems_required', '1' do |s|
s.required_rubygems_version = '< 0'
end
@@ -1022,23 +1047,13 @@ load Gem.bin_path('a', 'executable', version)
use_ui @ui do
@installer = Gem::Installer.new gem
e = assert_raises Gem::InstallError do
- @installer.install
+ @installer.pre_install_checks
end
assert_equal 'old_rubygems_required requires RubyGems version < 0. ' +
"Try 'gem update --system' to update RubyGems itself.", e.message
end
end
- def test_installation_satisfies_dependency_eh
- quick_spec 'a'
-
- dep = Gem::Dependency.new 'a', '>= 2'
- assert @installer.installation_satisfies_dependency?(dep)
-
- dep = Gem::Dependency.new 'a', '> 2'
- refute @installer.installation_satisfies_dependency?(dep)
- end
-
def test_shebang
util_make_exec @spec, "#!/usr/bin/ruby"
@@ -1190,6 +1205,46 @@ load Gem.bin_path('a', 'executable', version)
assert File.exist?(File.join(dest, 'bin', 'executable'))
end
+ def test_write_build_args
+ refute_path_exists @spec.build_info_file
+
+ @installer.build_args = %w[
+ --with-libyaml-dir /usr/local/Cellar/libyaml/0.1.4
+ ]
+
+ @installer.write_build_info_file
+
+ assert_path_exists @spec.build_info_file
+
+ expected = "--with-libyaml-dir\n/usr/local/Cellar/libyaml/0.1.4\n"
+
+ assert_equal expected, File.read(@spec.build_info_file)
+ end
+
+ def test_write_build_args_empty
+ refute_path_exists @spec.build_info_file
+
+ @installer.write_build_info_file
+
+ refute_path_exists @spec.build_info_file
+ end
+
+ def test_write_cache_file
+ cache_file = File.join @gemhome, 'cache', @spec.file_name
+ gem = File.join @gemhome, @spec.file_name
+
+ FileUtils.mv cache_file, gem
+ refute_path_exists cache_file
+
+ installer = Gem::Installer.new gem
+ installer.spec = @spec
+ installer.gem_home = @gemhome
+
+ installer.write_cache_file
+
+ assert_path_exists cache_file
+ end
+
def test_write_spec
FileUtils.rm @spec.spec_file
refute File.exist?(@spec.spec_file)