summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorryan <ryan@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-01 03:45:05 +0000
committerryan <ryan@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-01 03:45:05 +0000
commitd22130922e7842226d38d59680e4bbb48a28a5f0 (patch)
tree39594d3a14641dd5488a99a5e633239296fa5742 /test
parent4752539e3f3e563d559732c52424206bd6f12dbd (diff)
Import rubygems 1.8.5 (released @ 137c80f)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31885 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/rubygems/functional.rb98
-rw-r--r--test/rubygems/test_gem.rb277
-rw-r--r--test/rubygems/test_gem_builder.rb19
-rw-r--r--test/rubygems/test_gem_command_manager.rb2
-rw-r--r--test/rubygems/test_gem_commands_build_command.rb34
-rw-r--r--test/rubygems/test_gem_commands_cleanup_command.rb57
-rw-r--r--test/rubygems/test_gem_commands_contents_command.rb49
-rw-r--r--test/rubygems/test_gem_commands_dependency_command.rb29
-rw-r--r--test/rubygems/test_gem_commands_fetch_command.rb9
-rw-r--r--test/rubygems/test_gem_commands_help_command.rb64
-rw-r--r--test/rubygems/test_gem_commands_install_command.rb49
-rw-r--r--test/rubygems/test_gem_commands_list_command.rb5
-rw-r--r--test/rubygems/test_gem_commands_outdated_command.rb19
-rw-r--r--test/rubygems/test_gem_commands_pristine_command.rb115
-rw-r--r--test/rubygems/test_gem_commands_push_command.rb2
-rw-r--r--test/rubygems/test_gem_commands_query_command.rb97
-rw-r--r--test/rubygems/test_gem_commands_sources_command.rb17
-rw-r--r--test/rubygems/test_gem_commands_specification_command.rb16
-rw-r--r--test/rubygems/test_gem_commands_stale_command.rb8
-rw-r--r--test/rubygems/test_gem_commands_unpack_command.rb57
-rw-r--r--test/rubygems/test_gem_commands_update_command.rb69
-rw-r--r--test/rubygems/test_gem_commands_which_command.rb11
-rw-r--r--test/rubygems/test_gem_dependency.rb29
-rw-r--r--test/rubygems/test_gem_dependency_installer.rb120
-rw-r--r--test/rubygems/test_gem_dependency_list.rb12
-rw-r--r--test/rubygems/test_gem_doc_manager.rb6
-rw-r--r--test/rubygems/test_gem_format.rb2
-rw-r--r--test/rubygems/test_gem_gem_path_searcher.rb74
-rw-r--r--test/rubygems/test_gem_gem_runner.rb5
-rw-r--r--test/rubygems/test_gem_indexer.rb95
-rw-r--r--test/rubygems/test_gem_install_update_options.rb11
-rw-r--r--test/rubygems/test_gem_installer.rb102
-rw-r--r--test/rubygems/test_gem_package_tar_output.rb1
-rw-r--r--test/rubygems/test_gem_path_support.rb64
-rw-r--r--test/rubygems/test_gem_platform.rb2
-rw-r--r--test/rubygems/test_gem_remote_fetcher.rb194
-rw-r--r--test/rubygems/test_gem_requirement.rb13
-rw-r--r--test/rubygems/test_gem_server.rb38
-rw-r--r--test/rubygems/test_gem_silent_ui.rb4
-rw-r--r--test/rubygems/test_gem_source_index.rb463
-rw-r--r--test/rubygems/test_gem_spec_fetcher.rb91
-rw-r--r--test/rubygems/test_gem_specification.rb437
-rw-r--r--test/rubygems/test_gem_text.rb15
-rw-r--r--test/rubygems/test_gem_uninstaller.rb66
-rw-r--r--test/rubygems/test_kernel.rb3
45 files changed, 1664 insertions, 1286 deletions
diff --git a/test/rubygems/functional.rb b/test/rubygems/functional.rb
deleted file mode 100644
index 6b7131f..0000000
--- a/test/rubygems/functional.rb
+++ /dev/null
@@ -1,98 +0,0 @@
-######################################################################
-# This file is imported from the rubygems project.
-# DO NOT make modifications in this repo. They _will_ be reverted!
-# File a patch instead and assign it to Ryan Davis or Eric Hodel.
-######################################################################
-
-require 'rubygems'
-require 'minitest/unit'
-require 'test/insure_session'
-require 'rubygems/format'
-require 'rubygems/command_manager'
-
-class FunctionalTest < MiniTest::Unit::TestCase
-
- def setup
- @gem_path = File.expand_path("bin/gem")
- lib_path = File.expand_path("lib")
- @ruby_options = "-I#{lib_path} -I."
- @verbose = false
- end
-
- def test_gem_help_options
- gem_nossl 'help options'
- assert_match(/Usage:/, @out, @err)
- assert_status
- end
-
- def test_gem_help_commands
- gem_nossl 'help commands'
- assert_match(/gem install/, @out)
- assert_status
- end
-
- def test_gem_no_args_shows_help
- gem_nossl
- assert_match(/Usage:/, @out)
- assert_status 1
- end
-
- # This test is disabled because of the insanely long time it takes
- # to time out.
- def xtest_bogus_source_hoses_up_remote_install_but_gem_command_gives_decent_error_message
- @ruby_options << " -rtest/bogussources"
- gem_nossl "install asdf --remote"
- assert_match(/error/im, @err)
- assert_status 1
- end
-
- def test_all_command_helps
- mgr = Gem::CommandManager.new
- mgr.command_names.each do |cmdname|
- gem_nossl "help #{cmdname}"
- assert_match(/Usage: gem #{cmdname}/, @out,
- "should see help for #{cmdname}")
- end
- end
-
- # :section: Help Methods
-
- # Run a gem command without the SSL library.
- def gem_nossl(options="")
- old_options = @ruby_options.dup
- @ruby_options << " -Itest/fake_certlib"
- gem(options)
- ensure
- @ruby_options = old_options
- end
-
- # Run a gem command with the SSL library.
- def gem_withssl(options="")
- gem(options)
- end
-
- # Run a gem command for the functional test.
- def gem(options="")
- shell = Session::Shell.new
- options = options + " --config-file missing_file" if options !~ /--config-file/
- command = "#{Gem.ruby} #{@ruby_options} #{@gem_path} #{options}"
- puts "\n\nCOMMAND: [#{command}]" if @verbose
- @out, @err = shell.execute command
- @status = shell.exit_status
- puts "STATUS: [#{@status}]" if @verbose
- puts "OUTPUT: [#{@out}]" if @verbose
- puts "ERROR: [#{@err}]" if @verbose
- puts "PWD: [#{Dir.pwd}]" if @verbose
- shell.close
- end
-
- private
-
- def assert_status(expected_status=0)
- assert_equal expected_status, @status
- end
-
-end
-
-MiniTest::Unit.autorun
-
diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb
index 118066b..9607711 100644
--- a/test/rubygems/test_gem.rb
+++ b/test/rubygems/test_gem.rb
@@ -29,12 +29,12 @@ class TestGem < Gem::TestCase
def assert_activate expected, *specs
specs.each do |spec|
case spec
- when Array
- Gem.activate(*spec)
- when String
- Gem.activate spec
+ when String then
+ Gem::Specification.find_by_name(spec).activate
+ when Gem::Specification then
+ spec.activate
else
- Gem.activate spec.name
+ flunk spec.inspect
end
end
@@ -57,17 +57,21 @@ class TestGem < Gem::TestCase
Gem.unresolved_deps.values.map(&:to_s).sort
end
+ # TODO: move these to specification
def test_self_activate_via_require
- new_spec "a", "1", "b" => "= 1"
- new_spec "b", "1", nil, "lib/b/c.rb"
- new_spec "b", "2", nil, "lib/b/c.rb"
+ a1 = new_spec "a", "1", "b" => "= 1"
+ b1 = new_spec "b", "1", nil, "lib/b/c.rb"
+ b2 = new_spec "b", "2", nil, "lib/b/c.rb"
+
+ install_specs a1, b1, b2
- Gem.activate "a", "= 1"
+ a1.activate
require "b/c"
assert_equal %w(a-1 b-1), loaded_spec_names
end
+ # TODO: move these to specification
def test_self_activate_deep_unambiguous
a1 = new_spec "a", "1", "b" => "= 1"
b1 = new_spec "b", "1", "c" => "= 1"
@@ -77,7 +81,7 @@ class TestGem < Gem::TestCase
install_specs a1, b1, b2, c1, c2
- Gem.activate "a", "= 1"
+ a1.activate
assert_equal %w(a-1 b-1 c-1), loaded_spec_names
end
@@ -88,6 +92,7 @@ class TestGem < Gem::TestCase
$LOADED_FEATURES.replace old_loaded_features
end
+ # TODO: move these to specification
def test_self_activate_ambiguous_direct
save_loaded_features do
a1 = new_spec "a", "1", "b" => "> 0"
@@ -96,9 +101,10 @@ class TestGem < Gem::TestCase
c1 = new_spec "c", "1"
c2 = new_spec "c", "2"
+ Gem::Specification.reset
install_specs a1, b1, b2, c1, c2
- Gem.activate "a", "= 1"
+ a1.activate
assert_equal %w(a-1), loaded_spec_names
assert_equal ["b (> 0)"], unresolved_names
@@ -109,6 +115,7 @@ class TestGem < Gem::TestCase
end
end
+ # TODO: move these to specification
def test_self_activate_ambiguous_indirect
save_loaded_features do
a1 = new_spec "a", "1", "b" => "> 0"
@@ -119,7 +126,7 @@ class TestGem < Gem::TestCase
install_specs a1, b1, b2, c1, c2
- Gem.activate "a", "= 1"
+ a1.activate
assert_equal %w(a-1), loaded_spec_names
assert_equal ["b (> 0)"], unresolved_names
@@ -130,6 +137,7 @@ class TestGem < Gem::TestCase
end
end
+ # TODO: move these to specification
def test_self_activate_ambiguous_unrelated
save_loaded_features do
a1 = new_spec "a", "1", "b" => "> 0"
@@ -141,7 +149,7 @@ class TestGem < Gem::TestCase
install_specs a1, b1, b2, c1, c2, d1
- Gem.activate "a", "= 1"
+ a1.activate
assert_equal %w(a-1), loaded_spec_names
assert_equal ["b (> 0)"], unresolved_names
@@ -152,6 +160,7 @@ class TestGem < Gem::TestCase
end
end
+ # TODO: move these to specification
def test_self_activate_ambiguous_indirect_conflict
save_loaded_features do
a1 = new_spec "a", "1", "b" => "> 0"
@@ -163,7 +172,7 @@ class TestGem < Gem::TestCase
install_specs a1, a2, b1, b2, c1, c2
- Gem.activate "a", "= 2"
+ a2.activate
assert_equal %w(a-2), loaded_spec_names
assert_equal ["b (> 0)"], unresolved_names
@@ -174,13 +183,14 @@ class TestGem < Gem::TestCase
end
end
+ # TODO: move these to specification
def test_require_already_activated
save_loaded_features do
a1 = new_spec "a", "1", nil, "lib/d.rb"
install_specs a1 # , a2, b1, b2, c1, c2
- Gem.activate "a", "= 1"
+ a1.activate
assert_equal %w(a-1), loaded_spec_names
assert_equal [], unresolved_names
@@ -191,6 +201,7 @@ class TestGem < Gem::TestCase
end
end
+ # TODO: move these to specification
def test_require_already_activated_indirect_conflict
save_loaded_features do
a1 = new_spec "a", "1", "b" => "> 0"
@@ -202,8 +213,8 @@ class TestGem < Gem::TestCase
install_specs a1, a2, b1, b2, c1, c2
- Gem.activate "a", "= 1"
- Gem.activate "c", "= 1"
+ a1.activate
+ c1.activate
assert_equal %w(a-1 c-1), loaded_spec_names
assert_equal ["b (> 0)"], unresolved_names
@@ -222,11 +233,26 @@ class TestGem < Gem::TestCase
end
end
+ def test_require_does_not_glob
+ save_loaded_features do
+ a1 = new_spec "a", "1", nil, "lib/a1.rb"
+
+ install_specs a1
+
+ assert_raises ::LoadError do
+ require "a*"
+ end
+
+ assert_equal [], loaded_spec_names
+ end
+ end
+
+ # TODO: move these to specification
def test_self_activate_loaded
- util_spec 'foo', '1'
+ foo = util_spec 'foo', '1'
- assert Gem.activate 'foo'
- refute Gem.activate 'foo'
+ assert foo.activate
+ refute foo.activate
end
##
@@ -249,15 +275,16 @@ class TestGem < Gem::TestCase
# [B] ~> 1.0
#
# and should resolve using b-1.0
+ # TODO: move these to specification
def test_self_activate_over
- util_spec 'a', '1.0', 'b' => '>= 1.0', 'c' => '= 1.0'
+ a = util_spec 'a', '1.0', 'b' => '>= 1.0', 'c' => '= 1.0'
util_spec 'b', '1.0'
util_spec 'b', '1.1'
util_spec 'b', '2.0'
util_spec 'c', '1.0', 'b' => '~> 1.0'
- Gem.activate "a"
+ a.activate
assert_equal %w[a-1.0 c-1.0], loaded_spec_names
assert_equal ["b (>= 1.0, ~> 1.0)"], unresolved_names
@@ -412,28 +439,22 @@ class TestGem < Gem::TestCase
assert_activate %w[d-1 e-1], e1, "d"
end
- def test_self_all_load_paths
+ def test_self_available?
util_make_gems
-
- expected = [
- File.join(@gemhome, *%W[gems #{@a1.full_name} lib]),
- File.join(@gemhome, *%W[gems #{@a2.full_name} lib]),
- File.join(@gemhome, *%W[gems #{@a3a.full_name} lib]),
- File.join(@gemhome, *%W[gems #{@a_evil9.full_name} lib]),
- File.join(@gemhome, *%W[gems #{@b2.full_name} lib]),
- File.join(@gemhome, *%W[gems #{@c1_2.full_name} lib]),
- File.join(@gemhome, *%W[gems #{@pl1.full_name} lib]),
- ]
-
- assert_equal expected, Gem.all_load_paths.sort
+ Deprecate.skip_during do
+ assert(Gem.available?("a"))
+ assert(Gem.available?("a", "1"))
+ assert(Gem.available?("a", ">1"))
+ assert(!Gem.available?("monkeys"))
+ end
end
- def test_self_available?
- util_make_gems
- assert(Gem.available?("a"))
- assert(Gem.available?("a", "1"))
- assert(Gem.available?("a", ">1"))
- assert(!Gem.available?("monkeys"))
+ def test_self_bin_path_no_exec_name
+ e = assert_raises ArgumentError do
+ Gem.bin_path 'a'
+ end
+
+ assert_equal 'you must supply exec_name', e.message
end
def test_self_bin_path_bin_name
@@ -446,16 +467,6 @@ class TestGem < Gem::TestCase
assert_equal @abin_path, Gem.bin_path('a', 'abin', '4')
end
- def test_self_bin_path_name
- util_exec_gem
- assert_equal @exec_path, Gem.bin_path('a')
- end
-
- def test_self_bin_path_name_version
- util_exec_gem
- assert_equal @exec_path, Gem.bin_path('a', nil, '4')
- end
-
def test_self_bin_path_nonexistent_binfile
quick_spec 'a', '2' do |s|
s.executables = ['exec']
@@ -467,14 +478,14 @@ class TestGem < Gem::TestCase
def test_self_bin_path_no_bin_file
quick_spec 'a', '1'
- assert_raises(Gem::Exception) do
+ assert_raises(ArgumentError) do
Gem.bin_path('a', nil, '1')
end
end
def test_self_bin_path_not_found
assert_raises(Gem::GemNotFoundException) do
- Gem.bin_path('non-existent')
+ Gem.bin_path('non-existent', 'blah')
end
end
@@ -482,7 +493,6 @@ class TestGem < Gem::TestCase
util_exec_gem
quick_spec 'a', '10' do |s|
s.executables = []
- s.default_executable = nil
end
# Should not find a-10's non-abin (bug)
assert_equal @abin_path, Gem.bin_path('a', 'abin')
@@ -507,17 +517,12 @@ class TestGem < Gem::TestCase
end
def test_self_clear_paths
- Gem.dir
- Gem.path
- searcher = Gem.searcher
- source_index = Gem.source_index
+ assert_match(/gemhome$/, Gem.dir)
+ assert_match(/gemhome$/, Gem.path.first)
Gem.clear_paths
- assert_equal nil, Gem.instance_variable_get(:@gem_home)
- assert_equal nil, Gem.instance_variable_get(:@gem_path)
- refute_equal searcher, Gem.searcher
- refute_equal source_index.object_id, Gem.source_index.object_id
+ assert_nil Gem::Specification.send(:class_variable_get, :@@all)
end
def test_self_configuration
@@ -540,8 +545,6 @@ class TestGem < Gem::TestCase
install_gem foo
end
- Gem.source_index = nil
-
gem 'foo'
expected = File.join @gemhome, 'gems', foo.full_name, 'data', 'foo'
@@ -598,7 +601,7 @@ class TestGem < Gem::TestCase
Gem.ensure_gem_subdirectories @gemhome
- assert File.directory?(Gem.cache_dir(@gemhome))
+ assert File.directory? File.join(@gemhome, "cache")
end
def test_self_ensure_gem_directories_missing_parents
@@ -610,7 +613,7 @@ class TestGem < Gem::TestCase
Gem.ensure_gem_subdirectories gemdir
- assert File.directory?(Gem.cache_dir(gemdir))
+ assert File.directory?(util_cache_dir)
end
unless win_platform? then # only for FS that support write protection
@@ -624,7 +627,7 @@ class TestGem < Gem::TestCase
Gem.ensure_gem_subdirectories gemdir
- refute File.exist?(Gem.cache_dir(gemdir))
+ refute File.exist?(util_cache_dir)
ensure
FileUtils.chmod 0600, gemdir
end
@@ -641,7 +644,7 @@ class TestGem < Gem::TestCase
Gem.ensure_gem_subdirectories gemdir
- refute File.exist?(Gem.cache_dir(gemdir))
+ refute File.exist? File.join(gemdir, "gems")
ensure
FileUtils.chmod 0600, parent
end
@@ -661,30 +664,26 @@ class TestGem < Gem::TestCase
end
def test_self_find_files
- discover_path = File.join 'lib', 'sff', 'discover.rb'
cwd = File.expand_path("test/rubygems", @@project_dir)
$LOAD_PATH.unshift cwd
- foo1 = quick_gem 'sff', '1' do |s|
- s.files << discover_path
- end
-
- foo2 = quick_gem 'sff', '2' do |s|
- s.files << discover_path
- end
-
- path = File.join 'gems', foo1.full_name, discover_path
- write_file(path) { |fp| fp.puts "# #{path}" }
+ discover_path = File.join 'lib', 'sff', 'discover.rb'
- path = File.join 'gems', foo2.full_name, discover_path
- write_file(path) { |fp| fp.puts "# #{path}" }
+ foo1, foo2 = %w(1 2).map { |version|
+ spec = quick_gem 'sff', version do |s|
+ s.files << discover_path
+ end
- @fetcher = Gem::FakeFetcher.new
- Gem::RemoteFetcher.fetcher = @fetcher
+ write_file(File.join 'gems', spec.full_name, discover_path) do |fp|
+ fp.puts "# #{spec.full_name}"
+ end
- Gem.source_index = util_setup_spec_fetcher foo1, foo2
+ spec
+ }
+ # HACK should be Gem.refresh
Gem.searcher = nil
+ Gem::Specification.reset
expected = [
File.expand_path('test/rubygems/sff/discover.rb', @@project_dir),
@@ -698,26 +697,11 @@ class TestGem < Gem::TestCase
assert_equal cwd, $LOAD_PATH.shift
end
- def test_self_latest_load_paths
- util_make_gems
-
- expected = [
- File.join(@gemhome, *%W[gems #{@a3a.full_name} lib]),
- File.join(@gemhome, *%W[gems #{@a_evil9.full_name} lib]),
- File.join(@gemhome, *%W[gems #{@b2.full_name} lib]),
- File.join(@gemhome, *%W[gems #{@c1_2.full_name} lib]),
- File.join(@gemhome, *%W[gems #{@pl1.full_name} lib]),
- ]
-
- assert_equal expected, Gem.latest_load_paths.sort
- end
-
def test_self_loaded_specs
foo = quick_spec 'foo'
install_gem foo
- Gem.source_index = nil
- Gem.activate 'foo'
+ foo.activate
assert_equal true, Gem.loaded_specs.keys.include?('foo')
end
@@ -738,9 +722,10 @@ class TestGem < Gem::TestCase
orig_APPLE_GEM_HOME = APPLE_GEM_HOME
Object.send :remove_const, :APPLE_GEM_HOME
end
- Gem.instance_variable_set :@gem_path, nil
- assert_equal [Gem.default_path, Gem.dir].flatten, Gem.path
+ Gem.instance_variable_set :@paths, nil
+
+ assert_equal [Gem.default_path, Gem.dir].flatten.uniq, Gem.path
ensure
Object.const_set :APPLE_GEM_HOME, orig_APPLE_GEM_HOME
end
@@ -771,7 +756,6 @@ class TestGem < Gem::TestCase
end
def test_self_path_ENV_PATH
- Gem.send :set_paths, nil
path_count = Gem.path.size
Gem.clear_paths
@@ -840,29 +824,20 @@ class TestGem < Gem::TestCase
def test_self_refresh
util_make_gems
- a1_spec = File.join @gemhome, "specifications", @a1.spec_name
-
- FileUtils.mv a1_spec, @tempdir
+ a1_spec = @a1.spec_file
+ moved_path = File.join @tempdir, File.basename(a1_spec)
- refute Gem.source_index.gems.include?(@a1.full_name)
-
- FileUtils.mv File.join(@tempdir, @a1.spec_name), a1_spec
+ FileUtils.mv a1_spec, moved_path
Gem.refresh
- assert_includes Gem.source_index.gems, @a1.full_name
- assert_equal nil, Gem.instance_variable_get(:@searcher)
- end
+ refute_includes Gem::Specification.all_names, @a1.full_name
- def test_self_required_location
- util_make_gems
+ FileUtils.mv moved_path, a1_spec
+
+ Gem.refresh
- assert_equal File.join(@tempdir, *%w[gemhome gems c-1.2 lib code.rb]),
- Gem.required_location("c", "code.rb")
- assert_equal File.join(@tempdir, *%w[gemhome gems a-1 lib code.rb]),
- Gem.required_location("a", "code.rb", "< 2")
- assert_equal File.join(@tempdir, *%w[gemhome gems a-2 lib code.rb]),
- Gem.required_location("a", "code.rb", "= 2")
+ assert_includes Gem::Specification.all_names, @a1.full_name
end
def test_self_ruby_escaping_spaces_in_path
@@ -927,19 +902,20 @@ class TestGem < Gem::TestCase
util_restore_RUBY_VERSION
end
- def test_self_searcher
- assert_kind_of Gem::GemPathSearcher, Gem.searcher
- end
-
- def test_self_set_paths
+ def test_self_paths_eq
other = File.join @tempdir, 'other'
path = [@userhome, other].join File::PATH_SEPARATOR
- Gem.send :set_paths, path
+
+ #
+ # FIXME remove after fixing test_case
+ #
+ ENV["GEM_HOME"] = @gemhome
+ Gem.paths = { "GEM_PATH" => path }
assert_equal [@userhome, other, @gemhome], Gem.path
end
- def test_self_set_paths_nonexistent_home
+ def test_self_paths_eq_nonexistent_home
ENV['GEM_HOME'] = @gemhome
Gem.clear_paths
@@ -947,19 +923,37 @@ class TestGem < Gem::TestCase
ENV['HOME'] = other
- Gem.send :set_paths, other
+ Gem.paths = { "GEM_PATH" => other }
assert_equal [other, @gemhome], Gem.path
end
def test_self_source_index
- assert_kind_of Gem::SourceIndex, Gem.source_index
+ Deprecate.skip_during do
+ assert_kind_of Gem::SourceIndex, Gem.source_index
+ end
end
def test_self_sources
assert_equal %w[http://gems.example.com/], Gem.sources
end
+ def test_self_try_activate_missing_dep
+ a = util_spec 'a', '1.0', 'b' => '>= 1.0'
+
+ a_file = File.join a.gem_dir, 'lib', 'a_file.rb'
+
+ write_file a_file do |io|
+ io.puts '# a_file.rb'
+ end
+
+ e = assert_raises Gem::LoadError do
+ Gem.try_activate 'a_file'
+ end
+
+ assert_match %r%Could not find b %, e.message
+ end
+
def test_ssl_available_eh
orig_Gem_ssl_available = Gem.ssl_available?
@@ -994,20 +988,6 @@ class TestGem < Gem::TestCase
end
end
- def test_self_cache_dir
- util_ensure_gem_dirs
-
- assert_equal File.join(@gemhome, 'cache'), Gem.cache_dir
- assert_equal File.join(@userhome, '.gem', Gem.ruby_engine, Gem::ConfigMap[:ruby_version], 'cache'), Gem.cache_dir(Gem.user_dir)
- end
-
- def test_self_cache_gem
- util_ensure_gem_dirs
-
- assert_equal File.join(@gemhome, 'cache', 'test.gem'), Gem.cache_gem('test.gem')
- assert_equal File.join(@userhome, '.gem', Gem.ruby_engine, Gem::ConfigMap[:ruby_version], 'cache', 'test.gem'), Gem.cache_gem('test.gem', Gem.user_dir)
- end
-
if Gem.win_platform? then
def test_self_user_home_userprofile
skip 'Ruby 1.9 properly handles ~ path expansion' unless '1.9' > RUBY_VERSION
@@ -1069,8 +1049,8 @@ class TestGem < Gem::TestCase
install_gem foo
end
- Gem.source_index = nil
Gem.searcher = nil
+ Gem::Specification.reset
gem 'foo'
@@ -1114,6 +1094,10 @@ class TestGem < Gem::TestCase
def util_ensure_gem_dirs
Gem.ensure_gem_subdirectories @gemhome
+
+ #
+ # FIXME what does this solve precisely? -ebh
+ #
@additional.each do |dir|
Gem.ensure_gem_subdirectories @gemhome
end
@@ -1121,7 +1105,6 @@ class TestGem < Gem::TestCase
def util_exec_gem
spec, _ = quick_spec 'a', '4' do |s|
- s.default_executable = 'exec'
s.executables = ['exec', 'abin']
end
@@ -1164,5 +1147,9 @@ class TestGem < Gem::TestCase
Gem::Commands.send :remove_const, :InterruptCommand if
Gem::Commands.const_defined? :InterruptCommand
end
+
+ def util_cache_dir
+ File.join Gem.dir, "cache"
+ end
end
diff --git a/test/rubygems/test_gem_builder.rb b/test/rubygems/test_gem_builder.rb
index f95472f..5895b5f 100644
--- a/test/rubygems/test_gem_builder.rb
+++ b/test/rubygems/test_gem_builder.rb
@@ -6,6 +6,7 @@
require 'rubygems/test_case'
require 'rubygems/builder'
+require 'rubygems/package'
class TestGemBuilder < Gem::TestCase
@@ -29,5 +30,21 @@ class TestGemBuilder < Gem::TestCase
end
end
-end
+ def test_build_specification_result
+ util_make_gems
+
+ spec = build_gem_and_yield_spec @a1
+
+ assert_operator @a1, :eql?, spec
+ end
+ def build_gem_and_yield_spec(spec)
+ builder = Gem::Builder.new spec
+
+ spec = Dir.chdir @tempdir do
+ FileUtils.mkdir 'lib'
+ File.open('lib/code.rb', 'w') { |f| f << "something" }
+ Gem::Package.open(File.open(builder.build, 'rb')) { |x| x.metadata }
+ end
+ end
+end
diff --git a/test/rubygems/test_gem_command_manager.rb b/test/rubygems/test_gem_command_manager.rb
index 3769c25..54b26e1 100644
--- a/test/rubygems/test_gem_command_manager.rb
+++ b/test/rubygems/test_gem_command_manager.rb
@@ -29,6 +29,7 @@ class TestGemCommandManager < Gem::TestCase
end
ensure
$:.replace old_load_path
+ Gem::CommandManager.reset
end
def test_run_crash_command
@@ -46,6 +47,7 @@ class TestGemCommandManager < Gem::TestCase
end
ensure
$:.replace old_load_path
+ @command_manager.unregister_command :crash
end
def test_process_args_bad_arg
diff --git a/test/rubygems/test_gem_commands_build_command.rb b/test/rubygems/test_gem_commands_build_command.rb
index 5c38a1a..d4d7c29 100644
--- a/test/rubygems/test_gem_commands_build_command.rb
+++ b/test/rubygems/test_gem_commands_build_command.rb
@@ -40,10 +40,38 @@ class TestGemCommandsBuildCommand < Gem::TestCase
util_test_build_gem @gem, gemspec_file
end
- def test_execute_bad_gem
+ def test_execute_bad_spec
+ @gem.date = "2010-11-08"
+
+ gemspec_file = File.join(@tempdir, @gem.spec_name)
+
+ File.open gemspec_file, 'w' do |gs|
+ gs.write @gem.to_ruby.sub(/11-08/, "11-8")
+ end
+
+ @cmd.options[:args] = [gemspec_file]
+
+ out, err = use_ui @ui do
+ capture_io do
+ assert_raises Gem::MockGemUi::TermError do
+ @cmd.execute
+ end
+ end
+ end
+
+ assert_equal "", out
+ assert_match(/invalid date format in specification/, err)
+
+ assert_equal '', @ui.output
+ assert_equal "ERROR: Error loading gemspec. Aborting.\n", @ui.error
+ end
+
+ def test_execute_missing_file
@cmd.options[:args] = %w[some_gem]
use_ui @ui do
- @cmd.execute
+ assert_raises Gem::MockGemUi::TermError do
+ @cmd.execute
+ end
end
assert_equal '', @ui.output
@@ -67,7 +95,7 @@ class TestGemCommandsBuildCommand < Gem::TestCase
assert_equal [], output
assert_equal '', @ui.error
- gem_file = File.join @tempdir, gem.file_name
+ gem_file = File.join @tempdir, File.basename(gem.cache_file)
assert File.exist?(gem_file)
spec = Gem::Format.from_file_by_path(gem_file).spec
diff --git a/test/rubygems/test_gem_commands_cleanup_command.rb b/test/rubygems/test_gem_commands_cleanup_command.rb
new file mode 100644
index 0000000..14224c4
--- /dev/null
+++ b/test/rubygems/test_gem_commands_cleanup_command.rb
@@ -0,0 +1,57 @@
+######################################################################
+# This file is imported from the rubygems project.
+# DO NOT make modifications in this repo. They _will_ be reverted!
+# File a patch instead and assign it to Ryan Davis or Eric Hodel.
+######################################################################
+
+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
+
diff --git a/test/rubygems/test_gem_commands_contents_command.rb b/test/rubygems/test_gem_commands_contents_command.rb
index 6b9750e..cf927e7 100644
--- a/test/rubygems/test_gem_commands_contents_command.rb
+++ b/test/rubygems/test_gem_commands_contents_command.rb
@@ -15,11 +15,18 @@ class TestGemCommandsContentsCommand < Gem::TestCase
@cmd = Gem::Commands::ContentsCommand.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])
+ end
+
def test_execute
@cmd.options[:args] = %w[foo]
- quick_gem 'foo' do |gem|
- gem.files = %w[lib/foo.rb Rakefile]
- end
+
+ gem 'foo'
use_ui @ui do
@cmd.execute
@@ -33,13 +40,8 @@ class TestGemCommandsContentsCommand < Gem::TestCase
def test_execute_all
@cmd.options[:all] = true
- quick_gem 'foo' do |gem|
- gem.files = %w[lib/foo.rb Rakefile]
- end
-
- quick_gem 'bar' do |gem|
- gem.files = %w[lib/bar.rb Rakefile]
- end
+ gem 'foo'
+ gem 'bar'
use_ui @ui do
@cmd.execute
@@ -67,13 +69,8 @@ class TestGemCommandsContentsCommand < Gem::TestCase
def test_execute_exact_match
@cmd.options[:args] = %w[foo]
- quick_gem 'foo' do |gem|
- gem.files = %w[lib/foo.rb Rakefile]
- end
-
- quick_gem 'foo_bar' do |gem|
- gem.files = %w[lib/foo_bar.rb Rakefile]
- end
+ gem 'foo'
+ gem 'bar'
use_ui @ui do
@cmd.execute
@@ -88,9 +85,7 @@ class TestGemCommandsContentsCommand < Gem::TestCase
@cmd.options[:args] = %w[foo]
@cmd.options[:lib_only] = true
- quick_gem 'foo' do |gem|
- gem.files = %w[lib/foo.rb Rakefile]
- end
+ gem 'foo'
use_ui @ui do
@cmd.execute
@@ -104,13 +99,9 @@ class TestGemCommandsContentsCommand < Gem::TestCase
def test_execute_multiple
@cmd.options[:args] = %w[foo bar]
- quick_gem 'foo' do |gem|
- gem.files = %w[lib/foo.rb Rakefile]
- end
- quick_gem 'bar' do |gem|
- gem.files = %w[lib/bar.rb Rakefile]
- end
+ gem 'foo'
+ gem 'bar'
use_ui @ui do
@cmd.execute
@@ -126,17 +117,15 @@ class TestGemCommandsContentsCommand < Gem::TestCase
@cmd.options[:args] = %w[foo]
@cmd.options[:prefix] = false
- quick_gem 'foo' do |gem|
- gem.files = %w[lib/foo.rb Rakefile]
- end
+ gem 'foo'
use_ui @ui do
@cmd.execute
end
expected = <<-EOF
-lib/foo.rb
Rakefile
+lib/foo.rb
EOF
assert_equal expected, @ui.output
diff --git a/test/rubygems/test_gem_commands_dependency_command.rb b/test/rubygems/test_gem_commands_dependency_command.rb
index 665cd98..d3f2b68 100644
--- a/test/rubygems/test_gem_commands_dependency_command.rb
+++ b/test/rubygems/test_gem_commands_dependency_command.rb
@@ -24,8 +24,6 @@ class TestGemCommandsDependencyCommand < Gem::TestCase
gem.add_dependency 'baz', '> 1'
end
- Gem.source_index = nil
-
@cmd.options[:args] = %w[foo]
use_ui @ui do
@@ -38,8 +36,6 @@ class TestGemCommandsDependencyCommand < Gem::TestCase
end
def test_execute_no_args
- Gem.source_index = nil
-
@cmd.options[:args] = []
use_ui @ui do
@@ -99,8 +95,6 @@ Gem pl-1-x86-linux
end
def test_execute_regexp
- Gem.source_index = nil
-
@cmd.options[:args] = %w[/[ab]/]
use_ui @ui do
@@ -136,8 +130,6 @@ Gem b-2
gem.add_dependency 'foo'
end
- Gem.source_index = nil
-
@cmd.options[:args] = %w[foo]
@cmd.options[:reverse_dependencies] = true
@@ -199,14 +191,31 @@ ERROR: Only reverse dependencies for local gems are supported.
assert_equal '', @ui.error
end
+ def test_execute_remote_version
+ @fetcher = Gem::FakeFetcher.new
+ Gem::RemoteFetcher.fetcher = @fetcher
+
+ util_setup_spec_fetcher @a1, @a2
+
+ @cmd.options[:args] = %w[a]
+ @cmd.options[:domain] = :remote
+ @cmd.options[:version] = req '= 1'
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_equal "Gem a-1\n\n", @ui.output
+ assert_equal '', @ui.error
+ end
+
def test_execute_prerelease
@fetcher = Gem::FakeFetcher.new
Gem::RemoteFetcher.fetcher = @fetcher
+ util_clear_gems
util_setup_spec_fetcher @a2_pre
- FileUtils.rm File.join(@gemhome, 'specifications', @a2_pre.spec_name)
-
@cmd.options[:args] = %w[a]
@cmd.options[:domain] = :remote
@cmd.options[:prerelease] = true
diff --git a/test/rubygems/test_gem_commands_fetch_command.rb b/test/rubygems/test_gem_commands_fetch_command.rb
index 173a335..926e9e9 100644
--- a/test/rubygems/test_gem_commands_fetch_command.rb
+++ b/test/rubygems/test_gem_commands_fetch_command.rb
@@ -22,7 +22,7 @@ class TestGemCommandsFetchCommand < Gem::TestCase
util_setup_spec_fetcher @a2
@fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] =
- File.read(Gem.cache_gem(@a2.file_name, @gemhome))
+ File.read(@a2.cache_file)
@cmd.options[:args] = [@a2.name]
@@ -38,12 +38,13 @@ class TestGemCommandsFetchCommand < Gem::TestCase
def test_execute_prerelease
util_setup_fake_fetcher true
+ util_clear_gems
util_setup_spec_fetcher @a2, @a2_pre
@fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] =
- File.read(Gem.cache_gem(@a2.file_name, @gemhome))
+ File.read(@a2.cache_file)
@fetcher.data["#{@gem_repo}gems/#{@a2_pre.file_name}"] =
- File.read(Gem.cache_gem(@a2_pre.file_name, @gemhome))
+ File.read(@a2_pre.cache_file)
@cmd.options[:args] = [@a2.name]
@cmd.options[:prerelease] = true
@@ -63,7 +64,7 @@ class TestGemCommandsFetchCommand < Gem::TestCase
util_setup_spec_fetcher @a1, @a2
@fetcher.data["#{@gem_repo}gems/#{@a1.file_name}"] =
- File.read(Gem.cache_gem(@a1.file_name, @gemhome))
+ File.read(@a1.cache_file)
@cmd.options[:args] = [@a2.name]
@cmd.options[:version] = Gem::Requirement.new '1'
diff --git a/test/rubygems/test_gem_commands_help_command.rb b/test/rubygems/test_gem_commands_help_command.rb
new file mode 100644
index 0000000..acfc2da
--- /dev/null
+++ b/test/rubygems/test_gem_commands_help_command.rb
@@ -0,0 +1,64 @@
+######################################################################
+# This file is imported from the rubygems project.
+# DO NOT make modifications in this repo. They _will_ be reverted!
+# File a patch instead and assign it to Ryan Davis or Eric Hodel.
+######################################################################
+
+require "rubygems"
+require "rubygems/test_case"
+require "rubygems/commands/help_command"
+require "rubygems/format"
+require "rubygems/command_manager"
+
+class TestGemCommandsHelpCommand < Gem::TestCase
+ def setup
+ super
+
+ @cmd = Gem::Commands::HelpCommand.new
+ end
+
+ def test_gem_help_bad
+ util_gem 'bad' do |out, err|
+ assert_equal('', out)
+ assert_match(/Unknown command bad. Try gem help commands\n/, err)
+ end
+ end
+
+ def test_gem_help_platforms
+ util_gem 'platforms' do |out, err|
+ assert_match(/x86-freebsd/, out)
+ assert_equal '', err
+ end
+ end
+
+ def test_gem_help_commands
+ mgr = Gem::CommandManager.new
+
+ util_gem 'commands' do |out, err|
+ mgr.command_names.each do |cmd|
+ assert_match(/\s+#{cmd}\s+\S+/, out)
+ end
+ assert_equal '', err
+ end
+ end
+
+ def test_gem_no_args_shows_help
+ util_gem do |out, err|
+ assert_match(/Usage:/, out)
+ assert_match(/gem install/, out)
+ assert_equal '', err
+ end
+ end
+
+ def util_gem *args
+ @cmd.options[:args] = args
+
+ use_ui @ui do
+ Dir.chdir @tempdir do
+ @cmd.execute
+ end
+ end
+
+ yield @ui.output, @ui.error
+ end
+end
diff --git a/test/rubygems/test_gem_commands_install_command.rb b/test/rubygems/test_gem_commands_install_command.rb
index adc66aa..522731b 100644
--- a/test/rubygems/test_gem_commands_install_command.rb
+++ b/test/rubygems/test_gem_commands_install_command.rb
@@ -24,13 +24,13 @@ class TestGemCommandsInstallCommand < Gem::TestCase
end
def test_execute_exclude_prerelease
- util_setup_fake_fetcher(:prerelease)
- util_setup_spec_fetcher @a2, @a2_pre
+ util_setup_fake_fetcher :prerelease
+ util_setup_spec_fetcher
@fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] =
- read_binary(Gem.cache_gem(@a2.file_name, @gemhome))
+ read_binary(@a2.cache_file)
@fetcher.data["#{@gem_repo}gems/#{@a2_pre.file_name}"] =
- read_binary(Gem.cache_gem(@a2_pre.file_name, @gemhome))
+ read_binary(@a2_pre.cache_file)
@cmd.options[:args] = [@a2.name]
@@ -46,13 +46,13 @@ class TestGemCommandsInstallCommand < Gem::TestCase
end
def test_execute_explicit_version_includes_prerelease
- util_setup_fake_fetcher(:prerelease)
- util_setup_spec_fetcher @a2, @a2_pre
+ util_setup_fake_fetcher :prerelease
+ util_setup_spec_fetcher
@fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] =
- read_binary(Gem.cache_gem(@a2.file_name, @gemhome))
+ read_binary(@a2.cache_file)
@fetcher.data["#{@gem_repo}gems/#{@a2_pre.file_name}"] =
- read_binary(Gem.cache_gem(@a2_pre.file_name, @gemhome))
+ read_binary(@a2_pre.cache_file)
@cmd.handle_options [@a2_pre.name, '--version', @a2_pre.version.to_s,
"--no-ri", "--no-rdoc"]
@@ -92,7 +92,7 @@ class TestGemCommandsInstallCommand < Gem::TestCase
util_setup_fake_fetcher
@cmd.options[:domain] = :local
- FileUtils.mv Gem.cache_gem(@a2.file_name, @gemhome), @tempdir
+ FileUtils.mv @a2.cache_file, @tempdir
@cmd.options[:args] = [@a2.name]
@@ -121,15 +121,15 @@ class TestGemCommandsInstallCommand < Gem::TestCase
util_setup_fake_fetcher
@cmd.options[:user_install] = false
- FileUtils.mv Gem.cache_gem(@a2.file_name, @gemhome), @tempdir
+ FileUtils.mv @a2.cache_file, @tempdir
@cmd.options[:args] = [@a2.name]
use_ui @ui do
orig_dir = Dir.pwd
begin
- File.chmod 0755, @userhome
- File.chmod 0555, @gemhome
+ FileUtils.chmod 0755, @userhome
+ FileUtils.chmod 0555, @gemhome
Dir.chdir @tempdir
assert_raises Gem::FilePermissionError do
@@ -137,7 +137,7 @@ class TestGemCommandsInstallCommand < Gem::TestCase
end
ensure
Dir.chdir orig_dir
- File.chmod 0755, @gemhome
+ FileUtils.chmod 0755, @gemhome
end
end
end
@@ -208,13 +208,14 @@ ERROR: Possible alternatives: non_existent_with_hint
end
def test_execute_prerelease
- util_setup_fake_fetcher(:prerelease)
+ util_setup_fake_fetcher :prerelease
+ util_clear_gems
util_setup_spec_fetcher @a2, @a2_pre
@fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] =
- read_binary(Gem.cache_gem(@a2.file_name, @gemhome))
+ read_binary(@a2.cache_file)
@fetcher.data["#{@gem_repo}gems/#{@a2_pre.file_name}"] =
- read_binary(Gem.cache_gem(@a2_pre.file_name, @gemhome))
+ read_binary(@a2_pre.cache_file)
@cmd.options[:prerelease] = true
@cmd.options[:args] = [@a2_pre.name]
@@ -235,10 +236,10 @@ ERROR: Possible alternatives: non_existent_with_hint
@cmd.options[:generate_ri] = true
util_setup_fake_fetcher
- util_setup_spec_fetcher @a2
+ util_setup_spec_fetcher
@fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] =
- read_binary(Gem.cache_gem(@a2.file_name, @gemhome))
+ read_binary(@a2.cache_file)
@cmd.options[:args] = [@a2.name]
@@ -265,9 +266,9 @@ ERROR: Possible alternatives: non_existent_with_hint
util_setup_fake_fetcher
@cmd.options[:domain] = :local
- FileUtils.mv Gem.cache_gem(@a2.file_name, @gemhome), @tempdir
+ FileUtils.mv @a2.cache_file, @tempdir
- FileUtils.mv Gem.cache_gem(@b2.file_name, @gemhome), @tempdir
+ FileUtils.mv @b2.cache_file, @tempdir
@cmd.options[:args] = [@a2.name, @b2.name]
@@ -293,10 +294,10 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_execute_conservative
util_setup_fake_fetcher
- util_setup_spec_fetcher @b2
+ util_setup_spec_fetcher
@fetcher.data["#{@gem_repo}gems/#{@b2.file_name}"] =
- read_binary(Gem.cache_gem(@b2.file_name, @gemhome))
+ read_binary(@b2.cache_file)
uninstall_gem(@b2)
@@ -308,16 +309,16 @@ ERROR: Possible alternatives: non_existent_with_hint
orig_dir = Dir.pwd
begin
Dir.chdir @tempdir
- e = assert_raises Gem::SystemExitException do
+ assert_raises Gem::SystemExitException do
@cmd.execute
end
- assert_equal 0, e.exit_code
ensure
Dir.chdir orig_dir
end
end
out = @ui.output.split "\n"
+ assert_equal "", @ui.error
assert_equal "Successfully installed #{@b2.full_name}", out.shift
assert_equal "1 gem installed", out.shift
assert out.empty?, out.inspect
diff --git a/test/rubygems/test_gem_commands_list_command.rb b/test/rubygems/test_gem_commands_list_command.rb
index 9a56ebc..1339737 100644
--- a/test/rubygems/test_gem_commands_list_command.rb
+++ b/test/rubygems/test_gem_commands_list_command.rb
@@ -26,16 +26,13 @@ class TestGemCommandsListCommand < Gem::TestCase
def test_execute_installed
@cmd.handle_options %w[c --installed]
- e = assert_raises Gem::SystemExitException do
+ assert_raises Gem::MockGemUi::SystemExitException do
use_ui @ui do
@cmd.execute
end
end
- assert_equal 0, e.exit_code
-
assert_equal "true\n", @ui.output
-
assert_equal '', @ui.error
end
diff --git a/test/rubygems/test_gem_commands_outdated_command.rb b/test/rubygems/test_gem_commands_outdated_command.rb
index 632e9a5..ae15efe 100644
--- a/test/rubygems/test_gem_commands_outdated_command.rb
+++ b/test/rubygems/test_gem_commands_outdated_command.rb
@@ -20,24 +20,25 @@ class TestGemCommandsOutdatedCommand < Gem::TestCase
end
def test_execute
- quick_gem 'foo', '0.1'
- quick_gem 'foo', '0.2'
remote_10 = quick_spec 'foo', '1.0'
remote_20 = quick_spec 'foo', '2.0'
- remote_spec_file = File.join @gemhome, 'specifications', remote_10.spec_name
- remote_spec_file = File.join @gemhome, 'specifications', remote_20.spec_name
-
- @fetcher = Gem::FakeFetcher.new
- Gem::RemoteFetcher.fetcher = @fetcher
+ Gem::RemoteFetcher.fetcher = @fetcher = Gem::FakeFetcher.new
+ util_clear_gems
util_setup_spec_fetcher remote_10, remote_20
- use_ui @ui do @cmd.execute end
+ quick_gem 'foo', '0.1'
+ quick_gem 'foo', '0.2'
+
+ Gem::Specification.reset
+
+ use_ui @ui do
+ @cmd.execute
+ end
assert_equal "foo (0.2 < 2.0)\n", @ui.output
assert_equal "", @ui.error
end
-
end
diff --git a/test/rubygems/test_gem_commands_pristine_command.rb b/test/rubygems/test_gem_commands_pristine_command.rb
index 4decdf8..aa1f3bf 100644
--- a/test/rubygems/test_gem_commands_pristine_command.rb
+++ b/test/rubygems/test_gem_commands_pristine_command.rb
@@ -16,8 +16,8 @@ class TestGemCommandsPristineCommand < Gem::TestCase
def test_execute
a = quick_spec 'a' do |s| s.executables = %w[foo] end
- FileUtils.mkdir_p File.join(@tempdir, 'bin')
- File.open File.join(@tempdir, 'bin', 'foo'), 'w' do |fp|
+
+ write_file File.join(@tempdir, 'bin', 'foo') do |fp|
fp.puts "#!/usr/bin/ruby"
end
@@ -25,7 +25,7 @@ class TestGemCommandsPristineCommand < Gem::TestCase
foo_path = File.join @gemhome, 'gems', a.full_name, 'bin', 'foo'
- File.open foo_path, 'w' do |io|
+ write_file foo_path do |io|
io.puts 'I changed it!'
end
@@ -39,15 +39,14 @@ class TestGemCommandsPristineCommand < Gem::TestCase
out = @ui.output.split "\n"
- assert_equal "Restoring gem(s) to pristine condition...", out.shift
+ assert_equal "Restoring gems to pristine condition...", out.shift
assert_equal "Restored #{a.full_name}", out.shift
assert_empty out, out.inspect
end
def test_execute_all
a = quick_spec 'a' do |s| s.executables = %w[foo] end
- FileUtils.mkdir_p File.join(@tempdir, 'bin')
- File.open File.join(@tempdir, 'bin', 'foo'), 'w' do |fp|
+ write_file File.join(@tempdir, 'bin', 'foo') do |fp|
fp.puts "#!/usr/bin/ruby"
end
@@ -67,35 +66,106 @@ class TestGemCommandsPristineCommand < Gem::TestCase
out = @ui.output.split "\n"
- assert_equal "Restoring gem(s) to pristine condition...", out.shift
+ assert_equal "Restoring gems to pristine condition...", out.shift
assert_equal "Restored #{a.full_name}", out.shift
assert_empty out, out.inspect
end
- def test_execute_missing_cache_gem
- a = quick_spec 'a' do |s|
- s.executables = %w[foo]
+ def test_execute_no_exetension
+ a = quick_spec 'a' do |s| s.extensions << 'ext/a/extconf.rb' end
+
+ ext_path = File.join @tempdir, 'ext', 'a', 'extconf.rb'
+ write_file ext_path do |io|
+ io.write '# extconf.rb'
end
- FileUtils.mkdir_p File.join(@tempdir, 'bin')
+ util_build_gem a
- File.open File.join(@tempdir, 'bin', 'foo'), 'w' do |fp|
- fp.puts "#!/usr/bin/ruby"
+ @cmd.options[:args] = %w[a]
+ @cmd.options[:extensions] = false
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ out = @ui.output.split "\n"
+
+ assert_equal 'Restoring gems to pristine condition...', out.shift
+ assert_equal "Skipped #{a.full_name}, it needs to compile an extension",
+ out.shift
+ assert_empty out, out.inspect
+ end
+
+ def test_execute_many
+ a = quick_spec 'a'
+ b = quick_spec 'b'
+
+ install_gem a
+ install_gem b
+
+ @cmd.options[:args] = %w[a b]
+
+ use_ui @ui do
+ @cmd.execute
end
+ out = @ui.output.split "\n"
+
+ assert_equal "Restoring gems to pristine condition...", out.shift
+ assert_equal "Restored #{a.full_name}", out.shift
+ assert_equal "Restored #{b.full_name}", out.shift
+ assert_empty out, out.inspect
+ end
+
+ def test_execute_many_multi_repo
+ a = quick_spec 'a'
install_gem a
- a_data = nil
- open File.join(@gemhome, 'cache', a.file_name), 'rb' do |fp|
- a_data = fp.read
+ Gem.clear_paths
+ gemhome2 = File.join @tempdir, 'gemhome2'
+ Gem.paths = { "GEM_PATH" => [gemhome2, @gemhome], "GEM_HOME" => gemhome2 }
+
+ b = quick_spec 'b'
+ install_gem b
+
+ @cmd.options[:args] = %w[a b]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ out = @ui.output.split "\n"
+
+ assert_equal "Restoring gems to pristine condition...", out.shift
+ assert_equal "Restored #{a.full_name}", out.shift
+ assert_equal "Restored #{b.full_name}", out.shift
+ assert_empty out, out.inspect
+
+ assert_path_exists File.join(@gemhome, "gems", 'a-2')
+ refute_path_exists File.join(gemhome2, "gems", 'a-2')
+ assert_path_exists File.join(gemhome2, "gems", 'b-2')
+ refute_path_exists File.join(@gemhome, "gems", 'b-2')
+ end
+
+ def test_execute_missing_cache_gem
+ a_2 = quick_spec 'a', 2
+ a_3 = quick_spec 'a', 3
+
+ install_gem a_2
+ install_gem a_3
+
+ a_2_data = nil
+ open File.join(@gemhome, 'cache', a_2.file_name), 'rb' do |fp|
+ a_2_data = fp.read
end
util_setup_fake_fetcher
- util_setup_spec_fetcher a
+ util_setup_spec_fetcher a_2
- Gem::RemoteFetcher.fetcher.data["http://gems.example.com/gems/#{a.file_name}"] = a_data
+ url = "http://gems.example.com/gems/#{a_2.file_name}"
+ Gem::RemoteFetcher.fetcher.data[url] = a_2_data
- FileUtils.rm Gem.cache_gem(a.file_name, @gemhome)
+ FileUtils.rm a_2.cache_file
@cmd.options[:args] = %w[a]
@@ -106,11 +176,12 @@ class TestGemCommandsPristineCommand < Gem::TestCase
out = @ui.output.split "\n"
[
- "Restoring gem\(s\) to pristine condition...",
+ "Restoring gems to pristine condition...",
"Restored a-1",
"Cached gem for a-2 not found, attempting to fetch...",
"Restored a-2",
- "Restored a-3.a"
+ "Restored a-3.a",
+ "Restored a-3",
].each do |line|
assert_equal line, out.shift
end
@@ -127,7 +198,7 @@ class TestGemCommandsPristineCommand < Gem::TestCase
end
end
- assert_match %r|specify a gem name|, e.message
+ assert_match %r|at least one gem name|, e.message
end
end
diff --git a/test/rubygems/test_gem_commands_push_command.rb b/test/rubygems/test_gem_commands_push_command.rb
index 917407d..7aa7109 100644
--- a/test/rubygems/test_gem_commands_push_command.rb
+++ b/test/rubygems/test_gem_commands_push_command.rb
@@ -21,7 +21,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
super
@gems_dir = File.join @tempdir, 'gems'
- @cache_dir = Gem.cache_dir @gemhome
+ @cache_dir = File.join @gemhome, "cache"
FileUtils.mkdir @gems_dir
diff --git a/test/rubygems/test_gem_commands_query_command.rb b/test/rubygems/test_gem_commands_query_command.rb
index 91868b8..4f06968 100644
--- a/test/rubygems/test_gem_commands_query_command.rb
+++ b/test/rubygems/test_gem_commands_query_command.rb
@@ -15,8 +15,8 @@ class TestGemCommandsQueryCommand < Gem::TestCase
@cmd = Gem::Commands::QueryCommand.new
util_setup_fake_fetcher
-
- @si = util_setup_spec_fetcher @a1, @a2, @pl1, @a3a
+ util_clear_gems
+ util_setup_spec_fetcher @a1, @a2, @pl1, @a3a
@fetcher.data["#{@gem_repo}Marshal.#{Gem.marshal_version}"] = proc do
raise Gem::RemoteFetcher::FetchError
@@ -48,7 +48,8 @@ pl (1 i386-linux)
@a1.platform = 'x86-linux'
@a2.platform = 'universal-darwin'
- @si = util_setup_spec_fetcher @a1, @a1r, @a2, @b2, @pl1
+ util_clear_gems
+ util_setup_spec_fetcher @a1, @a1r, @a2, @b2, @pl1
@cmd.handle_options %w[-r -a]
@@ -113,7 +114,8 @@ pl (1 i386-linux)
@a2.homepage = 'http://a.example.com/'
@a2.rubyforge_project = 'rubygems'
- @si = util_setup_spec_fetcher @a1, @a2, @pl1
+ util_clear_gems
+ util_setup_spec_fetcher @a1, @a2, @pl1
@cmd.handle_options %w[-r -d]
@@ -154,7 +156,8 @@ pl (1)
@a2.rubyforge_project = 'rubygems'
@a2.platform = 'universal-darwin'
- @si = util_setup_spec_fetcher @a1, @a2, @pl1
+ util_clear_gems
+ util_setup_spec_fetcher @a1, @a2, @pl1
@cmd.handle_options %w[-r -d]
@@ -190,25 +193,22 @@ pl (1)
end
def test_execute_installed
- @cmd.handle_options %w[-n c --installed]
+ @cmd.handle_options %w[-n a --installed]
- e = assert_raises Gem::SystemExitException do
+ assert_raises Gem::MockGemUi::SystemExitException do
use_ui @ui do
@cmd.execute
end
end
- assert_equal 0, e.exit_code
-
assert_equal "true\n", @ui.output
-
assert_equal '', @ui.error
end
def test_execute_installed_no_name
@cmd.handle_options %w[--installed]
- e = assert_raises Gem::SystemExitException do
+ e = assert_raises Gem::MockGemUi::TermError do
use_ui @ui do
@cmd.execute
end
@@ -223,7 +223,7 @@ pl (1)
def test_execute_installed_not_installed
@cmd.handle_options %w[-n not_installed --installed]
- e = assert_raises Gem::SystemExitException do
+ e = assert_raises Gem::MockGemUi::TermError do
use_ui @ui do
@cmd.execute
end
@@ -236,9 +236,9 @@ pl (1)
end
def test_execute_installed_version
- @cmd.handle_options %w[-n c --installed --version 1.2]
+ @cmd.handle_options %w[-n a --installed --version 2]
- e = assert_raises Gem::SystemExitException do
+ assert_raises Gem::MockGemUi::SystemExitException do
use_ui @ui do
@cmd.execute
end
@@ -246,14 +246,12 @@ pl (1)
assert_equal "true\n", @ui.output
assert_equal '', @ui.error
-
- assert_equal 0, e.exit_code
end
def test_execute_installed_version_not_installed
@cmd.handle_options %w[-n c --installed --version 2]
- e = assert_raises Gem::SystemExitException do
+ e = assert_raises Gem::MockGemUi::TermError do
use_ui @ui do
@cmd.execute
end
@@ -265,65 +263,6 @@ pl (1)
assert_equal 1, e.exit_code
end
- def test_execute_local_details
- @a3a.summary = 'This is a lot of text. ' * 4
- @a3a.authors = ['Abraham Lincoln', 'Hirohito']
- @a3a.homepage = 'http://a.example.com/'
- @a3a.rubyforge_project = 'rubygems'
-
- @cmd.handle_options %w[--local --details]
-
- use_ui @ui do
- @cmd.execute
- end
-
- expected = <<-EOF
-
-*** LOCAL GEMS ***
-
-a (3.a, 2, 1)
- Author: A User
- Homepage: http://example.com
- Installed at (3.a): #{@gemhome}
- (2): #{@gemhome}
- (1): #{@gemhome}
-
- this is a summary
-
-a_evil (9)
- Author: A User
- Homepage: http://example.com
- Installed at: #{@gemhome}
-
- this is a summary
-
-b (2)
- Author: A User
- Homepage: http://example.com
- Installed at: #{@gemhome}
-
- this is a summary
-
-c (1.2)
- Author: A User
- Homepage: http://example.com
- Installed at: #{@gemhome}
-
- this is a summary
-
-pl (1)
- Platform: i386-linux
- Author: A User
- Homepage: http://example.com
- Installed at: #{@gemhome}
-
- this is a summary
- EOF
-
- assert_equal expected, @ui.output
- assert_equal '', @ui.error
- end
-
def test_execute_local_notty
@cmd.handle_options %w[]
@@ -335,9 +274,6 @@ pl (1)
expected = <<-EOF
a (3.a, 2, 1)
-a_evil (9)
-b (2)
-c (1.2)
pl (1 i386-linux)
EOF
@@ -412,9 +348,6 @@ a (3.a)
*** LOCAL GEMS ***
a (3.a, 2, 1)
-a_evil (9)
-b (2)
-c (1.2)
pl (1 i386-linux)
EOF
diff --git a/test/rubygems/test_gem_commands_sources_command.rb b/test/rubygems/test_gem_commands_sources_command.rb
index 40449be..7dea797 100644
--- a/test/rubygems/test_gem_commands_sources_command.rb
+++ b/test/rubygems/test_gem_commands_sources_command.rb
@@ -42,12 +42,11 @@ class TestGemCommandsSourcesCommand < Gem::TestCase
def test_execute_add
util_setup_fake_fetcher
- si = Gem::SourceIndex.new
- si.add_spec @a1
+ install_specs @a1
- specs = si.map do |_, spec|
+ specs = Gem::Specification.map { |spec|
[spec.name, spec.version, spec.original_platform]
- end
+ }
specs_dump_gz = StringIO.new
Zlib::GzipWriter.wrap specs_dump_gz do |io|
@@ -187,18 +186,18 @@ beta-gems.example.com is not a URI
@cmd.handle_options %w[--update]
util_setup_fake_fetcher
- source_index = util_setup_spec_fetcher @a1
+ util_setup_spec_fetcher @a1
- specs = source_index.map do |name, spec|
+ specs = Gem::Specification.map { |spec|
[spec.name, spec.version, spec.original_platform]
- end
+ }
@fetcher.data["#{@gem_repo}specs.#{Gem.marshal_version}.gz"] =
util_gzip Marshal.dump(specs)
- latest_specs = source_index.latest_specs.map do |spec|
+ latest_specs = Gem::Specification.latest_specs.map { |spec|
[spec.name, spec.version, spec.original_platform]
- end
+ }
@fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] =
util_gzip Marshal.dump(latest_specs)
diff --git a/test/rubygems/test_gem_commands_specification_command.rb b/test/rubygems/test_gem_commands_specification_command.rb
index 767992f..512b9f5 100644
--- a/test/rubygems/test_gem_commands_specification_command.rb
+++ b/test/rubygems/test_gem_commands_specification_command.rb
@@ -17,7 +17,8 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase
def test_execute
foo = quick_spec 'foo'
- Gem.source_index.add_spec foo
+
+ install_specs foo
@cmd.options[:args] = %w[foo]
@@ -77,8 +78,9 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase
end
def test_execute_field
- foo = quick_spec 'foo'
- Gem.source_index.add_spec foo
+ foo = new_spec 'foo', '2'
+
+ install_specs foo
@cmd.options[:args] = %w[foo name]
@@ -90,8 +92,9 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase
end
def test_execute_marshal
- foo = quick_spec 'foo'
- Gem.source_index.add_spec foo
+ foo = new_spec 'foo', '2'
+
+ install_specs foo
@cmd.options[:args] = %w[foo]
@cmd.options[:format] = :marshal
@@ -127,7 +130,8 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase
def test_execute_ruby
foo = quick_spec 'foo'
- Gem.source_index.add_spec foo
+
+ install_specs foo
@cmd.options[:args] = %w[foo]
@cmd.options[:format] = :ruby
diff --git a/test/rubygems/test_gem_commands_stale_command.rb b/test/rubygems/test_gem_commands_stale_command.rb
index d5aad6c..05cc9d2 100644
--- a/test/rubygems/test_gem_commands_stale_command.rb
+++ b/test/rubygems/test_gem_commands_stale_command.rb
@@ -25,12 +25,12 @@ class TestGemCommandsStaleCommand < Gem::TestCase
end
files.each do |file|
- filename = bar_baz.full_gem_path + "/#{file}"
- FileUtils.mkdir_p(File.dirname(filename))
+ filename = File.join(bar_baz.full_gem_path, file)
+ FileUtils.mkdir_p File.dirname filename
FileUtils.touch(filename, :mtime => Time.now)
- filename = foo_bar.full_gem_path + "/#{file}"
- FileUtils.mkdir_p(File.dirname(filename))
+ filename = File.join(foo_bar.full_gem_path, file)
+ FileUtils.mkdir_p File.dirname filename
FileUtils.touch(filename, :mtime => Time.now - 86400)
end
diff --git a/test/rubygems/test_gem_commands_unpack_command.rb b/test/rubygems/test_gem_commands_unpack_command.rb
index 8764a40..3f07227 100644
--- a/test/rubygems/test_gem_commands_unpack_command.rb
+++ b/test/rubygems/test_gem_commands_unpack_command.rb
@@ -21,20 +21,20 @@ class TestGemCommandsUnpackCommand < Gem::TestCase
util_make_gems
assert_equal(
- @cmd.find_in_cache(@a1.file_name),
- Gem.cache_gem(@a1.file_name, @gemhome),
+ @cmd.find_in_cache(File.basename @a1.cache_file),
+ @a1.cache_file,
'found a-1.gem in the cache'
)
end
def test_get_path
- util_make_gems
util_setup_fake_fetcher
+ util_clear_gems
util_setup_spec_fetcher @a1
a1_data = nil
- open Gem.cache_gem(@a1.file_name, @gemhome), 'rb' do |fp|
+ open @a1.cache_file, 'rb' do |fp|
a1_data = fp.read
end
@@ -44,15 +44,15 @@ class TestGemCommandsUnpackCommand < Gem::TestCase
dep = Gem::Dependency.new(@a1.name, @a1.version)
assert_equal(
@cmd.get_path(dep),
- Gem.cache_gem(@a1.file_name, @gemhome),
+ @a1.cache_file,
'fetches a-1 and returns the cache path'
)
- FileUtils.rm Gem.cache_gem(@a1.file_name, @gemhome)
+ FileUtils.rm @a1.cache_file
assert_equal(
@cmd.get_path(dep),
- Gem.cache_gem(@a1.file_name, @gemhome),
+ @a1.cache_file,
'when removed from cache, refetches a-1'
)
end
@@ -73,16 +73,14 @@ class TestGemCommandsUnpackCommand < Gem::TestCase
end
def test_execute_gem_path
- util_make_gems
- util_setup_spec_fetcher
util_setup_fake_fetcher
+ util_setup_spec_fetcher
Gem.clear_paths
gemhome2 = File.join @tempdir, 'gemhome2'
- Gem.send :set_paths, [gemhome2, @gemhome].join(File::PATH_SEPARATOR)
- Gem.send :set_home, gemhome2
+ Gem.paths = { "GEM_PATH" => [gemhome2, @gemhome], "GEM_HOME" => gemhome2 }
@cmd.options[:args] = %w[a]
@@ -96,15 +94,14 @@ class TestGemCommandsUnpackCommand < Gem::TestCase
end
def test_execute_gem_path_missing
- util_make_gems
+ util_setup_fake_fetcher
util_setup_spec_fetcher
Gem.clear_paths
gemhome2 = File.join @tempdir, 'gemhome2'
- Gem.send :set_paths, [gemhome2, @gemhome].join(File::PATH_SEPARATOR)
- Gem.send :set_home, gemhome2
+ Gem.paths = { "GEM_PATH" => [gemhome2, @gemhome], "GEM_HOME" => gemhome2 }
@cmd.options[:args] = %w[z]
@@ -123,7 +120,7 @@ class TestGemCommandsUnpackCommand < Gem::TestCase
util_clear_gems
a2_data = nil
- open Gem.cache_gem(@a2.file_name, @gemhome), 'rb' do |fp|
+ open @a2.cache_file, 'rb' do |fp|
a2_data = fp.read
end
@@ -142,10 +139,28 @@ class TestGemCommandsUnpackCommand < Gem::TestCase
assert File.exist?(File.join(@tempdir, 'a-2')), 'a should be unpacked'
end
+ def test_execute_spec
+ util_make_gems
+
+ @cmd.options[:args] = %w[a b]
+ @cmd.options[:spec] = true
+
+ use_ui @ui do
+ Dir.chdir @tempdir do
+ @cmd.execute
+ end
+ end
+
+ assert File.exist?(File.join(@tempdir, 'a-3.a.gemspec'))
+ assert File.exist?(File.join(@tempdir, 'b-2.gemspec'))
+ end
+
def test_execute_sudo
+ skip 'Cannot perform this test on windows (chmod)' if win_platform?
+
util_make_gems
- File.chmod 0555, @gemhome
+ FileUtils.chmod 0555, @gemhome
@cmd.options[:args] = %w[b]
@@ -157,7 +172,7 @@ class TestGemCommandsUnpackCommand < Gem::TestCase
assert File.exist?(File.join(@tempdir, 'b-2')), 'b should be unpacked'
ensure
- File.chmod 0755, @gemhome
+ FileUtils.chmod 0755, @gemhome
end
def test_execute_with_target_option
@@ -203,5 +218,13 @@ class TestGemCommandsUnpackCommand < Gem::TestCase
assert File.exist?(File.join(@tempdir, foo_spec.full_name))
end
+ def test_handle_options_metadata
+ refute @cmd.options[:spec]
+
+ @cmd.send :handle_options, %w[--spec a]
+
+ assert @cmd.options[:spec]
+ end
+
end
diff --git a/test/rubygems/test_gem_commands_update_command.rb b/test/rubygems/test_gem_commands_update_command.rb
index 24966a3..b43be11 100644
--- a/test/rubygems/test_gem_commands_update_command.rb
+++ b/test/rubygems/test_gem_commands_update_command.rb
@@ -24,15 +24,15 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
@cmd.options[:generate_ri] = false
util_setup_fake_fetcher
-
- @a1_path = Gem.cache_gem(@a1.file_name, @gemhome)
- @a2_path = Gem.cache_gem(@a2.file_name, @gemhome)
-
+ util_clear_gems
util_setup_spec_fetcher @a1, @a2
- @fetcher.data["#{@gem_repo}gems/#{@a1.file_name}"] =
+ @a1_path = @a1.cache_file
+ @a2_path = @a2.cache_file
+
+ @fetcher.data["#{@gem_repo}gems/#{File.basename @a1_path}"] =
read_binary @a1_path
- @fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] =
+ @fetcher.data["#{@gem_repo}gems/#{File.basename @a2_path}"] =
read_binary @a2_path
end
@@ -81,18 +81,19 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
def util_add_to_fetcher *specs
specs.each do |spec|
- gem_file = Gem.cache_gem(spec.file_name, @gemhome)
+ gem_file = spec.cache_file
+ file_name = File.basename gem_file
- @fetcher.data["http://gems.example.com/gems/#{spec.file_name}"] =
+ @fetcher.data["http://gems.example.com/gems/#{file_name}"] =
Gem.read_binary gem_file
end
end
def test_execute_system
+ util_clear_gems
util_setup_rubygem9
util_setup_spec_fetcher @rubygem9
util_add_to_fetcher @rubygem9
- util_clear_gems
@cmd.options[:args] = []
@cmd.options[:system] = true
@@ -113,17 +114,17 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
end
def test_execute_system_at_latest
+ util_clear_gems
util_setup_rubygem_current
util_setup_spec_fetcher @rubygem_current
util_add_to_fetcher @rubygem_current
- util_clear_gems
@cmd.options[:args] = []
@cmd.options[:system] = true
@cmd.options[:generate_rdoc] = false
@cmd.options[:generate_ri] = false
- assert_raises Gem::SystemExitException do
+ assert_raises Gem::MockGemUi::SystemExitException do
use_ui @ui do
@cmd.execute
end
@@ -135,11 +136,11 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
end
def test_execute_system_multiple
+ util_clear_gems
util_setup_rubygem9
util_setup_rubygem8
util_setup_spec_fetcher @rubygem8, @rubygem9
util_add_to_fetcher @rubygem8, @rubygem9
- util_clear_gems
@cmd.options[:args] = []
@cmd.options[:system] = true
@@ -184,6 +185,31 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
assert_empty out
end
+ def test_execute_system_specifically_to_latest_version
+ util_clear_gems
+ util_setup_rubygem9
+ util_setup_rubygem8
+ util_setup_spec_fetcher @rubygem8, @rubygem9
+ util_add_to_fetcher @rubygem8, @rubygem9
+
+ @cmd.options[:args] = []
+ @cmd.options[:system] = "9"
+ @cmd.options[:generate_rdoc] = false
+ @cmd.options[:generate_ri] = false
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ out = @ui.output.split "\n"
+ assert_equal "Updating rubygems-update", out.shift
+ assert_equal "Successfully installed rubygems-update-9", out.shift
+ assert_equal "Installing RubyGems 9", out.shift
+ assert_equal "RubyGems system software updated", out.shift
+
+ assert_empty out
+ end
+
def test_execute_system_with_gems
@cmd.options[:args] = %w[gem]
@cmd.options[:system] = true
@@ -218,16 +244,11 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
@a2.add_dependency 'c', '2'
@a2.add_dependency 'b', '2'
- @b2_path = Gem.cache_gem(@b2.file_name, @gemhome)
- @c1_2_path = Gem.cache_gem(@c1_2.file_name, @gemhome)
- @c2_path = Gem.cache_gem(@c2.file_name, @gemhome)
+ @b2_path = @b2.cache_file
+ @c1_2_path = @c1_2.cache_file
+ @c2_path = @c2.cache_file
- @source_index = Gem::SourceIndex.new
- @source_index.add_spec @a1
- @source_index.add_spec @a2
- @source_index.add_spec @b2
- @source_index.add_spec @c1_2
- @source_index.add_spec @c2
+ install_specs @a1, @a2, @b2, @c1_2, @c2
util_build_gem @a1
util_build_gem @a2
@@ -236,16 +257,16 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
@fetcher.data["#{@gem_repo}gems/#{@a1.file_name}"] = read_binary @a1_path
@fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] = read_binary @a2_path
@fetcher.data["#{@gem_repo}gems/#{@b2.file_name}"] = read_binary @b2_path
- @fetcher.data["#{@gem_repo}gems/#{@c1_2.file_name}"] =
- read_binary @c1_2_path
+ @fetcher.data["#{@gem_repo}gems/#{@c1_2.file_name}"] = read_binary @c1_2_path
@fetcher.data["#{@gem_repo}gems/#{@c2.file_name}"] = read_binary @c2_path
util_setup_spec_fetcher @a1, @a2, @b2, @c1_2, @c2
- util_clear_gems
Gem::Installer.new(@c1_2_path).install
Gem::Installer.new(@a1_path).install
+ Gem::Specification.reset
+
@cmd.options[:args] = []
use_ui @ui do
diff --git a/test/rubygems/test_gem_commands_which_command.rb b/test/rubygems/test_gem_commands_which_command.rb
index 8f9a292..7a21f7c 100644
--- a/test/rubygems/test_gem_commands_which_command.rb
+++ b/test/rubygems/test_gem_commands_which_command.rb
@@ -11,6 +11,7 @@ class TestGemCommandsWhichCommand < Gem::TestCase
def setup
super
+ Gem::Specification.reset
@cmd = Gem::Commands::WhichCommand.new
end
@@ -28,6 +29,8 @@ class TestGemCommandsWhichCommand < Gem::TestCase
end
def test_execute_one_missing
+ # TODO: this test fails in isolation
+
util_foo_bar
@cmd.handle_options %w[foo_bar missing]
@@ -37,7 +40,7 @@ class TestGemCommandsWhichCommand < Gem::TestCase
end
assert_equal "#{@foo_bar.full_gem_path}/lib/foo_bar.rb\n", @ui.output
- assert_match %r%Can't find ruby library file or shared library missing\n%,
+ assert_match %r%Can.t find ruby library file or shared library missing\n%,
@ui.error
end
@@ -51,7 +54,7 @@ class TestGemCommandsWhichCommand < Gem::TestCase
end
assert_equal '', @ui.output
- assert_match %r%Can't find ruby library file or shared library missing\n%,
+ assert_match %r%Can.t find ruby library file or shared library missing\n%,
@ui.error
end
@@ -62,8 +65,8 @@ class TestGemCommandsWhichCommand < Gem::TestCase
end
files.each do |file|
- filename = @foo_bar.full_gem_path + "/#{file}"
- FileUtils.mkdir_p File.dirname(filename)
+ filename = File.join(@foo_bar.full_gem_path, file)
+ FileUtils.mkdir_p File.dirname filename
FileUtils.touch filename
end
end
diff --git a/test/rubygems/test_gem_dependency.rb b/test/rubygems/test_gem_dependency.rb
index b4a21b8..a77ddf5 100644
--- a/test/rubygems/test_gem_dependency.rb
+++ b/test/rubygems/test_gem_dependency.rb
@@ -67,16 +67,20 @@ class TestGemDependency < Gem::TestCase
assert_match d, d, "match self"
assert_match dep("a", ">= 0"), d, "match version exact"
assert_match dep("a", ">= 0"), dep("a", "1"), "match version"
- assert_match dep(/a/, ">= 0"), d, "match simple regexp"
- assert_match dep(/a|b/, ">= 0"), d, "match scary regexp"
-
- refute_match dep(/a/), dep("b")
refute_match dep("a"), Object.new
+
+ Deprecate.skip_during do
+ assert_match dep(/a/, ">= 0"), d, "match simple regexp"
+ assert_match dep(/a|b/, ">= 0"), d, "match scary regexp"
+ refute_match dep(/a/), dep("b")
+ end
end
def test_equals_tilde_escape
refute_match dep("a|b"), dep("a", "1")
- assert_match dep(/a|b/), dep("a", "1")
+ Deprecate.skip_during do
+ assert_match dep(/a|b/), dep("a", "1")
+ end
end
def test_equals_tilde_object
@@ -90,9 +94,11 @@ class TestGemDependency < Gem::TestCase
def test_equals_tilde_spec
assert_match dep("a", ">= 0"), spec("a", "0")
assert_match dep("a", "1"), spec("a", "1")
- assert_match dep(/a/, ">= 0"), spec("a", "0")
- assert_match dep(/a|b/, ">= 0"), spec("b", "0")
- refute_match dep(/a/, ">= 0"), spec("b", "0")
+ Deprecate.skip_during do
+ assert_match dep(/a/, ">= 0"), spec("a", "0")
+ assert_match dep(/a|b/, ">= 0"), spec("b", "0")
+ refute_match dep(/a/, ">= 0"), spec("b", "0")
+ end
end
def test_hash
@@ -166,5 +172,12 @@ class TestGemDependency < Gem::TestCase
assert d.prerelease?
end
+
+ def test_specific
+ refute dep('a', '> 1').specific?
+
+ assert dep('a', '= 1').specific?
+ end
+
end
diff --git a/test/rubygems/test_gem_dependency_installer.rb b/test/rubygems/test_gem_dependency_installer.rb
index 5cf79d3..48d85b8 100644
--- a/test/rubygems/test_gem_dependency_installer.rb
+++ b/test/rubygems/test_gem_dependency_installer.rb
@@ -14,10 +14,14 @@ class TestGemDependencyInstaller < Gem::TestCase
super
@gems_dir = File.join @tempdir, 'gems'
- @cache_dir = Gem.cache_dir(@gemhome)
+ @cache_dir = File.join @gemhome, 'cache'
FileUtils.mkdir @gems_dir
+ Gem::RemoteFetcher.fetcher = @fetcher = Gem::FakeFetcher.new
+ end
+
+ def util_setup_gems
@a1, @a1_gem = util_gem 'a', '1' do |s| s.executables << 'a_bin' end
@a1_pre, @a1_pre_gem = util_gem 'a', '1.a'
@b1, @b1_gem = util_gem 'b', '1' do |s|
@@ -25,12 +29,13 @@ class TestGemDependencyInstaller < Gem::TestCase
s.add_development_dependency 'aa'
end
- Gem::RemoteFetcher.fetcher = @fetcher = Gem::FakeFetcher.new
-
+ util_clear_gems
util_reset_gems
end
def test_install
+ util_setup_gems
+
FileUtils.mv @a1_gem, @tempdir
inst = nil
@@ -39,13 +44,13 @@ class TestGemDependencyInstaller < Gem::TestCase
inst.install 'a'
end
- assert_equal Gem::SourceIndex.new(@a1.full_name => @a1),
- Gem::SourceIndex.from_installed_gems
-
+ assert_equal %w[a-1], Gem::Specification.map(&:full_name)
assert_equal [@a1], inst.installed_gems
end
def test_install_all_dependencies
+ util_setup_gems
+
_, e1_gem = util_gem 'e', '1' do |s|
s.add_dependency 'b'
end
@@ -71,6 +76,8 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_install_cache_dir
+ util_setup_gems
+
FileUtils.mv @a1_gem, @tempdir
FileUtils.mv @b1_gem, @tempdir
inst = nil
@@ -82,15 +89,18 @@ class TestGemDependencyInstaller < Gem::TestCase
assert_equal %w[a-1 b-1], inst.installed_gems.map { |s| s.full_name }
- assert Gem.cache_gem(@a1.file_name, @gemhome)
- assert Gem.cache_gem(@b1.file_name, @gemhome)
+ assert File.exist? File.join(@gemhome, "cache", @a1.file_name)
+ assert File.exist? File.join(@gemhome, "cache", @b1.file_name)
end
def test_install_dependencies_satisfied
+ util_setup_gems
+
a2, a2_gem = util_gem 'a', '2'
FileUtils.rm_rf File.join(@gemhome, 'gems')
- Gem.source_index.refresh!
+
+ Gem::Specification.reset
FileUtils.mv @a1_gem, @tempdir
FileUtils.mv a2_gem, @tempdir # not in index
@@ -109,14 +119,13 @@ class TestGemDependencyInstaller < Gem::TestCase
inst.install 'b'
end
- installed = Gem::SourceIndex.from_installed_gems.map { |n,s| s.full_name }
-
- assert_equal %w[a-2 b-1], installed.sort
-
+ assert_equal %w[a-2 b-1], Gem::Specification.map(&:full_name)
assert_equal %w[b-1], inst.installed_gems.map { |s| s.full_name }
end
def test_install_dependency
+ util_setup_gems
+
FileUtils.mv @a1_gem, @tempdir
FileUtils.mv @b1_gem, @tempdir
inst = nil
@@ -130,6 +139,8 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_install_dependency_development
+ util_setup_gems
+
@aa1, @aa1_gem = util_gem 'aa', '1'
util_reset_gems
@@ -148,6 +159,8 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_install_dependency_existing
+ util_setup_gems
+
Gem::Installer.new(@a1_gem).install
FileUtils.mv @a1_gem, @tempdir
FileUtils.mv @b1_gem, @tempdir
@@ -180,6 +193,8 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_install_local
+ util_setup_gems
+
FileUtils.mv @a1_gem, @tempdir
inst = nil
@@ -192,6 +207,8 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_install_local_dependency
+ util_setup_gems
+
FileUtils.mv @a1_gem, @tempdir
FileUtils.mv @b1_gem, @tempdir
@@ -206,6 +223,8 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_install_local_dependency_installed
+ util_setup_gems
+
FileUtils.mv @a1_gem, @tempdir
FileUtils.mv @b1_gem, @tempdir
@@ -222,6 +241,8 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_install_local_subdir
+ util_setup_gems
+
inst = nil
Dir.chdir @tempdir do
@@ -233,11 +254,13 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_install_env_shebang
+ util_setup_gems
+
FileUtils.mv @a1_gem, @tempdir
inst = nil
Dir.chdir @tempdir do
- inst = Gem::DependencyInstaller.new :env_shebang => true, :wrappers => true
+ inst = Gem::DependencyInstaller.new :env_shebang => true, :wrappers => true, :format_executable => false
inst.install 'a'
end
@@ -248,6 +271,8 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_install_force
+ util_setup_gems
+
FileUtils.mv @b1_gem, @tempdir
si = util_setup_spec_fetcher @b1
@fetcher.data['http://gems.example.com/gems/yaml'] = si.to_yaml
@@ -262,6 +287,8 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_install_ignore_dependencies
+ util_setup_gems
+
FileUtils.mv @b1_gem, @tempdir
inst = nil
@@ -274,6 +301,8 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_install_install_dir
+ util_setup_gems
+
FileUtils.mv @a1_gem, @tempdir
gemhome2 = File.join @tempdir, 'gemhome2'
Dir.mkdir gemhome2
@@ -287,10 +316,12 @@ class TestGemDependencyInstaller < Gem::TestCase
assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name }
assert File.exist?(File.join(gemhome2, 'specifications', @a1.spec_name))
- assert File.exist?(Gem.cache_gem(@a1.file_name, gemhome2))
+ assert File.exist?(File.join(gemhome2, 'cache', @a1.file_name))
end
def test_install_domain_both
+ util_setup_gems
+
a1_data = nil
File.open @a1_gem, 'rb' do |fp|
a1_data = fp.read
@@ -309,14 +340,13 @@ class TestGemDependencyInstaller < Gem::TestCase
assert_equal %w[a-1 b-1], inst.installed_gems.map { |s| s.full_name }
a1, b1 = inst.installed_gems
- a1_expected = File.join(@gemhome, 'specifications', a1.spec_name)
- b1_expected = File.join(@gemhome, 'specifications', b1.spec_name)
-
- assert_equal a1_expected, a1.loaded_from
- assert_equal b1_expected, b1.loaded_from
+ assert_equal a1.spec_file, a1.loaded_from
+ assert_equal b1.spec_file, b1.loaded_from
end
def test_install_domain_both_no_network
+ util_setup_gems
+
@fetcher.data["http://gems.example.com/gems/Marshal.#{@marshal_version}"] =
proc do
raise Gem::RemoteFetcher::FetchError
@@ -335,12 +365,11 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_install_domain_local
+ util_setup_gems
+
FileUtils.mv @b1_gem, @tempdir
inst = nil
- Gem.source_index.remove_spec @a1.full_name
- Gem.source_index.remove_spec @a1_pre.full_name
-
Dir.chdir @tempdir do
e = assert_raises Gem::DependencyError do
inst = Gem::DependencyInstaller.new :domain => :local
@@ -355,6 +384,8 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_install_domain_remote
+ util_setup_gems
+
a1_data = nil
File.open @a1_gem, 'rb' do |fp|
a1_data = fp.read
@@ -369,6 +400,8 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_install_dual_repository
+ util_setup_gems
+
FileUtils.mv @a1_gem, @tempdir
FileUtils.mv @b1_gem, @tempdir
inst = nil
@@ -393,6 +426,8 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_install_reinstall
+ util_setup_gems
+
Gem::Installer.new(@a1_gem).install
FileUtils.mv @a1_gem, @tempdir
inst = nil
@@ -402,13 +437,13 @@ class TestGemDependencyInstaller < Gem::TestCase
inst.install 'a'
end
- assert_equal Gem::SourceIndex.new(@a1.full_name => @a1),
- Gem::SourceIndex.from_installed_gems
-
- assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name }
+ assert_equal %w[a-1], Gem::Specification.map(&:full_name)
+ assert_equal %w[a-1], inst.installed_gems.map(&:full_name)
end
def test_install_remote
+ util_setup_gems
+
a1_data = nil
File.open @a1_gem, 'rb' do |fp|
a1_data = fp.read
@@ -426,6 +461,8 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_install_remote_dep
+ util_setup_gems
+
a1_data = nil
File.open @a1_gem, 'rb' do |fp|
a1_data = fp.read
@@ -444,6 +481,8 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_install_remote_platform_newer
+ util_setup_gems
+
a2_o, a2_o_gem = util_gem 'a', '2' do |s|
s.platform = Gem::Platform.new %w[cpu other_platform 1]
end
@@ -473,6 +512,8 @@ class TestGemDependencyInstaller < Gem::TestCase
if defined? OpenSSL then
def test_install_security_policy
+ util_setup_gems
+
data = File.open(@a1_gem, 'rb') { |f| f.read }
@fetcher.data['http://gems.example.com/gems/a-1.gem'] = data
@@ -495,9 +536,11 @@ class TestGemDependencyInstaller < Gem::TestCase
# Wrappers don't work on mswin
unless win_platform? then
def test_install_no_wrappers
+ util_setup_gems
+
@fetcher.data['http://gems.example.com/gems/a-1.gem'] = read_binary(@a1_gem)
- inst = Gem::DependencyInstaller.new :wrappers => false
+ inst = Gem::DependencyInstaller.new :wrappers => false, :format_executable => false
inst.install 'a'
refute_match(%r|This file was generated by RubyGems.|,
@@ -537,14 +580,19 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_find_gems_gems_with_sources
+ util_setup_gems
+
inst = Gem::DependencyInstaller.new
dep = Gem::Dependency.new 'b', '>= 0'
- assert_equal [[@b1, @gem_repo]],
- inst.find_gems_with_sources(dep)
+ Gem::Specification.reset
+
+ assert_equal [[@b1, @gem_repo]], inst.find_gems_with_sources(dep)
end
def test_find_gems_with_sources_local
+ util_setup_gems
+
FileUtils.mv @a1_gem, @tempdir
inst = Gem::DependencyInstaller.new
dep = Gem::Dependency.new 'a', '>= 0'
@@ -566,6 +614,8 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_find_gems_with_sources_prerelease
+ util_setup_gems
+
installer = Gem::DependencyInstaller.new
dependency = Gem::Dependency.new('a', Gem::Requirement.default)
@@ -586,8 +636,8 @@ class TestGemDependencyInstaller < Gem::TestCase
def assert_resolve expected, *specs
util_clear_gems
-
util_setup_spec_fetcher(*specs)
+ Gem::Specification.reset
inst = Gem::DependencyInstaller.new
inst.find_spec_by_name_and_version specs.first.name
@@ -601,6 +651,7 @@ class TestGemDependencyInstaller < Gem::TestCase
util_clear_gems
util_setup_spec_fetcher(*specs)
+ Gem::Specification.reset
spec = specs.first
@@ -613,6 +664,9 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_gather_dependencies
+ util_setup_gems
+ util_reset_gems
+
inst = Gem::DependencyInstaller.new
inst.find_spec_by_name_and_version 'b'
inst.gather_dependencies
@@ -725,6 +779,7 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def test_gather_dependencies_prerelease
+ util_setup_gems
util_setup_c1_pre
assert_resolve_pre %w[a-1.a b-1 c-1.a], @c1_pre, @a1_pre, @b1
@@ -782,6 +837,9 @@ class TestGemDependencyInstaller < Gem::TestCase
end
def util_reset_gems
+ @a1 ||= nil
+ @b1 ||= nil
+ @a1_pre ||= nil
@c1_pre ||= nil
@d1 ||= nil
@d2 ||= nil
diff --git a/test/rubygems/test_gem_dependency_list.rb b/test/rubygems/test_gem_dependency_list.rb
index 4201a31..348f111 100644
--- a/test/rubygems/test_gem_dependency_list.rb
+++ b/test/rubygems/test_gem_dependency_list.rb
@@ -12,8 +12,11 @@ class TestGemDependencyList < Gem::TestCase
def setup
super
+ util_clear_gems
+
@deplist = Gem::DependencyList.new
+ # TODO: switch to new_spec
@a1 = quick_spec 'a', '1'
@a2 = quick_spec 'a', '2'
@a3 = quick_spec 'a', '3'
@@ -28,13 +31,10 @@ class TestGemDependencyList < Gem::TestCase
end
def test_self_from_source_index
- hash = {
- 'a-1' => @a1,
- 'b-2' => @b2,
- }
+ util_clear_gems
+ install_specs @a1, @b2
- si = Gem::SourceIndex.new hash
- deps = Gem::DependencyList.from_source_index si
+ deps = Deprecate.skip_during { Gem::DependencyList.from_source_index }
assert_equal %w[b-2 a-1], deps.dependency_order.map { |s| s.full_name }
end
diff --git a/test/rubygems/test_gem_doc_manager.rb b/test/rubygems/test_gem_doc_manager.rb
index f52f1f8..f7ab641 100644
--- a/test/rubygems/test_gem_doc_manager.rb
+++ b/test/rubygems/test_gem_doc_manager.rb
@@ -17,21 +17,21 @@ class TestGemDocManager < Gem::TestCase
end
def test_uninstall_doc_unwritable
- path = @spec.installation_path
+ path = @spec.base_dir
orig_mode = File.stat(path).mode
# File.chmod has no effect on MS Windows directories (it needs ACL).
if win_platform?
skip("test_uninstall_doc_unwritable skipped on MS Windows")
else
- File.chmod 0000, path
+ FileUtils.chmod 0000, path
end
assert_raises Gem::FilePermissionError do
@manager.uninstall_doc
end
ensure
- File.chmod orig_mode, path
+ FileUtils.chmod orig_mode, path
end
end
diff --git a/test/rubygems/test_gem_format.rb b/test/rubygems/test_gem_format.rb
index 6f16958..85fb521 100644
--- a/test/rubygems/test_gem_format.rb
+++ b/test/rubygems/test_gem_format.rb
@@ -20,7 +20,7 @@ class TestGemFormat < Gem::Package::TarTestCase
def test_class_from_file_by_path
util_make_gems
- gems = Dir[Gem.cache_gem('*.gem', @gemhome)]
+ gems = Dir[File.join(@gemhome, "cache", "*.gem")]
names = [@a1, @a2, @a3a, @a_evil9, @b2, @c1_2, @pl1].map do |spec|
spec.original_name
diff --git a/test/rubygems/test_gem_gem_path_searcher.rb b/test/rubygems/test_gem_gem_path_searcher.rb
index cb4516e..c7f5af7 100644
--- a/test/rubygems/test_gem_gem_path_searcher.rb
+++ b/test/rubygems/test_gem_gem_path_searcher.rb
@@ -13,72 +13,88 @@ class Gem::GemPathSearcher
end
class TestGemGemPathSearcher < Gem::TestCase
-
def setup
super
- @foo1 = quick_gem 'foo', '0.1' do |s|
- s.require_paths << 'lib2'
- s.files << 'lib/foo.rb'
- end
-
+ @foo1 = new_spec 'foo', '0.1', nil, "lib/foo.rb"
+ @foo1.require_paths << 'lib2'
path = File.join 'gems', @foo1.full_name, 'lib', 'foo.rb'
write_file(path) { |fp| fp.puts "# #{path}" }
- @foo2 = quick_gem 'foo', '0.2'
- @bar1 = quick_gem 'bar', '0.1'
- @bar2 = quick_gem 'bar', '0.2'
- @nrp = quick_gem 'nil_require_paths', '0.1'
- @nrp.require_paths = nil
+ @foo2 = new_spec 'foo', '0.2'
+ @bar1 = new_spec 'bar', '0.1'
+ @bar2 = new_spec 'bar', '0.2'
+ @nrp = new_spec 'nil_require_paths', '0.1' do |s|
+ s.require_paths = nil
+ end
+ util_setup_fake_fetcher
+ Gem::Specification.reset
+ util_setup_spec_fetcher @foo1, @foo2, @bar1, @bar2
@fetcher = Gem::FakeFetcher.new
Gem::RemoteFetcher.fetcher = @fetcher
- Gem.source_index = util_setup_spec_fetcher @foo1, @foo2, @bar1, @bar2
-
- @gps = Gem::GemPathSearcher.new
+ @gps = Deprecate.skip_during { Gem::GemPathSearcher.new }
end
def test_find
- assert_equal @foo1, @gps.find('foo')
+ Deprecate.skip_during do
+ assert_equal @foo1, @gps.find('foo')
+ end
end
def test_find_all
- assert_equal [@foo1], @gps.find_all('foo')
+ Deprecate.skip_during do
+ assert_equal [@foo1], @gps.find_all('foo')
+ end
end
def test_init_gemspecs
- assert_equal [@bar2, @bar1, @foo2, @foo1], @gps.init_gemspecs
+ Deprecate.skip_during do
+ util_clear_gems
+ util_setup_spec_fetcher @foo1, @foo2, @bar1, @bar2
+ expected = [@bar2, @bar1, @foo2, @foo1].map(&:full_name)
+ actual = @gps.init_gemspecs.map(&:full_name)
+ assert_equal expected, actual
+ end
end
def test_lib_dirs_for
- lib_dirs = @gps.lib_dirs_for(@foo1)
- expected = File.join @gemhome, 'gems', @foo1.full_name, '{lib,lib2}'
+ Deprecate.skip_during do
+ lib_dirs = @gps.lib_dirs_for(@foo1)
+ expected = File.join @gemhome, 'gems', @foo1.full_name, '{lib,lib2}'
- assert_equal expected, lib_dirs
+ assert_equal expected, lib_dirs
+ end
end
def test_lib_dirs_for_nil_require_paths
- assert_nil @gps.lib_dirs_for(@nrp)
+ Deprecate.skip_during do
+ assert_nil @gps.lib_dirs_for(@nrp)
+ end
end
def test_matching_file_eh
- refute @gps.matching_file?(@foo1, 'bar')
- assert @gps.matching_file?(@foo1, 'foo')
+ Deprecate.skip_during do
+ refute @gps.matching_file?(@foo1, 'bar')
+ assert @gps.matching_file?(@foo1, 'foo')
+ end
end
def test_matching_files
- assert_equal [], @gps.matching_files(@foo1, 'bar')
+ Deprecate.skip_during do
+ assert_equal [], @gps.matching_files(@foo1, 'bar')
- expected = File.join @foo1.full_gem_path, 'lib', 'foo.rb'
+ expected = File.join @foo1.full_gem_path, 'lib', 'foo.rb'
- assert_equal [expected], @gps.matching_files(@foo1, 'foo')
+ assert_equal [expected], @gps.matching_files(@foo1, 'foo')
+ end
end
def test_matching_files_nil_require_paths
- assert_empty @gps.matching_files(@nrp, 'foo')
+ Deprecate.skip_during do
+ assert_empty @gps.matching_files(@nrp, 'foo')
+ end
end
-
end
-
diff --git a/test/rubygems/test_gem_gem_runner.rb b/test/rubygems/test_gem_gem_runner.rb
index 177c715..3cb8410 100644
--- a/test/rubygems/test_gem_gem_runner.rb
+++ b/test/rubygems/test_gem_gem_runner.rb
@@ -39,10 +39,7 @@ class TestGemGemRunner < Gem::TestCase
def test_build_args__are_handled
Gem.clear_paths
- gr = Gem::GemRunner.new
- assert_raises(Gem::SystemExitException) do
- gr.run(%W[--help -- --build_arg1 --build_arg2])
- end
+ Gem::GemRunner.new.run(%W[help -- --build_arg1 --build_arg2])
assert_equal %w[--build_arg1 --build_arg2], Gem::Command.build_args
end
diff --git a/test/rubygems/test_gem_indexer.rb b/test/rubygems/test_gem_indexer.rb
index e3c78ec..a4f9bd4 100644
--- a/test/rubygems/test_gem_indexer.rb
+++ b/test/rubygems/test_gem_indexer.rb
@@ -16,6 +16,7 @@ class TestGemIndexer < Gem::TestCase
def setup
super
+ util_clear_gems
util_make_gems
@d2_0 = quick_spec 'd', '2.0' do |s|
@@ -33,11 +34,12 @@ class TestGemIndexer < Gem::TestCase
gems = File.join(@tempdir, 'gems')
FileUtils.mkdir_p gems
- FileUtils.mv Dir[Gem.cache_gem('*.gem', @gemhome)], gems
+ FileUtils.mv Dir[File.join(@gemhome, "cache", '*.gem')], gems
- @indexer = Gem::Indexer.new @tempdir, :rss_title => 'ExampleForge gems',
- :rss_host => 'example.com',
- :rss_gems_host => 'gems.example.com'
+ @indexer = Gem::Indexer.new(@tempdir,
+ :rss_title => 'ExampleForge gems',
+ :rss_host => 'example.com',
+ :rss_gems_host => 'gems.example.com')
end
def test_initialize
@@ -61,36 +63,37 @@ class TestGemIndexer < Gem::TestCase
end
def test_build_indicies
- spec = quick_spec 'd', '2.0'
- spec.instance_variable_set :@original_platform, ''
-
@indexer.make_temp_directories
- index = Gem::SourceIndex.new
- index.add_spec spec
-
use_ui @ui do
- @indexer.build_indicies index
+ @indexer.build_indicies
end
specs_path = File.join @indexer.directory, "specs.#{@marshal_version}"
specs_dump = Gem.read_binary specs_path
specs = Marshal.load specs_dump
- expected = [
- ['d', Gem::Version.new('2.0'), 'ruby'],
- ]
+ expected = [["a", Gem::Version.new("1"), "ruby"],
+ ["a", Gem::Version.new("2"), "ruby"],
+ ["a_evil", Gem::Version.new("9"), "ruby"],
+ ["b", Gem::Version.new("2"), "ruby"],
+ ["c", Gem::Version.new("1.2"), "ruby"],
+ ["d", Gem::Version.new("2.0"), "ruby"],
+ ["pl", Gem::Version.new("1"), "i386-linux"]]
- assert_equal expected, specs, 'specs'
+ assert_equal expected, specs
- latest_specs_path = File.join @indexer.directory,
- "latest_specs.#{@marshal_version}"
+ latest_specs_path = File.join(@indexer.directory,
+ "latest_specs.#{@marshal_version}")
latest_specs_dump = Gem.read_binary latest_specs_path
latest_specs = Marshal.load latest_specs_dump
- expected = [
- ['d', Gem::Version.new('2.0'), 'ruby'],
- ]
+ expected = [["a", Gem::Version.new("2"), "ruby"],
+ ["a_evil", Gem::Version.new("9"), "ruby"],
+ ["b", Gem::Version.new("2"), "ruby"],
+ ["c", Gem::Version.new("1.2"), "ruby"],
+ ["d", Gem::Version.new("2.0"), "ruby"],
+ ["pl", Gem::Version.new("1"), "i386-linux"]]
assert_equal expected, latest_specs, 'latest_specs'
end
@@ -109,10 +112,10 @@ class TestGemIndexer < Gem::TestCase
assert File.directory?(quickdir)
assert File.directory?(marshal_quickdir)
- assert_indexed marshal_quickdir, "#{@a1.spec_name}.rz"
- assert_indexed marshal_quickdir, "#{@a2.spec_name}.rz"
+ assert_indexed marshal_quickdir, "#{File.basename(@a1.spec_file)}.rz"
+ assert_indexed marshal_quickdir, "#{File.basename(@a2.spec_file)}.rz"
- refute_indexed marshal_quickdir, @c1_2.spec_name
+ refute_indexed marshal_quickdir, File.basename(@c1_2.spec_file)
assert_indexed @tempdir, "specs.#{@marshal_version}"
assert_indexed @tempdir, "specs.#{@marshal_version}.gz"
@@ -230,12 +233,12 @@ class TestGemIndexer < Gem::TestCase
<description>
&lt;pre&gt;This line is really, really long. So long, in fact, that it is more than
eighty characters long! The purpose of this line is for testing wrapping
-behavior because sometimes people don't wrap their text to eighty characters.
+behavior because sometimes people don't wrap their text to eighty characters.
Without the wrapping, the text might not look good in the RSS feed.
Also, a list:
* An entry that's actually kind of sort
- * an entry that's really long, which will probably get wrapped funny.
+ * an entry that's really long, which will probably get wrapped funny.
That's ok, somebody wasn't thinking straight when they made it more than
eighty characters.&lt;/pre&gt;
</description>
@@ -272,10 +275,10 @@ eighty characters.&lt;/pre&gt;
assert File.directory?(quickdir)
assert File.directory?(marshal_quickdir)
- assert_indexed marshal_quickdir, "#{@a1.spec_name}.rz"
- assert_indexed marshal_quickdir, "#{@a2.spec_name}.rz"
+ assert_indexed marshal_quickdir, "#{File.basename(@a1.spec_file)}.rz"
+ assert_indexed marshal_quickdir, "#{File.basename(@a2.spec_file)}.rz"
- refute_indexed marshal_quickdir, "#{@c1_2.spec_name}"
+ refute_indexed marshal_quickdir, "#{File.basename(@c1_2.spec_file)}"
refute_indexed @tempdir, "specs.#{@marshal_version}"
refute_indexed @tempdir, "specs.#{@marshal_version}.gz"
@@ -308,8 +311,8 @@ eighty characters.&lt;/pre&gt;
assert File.directory?(marshal_quickdir)
- assert_indexed marshal_quickdir, "#{@a1.spec_name}.rz"
- assert_indexed marshal_quickdir, "#{@a2.spec_name}.rz"
+ assert_indexed marshal_quickdir, "#{File.basename(@a1.spec_file)}.rz"
+ assert_indexed marshal_quickdir, "#{File.basename(@a2.spec_file)}.rz"
assert_indexed @tempdir, "specs.#{@marshal_version}"
assert_indexed @tempdir, "specs.#{@marshal_version}.gz"
@@ -343,19 +346,19 @@ eighty characters.&lt;/pre&gt;
refute_indexed quickdir, "latest_index"
refute_indexed quickdir, "latest_index.rz"
- refute_indexed quickdir, "#{@a1.spec_name}.rz"
- refute_indexed quickdir, "#{@a2.spec_name}.rz"
- refute_indexed quickdir, "#{@b2.spec_name}.rz"
- refute_indexed quickdir, "#{@c1_2.spec_name}.rz"
+ refute_indexed quickdir, "#{File.basename(@a1.spec_file)}.rz"
+ refute_indexed quickdir, "#{File.basename(@a2.spec_file)}.rz"
+ refute_indexed quickdir, "#{File.basename(@b2.spec_file)}.rz"
+ refute_indexed quickdir, "#{File.basename(@c1_2.spec_file)}.rz"
refute_indexed quickdir, "#{@pl1.original_name}.gemspec.rz"
- refute_indexed quickdir, "#{@pl1.spec_name}.rz"
+ refute_indexed quickdir, "#{File.basename(@pl1.spec_file)}.rz"
- assert_indexed marshal_quickdir, "#{@a1.spec_name}.rz"
- assert_indexed marshal_quickdir, "#{@a2.spec_name}.rz"
+ assert_indexed marshal_quickdir, "#{File.basename(@a1.spec_file)}.rz"
+ assert_indexed marshal_quickdir, "#{File.basename(@a2.spec_file)}.rz"
- refute_indexed quickdir, "#{@c1_2.spec_name}"
- refute_indexed marshal_quickdir, "#{@c1_2.spec_name}"
+ refute_indexed quickdir, "#{File.basename(@c1_2.spec_file)}"
+ refute_indexed marshal_quickdir, "#{File.basename(@c1_2.spec_file)}"
assert_indexed @tempdir, "specs.#{@marshal_version}"
assert_indexed @tempdir, "specs.#{@marshal_version}.gz"
@@ -389,8 +392,8 @@ eighty characters.&lt;/pre&gt;
assert File.directory?(quickdir)
assert File.directory?(marshal_quickdir)
- assert_indexed marshal_quickdir, "#{@a1.spec_name}.rz"
- assert_indexed marshal_quickdir, "#{@a2.spec_name}.rz"
+ assert_indexed marshal_quickdir, "#{File.basename(@a1.spec_file)}.rz"
+ assert_indexed marshal_quickdir, "#{File.basename(@a2.spec_file)}.rz"
assert_indexed @tempdir, "specs.#{@marshal_version}"
assert_indexed @tempdir, "specs.#{@marshal_version}.gz"
@@ -404,10 +407,7 @@ eighty characters.&lt;/pre&gt;
@indexer.generate_index
end
- assert_match %r%^Loading 10 gems from #{Regexp.escape @tempdir}$%,
- @ui.output
assert_match %r%^\.\.\.\.\.\.\.\.\.\.$%, @ui.output
- assert_match %r%^Loaded all gems$%, @ui.output
assert_match %r%^Generating Marshal quick index gemspecs for 10 gems$%,
@ui.output
assert_match %r%^Complete$%, @ui.output
@@ -520,14 +520,15 @@ eighty characters.&lt;/pre&gt;
@d2_1_a_tuple = [@d2_1_a.name, @d2_1_a.version, @d2_1_a.original_platform]
gems = File.join @tempdir, 'gems'
- FileUtils.mv Gem.cache_gem(@d2_1.file_name, @gemhome), gems
- FileUtils.mv Gem.cache_gem(@d2_1_a.file_name, @gemhome), gems
+
+ FileUtils.mv @d2_1.cache_file, gems
+ FileUtils.mv @d2_1_a.cache_file, gems
use_ui @ui do
@indexer.update_index
end
- assert_indexed marshal_quickdir, "#{@d2_1.spec_name}.rz"
+ assert_indexed marshal_quickdir, "#{File.basename(@d2_1.spec_file)}.rz"
specs_index = Marshal.load Gem.read_binary(@indexer.dest_specs_index)
diff --git a/test/rubygems/test_gem_install_update_options.rb b/test/rubygems/test_gem_install_update_options.rb
index fe10fd4..2f0b911 100644
--- a/test/rubygems/test_gem_install_update_options.rb
+++ b/test/rubygems/test_gem_install_update_options.rb
@@ -46,9 +46,8 @@ class TestGemInstallUpdateOptions < Gem::InstallerTestCase
@installer = Gem::Installer.new @gem, @cmd.options
@installer.install
- assert File.exist?(File.join(Gem.user_dir, 'gems'))
- assert File.exist?(File.join(Gem.user_dir, 'gems',
- @spec.full_name))
+ assert_path_exists File.join(Gem.user_dir, 'gems')
+ assert_path_exists File.join(Gem.user_dir, 'gems', @spec.full_name)
end
def test_user_install_disabled_read_only
@@ -59,11 +58,13 @@ class TestGemInstallUpdateOptions < Gem::InstallerTestCase
refute @cmd.options[:user_install]
- File.chmod 0755, @userhome
+ FileUtils.chmod 0755, @userhome
FileUtils.chmod 0000, @gemhome
+ Gem.use_paths @gemhome, @userhome
+
assert_raises(Gem::FilePermissionError) do
- @installer = Gem::Installer.new @gem, @cmd.options
+ Gem::Installer.new(@gem, @cmd.options).install
end
end
ensure
diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb
index 554865d..249b195 100644
--- a/test/rubygems/test_gem_installer.rb
+++ b/test/rubygems/test_gem_installer.rb
@@ -8,6 +8,25 @@ require 'rubygems/installer_test_case'
class TestGemInstaller < Gem::InstallerTestCase
+ def setup
+ super
+
+ if __name__ !~ /^test_install(_|$)/ then
+ @gemhome = @installer_tmp
+ Gem.use_paths @installer_tmp
+
+ @spec = Gem::Specification.find_by_name 'a'
+ @user_spec = Gem::Specification.find_by_name 'b'
+
+ @installer.spec = @spec
+ @installer.gem_home = @installer_tmp
+ @installer.gem_dir = @spec.gem_dir
+ @user_installer.spec = @user_spec
+ @user_installer.gem_home = @installer_tmp
+ end
+ end
+
+
def test_app_script_text
@spec.version = 2
util_make_exec @spec, ''
@@ -108,7 +127,7 @@ load Gem.bin_path('a', 'executable', version)
def test_extract_files
format = Object.new
def format.file_entries
- [[{'size' => 7, 'mode' => 0400, 'path' => 'thefile'}, 'thefile']]
+ [[{'size' => 7, 'mode' => 0400, 'path' => 'thefile'}, 'content']]
end
@installer.format = format
@@ -116,7 +135,7 @@ load Gem.bin_path('a', 'executable', version)
@installer.extract_files
thefile_path = File.join(util_gem_dir, 'thefile')
- assert_equal 'thefile', File.read(thefile_path)
+ assert_equal 'content', File.read(thefile_path)
unless Gem.win_platform? then
assert_equal 0400, File.stat(thefile_path).mode & 0777
@@ -145,8 +164,9 @@ load Gem.bin_path('a', 'executable', version)
@installer.extract_files
end
- assert_equal "attempt to install file into \"../thefile\" under #{util_gem_dir.inspect}",
- e.message
+ dir = util_gem_dir
+ expected = "attempt to install file into \"../thefile\" under #{dir}"
+ assert_equal expected, e.message
assert_equal false, File.file?(File.join(@tempdir, '../thefile')),
"You may need to remove this file if you broke the test once"
end
@@ -163,7 +183,7 @@ load Gem.bin_path('a', 'executable', version)
@installer.extract_files
end
- assert_equal 'attempt to install file into "/thefile"', e.message
+ assert_equal 'attempt to install file into /thefile', e.message
assert_equal false, File.file?(File.join('/thefile')),
"You may need to remove this file if you broke the test once"
end
@@ -241,7 +261,7 @@ load Gem.bin_path('a', 'executable', version)
@installer.wrappers = true
@spec.executables = %w[executable]
- gem_dir = File.join "#{@gemhome}2", 'gems', @spec.full_name
+ gem_dir = File.join("#{@gemhome}2", "gems", @spec.full_name)
gem_bindir = File.join gem_dir, 'bin'
FileUtils.mkdir_p gem_bindir
File.open File.join(gem_bindir, 'executable'), 'w' do |f|
@@ -253,7 +273,7 @@ load Gem.bin_path('a', 'executable', version)
@installer.generate_bin
- installed_exec = File.join("#{@gemhome}2", 'bin', 'executable')
+ installed_exec = File.join("#{@gemhome}2", "bin", 'executable')
assert_equal true, File.exist?(installed_exec)
assert_equal mask, File.stat(installed_exec).mode unless win_platform?
@@ -279,14 +299,14 @@ load Gem.bin_path('a', 'executable', version)
if win_platform?
skip('test_generate_bin_script_no_perms skipped on MS Windows')
else
- File.chmod 0000, util_inst_bindir
+ FileUtils.chmod 0000, util_inst_bindir
assert_raises Gem::FilePermissionError do
@installer.generate_bin
end
end
ensure
- File.chmod 0700, util_inst_bindir unless $DEBUG
+ FileUtils.chmod 0755, util_inst_bindir unless ($DEBUG or win_platform?)
end
def test_generate_bin_script_no_shebang
@@ -346,7 +366,7 @@ load Gem.bin_path('a', 'executable', version)
@installer.generate_bin
assert_equal true, File.directory?(util_inst_bindir)
- installed_exec = File.join(util_inst_bindir, 'executable')
+ installed_exec = File.join util_inst_bindir, 'executable'
assert_equal true, File.symlink?(installed_exec)
assert_equal(File.join(util_gem_dir, 'bin', 'executable'),
File.readlink(installed_exec))
@@ -371,14 +391,14 @@ load Gem.bin_path('a', 'executable', version)
if win_platform?
skip('test_generate_bin_symlink_no_perms skipped on MS Windows')
else
- File.chmod 0000, util_inst_bindir
+ FileUtils.chmod 0000, util_inst_bindir
assert_raises Gem::FilePermissionError do
@installer.generate_bin
end
end
ensure
- File.chmod 0700, util_inst_bindir unless $DEBUG
+ FileUtils.chmod 0755, util_inst_bindir unless ($DEBUG or win_platform?)
end
def test_generate_bin_symlink_update_newer
@@ -404,10 +424,10 @@ load Gem.bin_path('a', 'executable', version)
@spec.version = 3
util_make_exec
- @installer.gem_dir = File.join util_gem_dir @spec
+ @installer.gem_dir = util_gem_dir @spec
@installer.generate_bin
installed_exec = File.join(util_inst_bindir, 'executable')
- assert_equal(File.join(util_gem_bindir(@spec), 'executable'),
+ assert_equal(@spec.bin_file('executable'),
File.readlink(installed_exec),
"Ensure symlink moved to latest version")
end
@@ -441,8 +461,9 @@ load Gem.bin_path('a', 'executable', version)
@installer.generate_bin
- installed_exec = File.join(util_inst_bindir, 'executable')
- assert_equal(File.join(util_gem_dir, 'bin', 'executable'),
+ installed_exec = File.join util_inst_bindir, 'executable'
+ expected = File.join util_gem_dir, 'bin', 'executable'
+ assert_equal(expected,
File.readlink(installed_exec),
"Ensure symlink not moved")
end
@@ -455,7 +476,7 @@ load Gem.bin_path('a', 'executable', version)
@installer.gem_dir = util_gem_dir
@installer.generate_bin
- installed_exec = File.join(util_inst_bindir, 'executable')
+ installed_exec = File.join util_inst_bindir, 'executable'
assert_equal true, File.exist?(installed_exec)
@spec = Gem::Specification.new do |s|
@@ -522,7 +543,7 @@ load Gem.bin_path('a', 'executable', version)
Dir.mkdir util_inst_bindir
util_build_gem spec
- FileUtils.mv Gem.cache_gem(spec.file_name, @gemhome), @tempdir
+ FileUtils.mv spec.cache_file, @tempdir
installer = Gem::Installer.new gem
@@ -535,7 +556,7 @@ load Gem.bin_path('a', 'executable', version)
util_clear_gems
gemdir = File.join @gemhome, 'gems', @spec.full_name
- cache_file = Gem.cache_gem(@spec.file_name, @gemhome)
+ cache_file = File.join @gemhome, 'cache', @spec.file_name
stub_exe = File.join @gemhome, 'bin', 'executable'
rakefile = File.join gemdir, 'ext', 'a', 'Rakefile'
@@ -555,12 +576,14 @@ load Gem.bin_path('a', 'executable', version)
assert File.exist?(cache_file), 'cache file must exist'
end
+ @newspec = nil
build_rake_in do
use_ui @ui do
- assert_equal @spec, @installer.install
+ @newspec = @installer.install
end
end
+ assert_equal @spec, @newspec
assert File.exist? gemdir
assert File.exist?(stub_exe), 'gem executable must exist'
@@ -576,7 +599,7 @@ load Gem.bin_path('a', 'executable', version)
spec_file = File.join(@gemhome, 'specifications', @spec.spec_name)
- assert_equal spec_file, @spec.loaded_from
+ assert_equal spec_file, @newspec.loaded_from
assert File.exist?(spec_file)
assert_same @installer, @post_build_hook_arg
@@ -656,17 +679,17 @@ load Gem.bin_path('a', 'executable', version)
gemhome2 = "#{@gemhome}2"
@spec.add_dependency 'b'
- b2 = quick_spec 'b', 2
+ quick_gem 'b', 2
FileUtils.mv @gemhome, gemhome2
- Gem.source_index.gems.delete b2.full_name
- source_index = Gem::SourceIndex.from_gems_in File.join(gemhome2,
- 'specifications')
+
+ Gem::Specification.dirs = [gemhome2] # TODO: switch all dirs= to use_paths
util_setup_gem
- @installer = Gem::Installer.new @gem, :install_dir => gemhome2,
- :source_index => source_index
+ @installer = Gem::Installer.new @gem, :install_dir => gemhome2
+
+ gem_home = Gem.dir
build_rake_in do
use_ui @ui do
@@ -675,6 +698,7 @@ load Gem.bin_path('a', 'executable', version)
end
assert File.exist?(File.join(gemhome2, 'gems', @spec.full_name))
+ assert_equal gem_home, Gem.dir
end
def test_install_force
@@ -712,7 +736,7 @@ load Gem.bin_path('a', 'executable', version)
end
def test_install_missing_dirs
- FileUtils.rm_f Gem.cache_dir
+ FileUtils.rm_f File.join(Gem.dir, 'cache')
FileUtils.rm_f File.join(Gem.dir, 'docs')
FileUtils.rm_f File.join(Gem.dir, 'specifications')
@@ -722,11 +746,11 @@ load Gem.bin_path('a', 'executable', version)
@installer.install
end
- File.directory? Gem.cache_dir
+ File.directory? File.join(Gem.dir, 'cache')
File.directory? File.join(Gem.dir, 'docs')
File.directory? File.join(Gem.dir, 'specifications')
- assert File.exist?(Gem.cache_gem(@spec.file_name, @gemhome))
+ assert File.exist?(File.join(@gemhome, 'cache', @spec.file_name))
assert File.exist?(File.join(@gemhome, 'specifications', @spec.spec_name))
end
@@ -812,8 +836,9 @@ load Gem.bin_path('a', 'executable', version)
@spec.post_install_message = 'I am a shiny gem!'
use_ui @ui do
- Dir.chdir @tempdir do Gem::Builder.new(@spec).build end
+ path = Gem::Builder.new(@spec).build
+ @installer = Gem::Installer.new path
@installer.install
end
@@ -838,7 +863,7 @@ load Gem.bin_path('a', 'executable', version)
util_build_gem spec
- gem = Gem.cache_gem(spec.file_name, @gemhome)
+ gem = File.join(@gemhome, 'cache', spec.file_name)
use_ui @ui do
@installer = Gem::Installer.new gem
@@ -1002,6 +1027,10 @@ load Gem.bin_path('a', 'executable', version)
assert_equal @spec, eval(File.read(spec_file))
end
+ def test_dir
+ assert_match @installer.dir, %r!/installer/gems/a-2$!
+ end
+
def old_ruby_required
spec = quick_spec 'old_ruby_required', '1' do |s|
s.required_ruby_version = '= 1.4.6'
@@ -1009,20 +1038,17 @@ load Gem.bin_path('a', 'executable', version)
util_build_gem spec
- Gem.cache_gem(spec.file_name, @gemhome)
+ spec.cache_file
end
def util_execless
@spec = quick_spec 'z'
+ util_build_gem @spec
- gem = File.join @tempdir, @spec.file_name
-
- @installer = util_installer @spec, gem, @gemhome
+ @installer = util_installer @spec, @gemhome
end
def mask
0100755 & (~File.umask)
end
-
end
-
diff --git a/test/rubygems/test_gem_package_tar_output.rb b/test/rubygems/test_gem_package_tar_output.rb
index 77f3185..01b4a0f 100644
--- a/test/rubygems/test_gem_package_tar_output.rb
+++ b/test/rubygems/test_gem_package_tar_output.rb
@@ -6,6 +6,7 @@
require 'rubygems/package/tar_test_case'
require 'rubygems/package/tar_output'
+require 'rubygems/security'
class TestGemPackageTarOutput < Gem::Package::TarTestCase
diff --git a/test/rubygems/test_gem_path_support.rb b/test/rubygems/test_gem_path_support.rb
new file mode 100644
index 0000000..7fb0cca
--- /dev/null
+++ b/test/rubygems/test_gem_path_support.rb
@@ -0,0 +1,64 @@
+######################################################################
+# This file is imported from the rubygems project.
+# DO NOT make modifications in this repo. They _will_ be reverted!
+# File a patch instead and assign it to Ryan Davis or Eric Hodel.
+######################################################################
+
+require 'rubygems/test_case'
+require 'rubygems'
+require 'fileutils'
+
+class TestGemPathSupport < Gem::TestCase
+ def setup
+ super
+
+ ENV["GEM_HOME"] = @tempdir
+ ENV["GEM_PATH"] = [@tempdir, "something"].join(File::PATH_SEPARATOR)
+ end
+
+ def test_initialize
+ ps = Gem::PathSupport.new
+
+ assert_equal ENV["GEM_HOME"], ps.home
+
+ expected = util_path
+ assert_equal expected, ps.path, "defaults to GEM_PATH"
+ end
+
+ def test_initialize_home
+ ps = Gem::PathSupport.new "GEM_HOME" => "#{@tempdir}/foo"
+
+ assert_equal File.join(@tempdir, "foo"), ps.home
+
+ expected = util_path + [File.join(@tempdir, 'foo')]
+ assert_equal expected, ps.path
+ end
+
+ def test_initialize_path
+ ps = Gem::PathSupport.new "GEM_PATH" => %W[#{@tempdir}/foo #{@tempdir}/bar]
+
+ assert_equal ENV["GEM_HOME"], ps.home
+
+ expected = [
+ File.join(@tempdir, 'foo'),
+ File.join(@tempdir, 'bar'),
+ ENV["GEM_HOME"],
+ ]
+
+ assert_equal expected, ps.path
+ end
+
+ def test_initialize_home_path
+ ps = Gem::PathSupport.new("GEM_HOME" => "#{@tempdir}/foo",
+ "GEM_PATH" => %W[#{@tempdir}/foo #{@tempdir}/bar])
+
+ assert_equal File.join(@tempdir, "foo"), ps.home
+
+ expected = [File.join(@tempdir, 'foo'), File.join(@tempdir, 'bar')]
+ assert_equal expected, ps.path
+ end
+
+ def util_path
+ ENV["GEM_PATH"].split(File::PATH_SEPARATOR)
+ end
+end
diff --git a/test/rubygems/test_gem_platform.rb b/test/rubygems/test_gem_platform.rb
index 485bab7..f46a20f 100644
--- a/test/rubygems/test_gem_platform.rb
+++ b/test/rubygems/test_gem_platform.rb
@@ -144,7 +144,7 @@ class TestGemPlatform < Gem::TestCase
def test_empty
platform = Gem::Platform.new 'cpu-other_platform1'
assert_respond_to platform, :empty?
- assert_equal false, platform.empty?
+ assert_equal false, Deprecate.skip_during { platform.empty? }
end
def test_to_s
diff --git a/test/rubygems/test_gem_remote_fetcher.rb b/test/rubygems/test_gem_remote_fetcher.rb
index 66fb682..e039bb7 100644
--- a/test/rubygems/test_gem_remote_fetcher.rb
+++ b/test/rubygems/test_gem_remote_fetcher.rb
@@ -99,7 +99,7 @@ gems:
# REFACTOR: copied from test_gem_dependency_installer.rb
@gems_dir = File.join @tempdir, 'gems'
- @cache_dir = Gem.cache_dir(@gemhome)
+ @cache_dir = File.join @gemhome, "cache"
FileUtils.mkdir @gems_dir
# TODO: why does the remote fetcher need it written to disk?
@@ -152,7 +152,7 @@ gems:
fetcher.fetch_size 'gems.example.com/yaml'
end
- assert_equal 'uri scheme is invalid', e.message
+ assert_equal 'uri scheme is invalid: nil', e.message
end
def test_fetch_size_socket_error
@@ -209,7 +209,7 @@ gems:
fetcher = util_fuck_with_fetcher a1_data
- a1_cache_gem = Gem.cache_gem(@a1.file_name, @gemhome)
+ a1_cache_gem = @a1.cache_file
assert_equal a1_cache_gem, fetcher.download(@a1, 'http://gems.example.com')
assert_equal("http://gems.example.com/gems/a-1.gem",
fetcher.instance_variable_get(:@test_arg).to_s)
@@ -221,8 +221,7 @@ gems:
inst = Gem::RemoteFetcher.fetcher
- assert_equal Gem.cache_gem(@a1.file_name, @gemhome),
- inst.download(@a1, 'http://gems.example.com')
+ assert_equal @a1.cache_file, inst.download(@a1, 'http://gems.example.com')
end
def test_download_local
@@ -234,8 +233,7 @@ gems:
inst = Gem::RemoteFetcher.fetcher
end
- assert_equal Gem.cache_gem(@a1.file_name, @gemhome),
- inst.download(@a1, local_path)
+ assert_equal @a1.cache_file, inst.download(@a1, local_path)
end
def test_download_local_space
@@ -249,21 +247,19 @@ gems:
inst = Gem::RemoteFetcher.fetcher
end
- assert_equal Gem.cache_gem(@a1.file_name, @gemhome),
- inst.download(@a1, local_path)
+ assert_equal @a1.cache_file, inst.download(@a1, local_path)
end
def test_download_install_dir
- a1_data = nil
- File.open @a1_gem, 'rb' do |fp|
- a1_data = fp.read
+ a1_data = File.open @a1_gem, 'rb' do |fp|
+ fp.read
end
fetcher = util_fuck_with_fetcher a1_data
install_dir = File.join @tempdir, 'more_gems'
- a1_cache_gem = Gem.cache_gem(@a1.file_name, install_dir)
+ a1_cache_gem = File.join install_dir, "cache", @a1.file_name
FileUtils.mkdir_p(File.dirname(a1_cache_gem))
actual = fetcher.download(@a1, 'http://gems.example.com', install_dir)
@@ -279,7 +275,7 @@ gems:
FileUtils.mv @a1_gem, @tempdir
local_path = File.join @tempdir, @a1.file_name
inst = nil
- File.chmod 0555, Gem.cache_dir(@gemhome)
+ FileUtils.chmod 0555, @a1.cache_dir
Dir.chdir @tempdir do
inst = Gem::RemoteFetcher.fetcher
@@ -288,19 +284,20 @@ gems:
assert_equal File.join(@tempdir, @a1.file_name),
inst.download(@a1, local_path)
ensure
- File.chmod 0755, Gem.cache_dir(@gemhome)
+ FileUtils.chmod 0755, @a1.cache_dir
end
def test_download_read_only
- File.chmod 0555, Gem.cache_dir(@gemhome)
- File.chmod 0555, File.join(@gemhome)
+ FileUtils.chmod 0555, @a1.cache_dir
+ FileUtils.chmod 0555, @gemhome
fetcher = util_fuck_with_fetcher File.read(@a1_gem)
fetcher.download(@a1, 'http://gems.example.com')
- assert File.exist?(Gem.cache_gem(@a1.file_name, Gem.user_dir))
+ a1_cache_gem = File.join Gem.user_dir, "cache", @a1.file_name
+ assert File.exist? a1_cache_gem
ensure
- File.chmod 0755, @gemhome
- File.chmod 0755, Gem.cache_dir(@gemhome)
+ FileUtils.chmod 0755, @gemhome
+ FileUtils.chmod 0755, @a1.cache_dir
end
end
@@ -319,7 +316,7 @@ gems:
fetcher = util_fuck_with_fetcher e1_data, :blow_chunks
- e1_cache_gem = Gem.cache_gem(e1.file_name, @gemhome)
+ e1_cache_gem = e1.cache_file
assert_equal e1_cache_gem, fetcher.download(e1, 'http://gems.example.com')
@@ -337,7 +334,7 @@ gems:
inst = Gem::RemoteFetcher.fetcher
end
- cache_path = Gem.cache_gem(@a1.file_name, @gemhome)
+ cache_path = @a1.cache_file
FileUtils.mv local_path, cache_path
gem = Gem::Format.from_file_by_path cache_path
@@ -422,7 +419,7 @@ gems:
def test_fetch_path_gzip
fetcher = Gem::RemoteFetcher.new nil
- def fetcher.open_uri_or_path(uri, mtime, head = nil)
+ def fetcher.fetch_http(uri, mtime, head = nil)
Gem.gzip 'foo'
end
@@ -432,7 +429,7 @@ gems:
def test_fetch_path_gzip_unmodified
fetcher = Gem::RemoteFetcher.new nil
- def fetcher.open_uri_or_path(uri, mtime, head = nil)
+ def fetcher.fetch_http(uri, mtime, head = nil)
nil
end
@@ -442,53 +439,59 @@ gems:
def test_fetch_path_io_error
fetcher = Gem::RemoteFetcher.new nil
- def fetcher.open_uri_or_path(uri, mtime, head = nil)
+ def fetcher.fetch_http(*)
raise EOFError
end
+ url = 'http://example.com/uri'
+
e = assert_raises Gem::RemoteFetcher::FetchError do
- fetcher.fetch_path 'uri'
+ fetcher.fetch_path url
end
- assert_equal 'EOFError: EOFError (uri)', e.message
- assert_equal 'uri', e.uri
+ assert_equal "EOFError: EOFError (#{url})", e.message
+ assert_equal url, e.uri
end
def test_fetch_path_socket_error
fetcher = Gem::RemoteFetcher.new nil
- def fetcher.open_uri_or_path(uri, mtime, head = nil)
+ def fetcher.fetch_http(uri, mtime, head = nil)
raise SocketError
end
+ url = 'http://example.com/uri'
+
e = assert_raises Gem::RemoteFetcher::FetchError do
- fetcher.fetch_path 'uri'
+ fetcher.fetch_path url
end
- assert_equal 'SocketError: SocketError (uri)', e.message
- assert_equal 'uri', e.uri
+ assert_equal "SocketError: SocketError (#{url})", e.message
+ assert_equal url, e.uri
end
def test_fetch_path_system_call_error
fetcher = Gem::RemoteFetcher.new nil
- def fetcher.open_uri_or_path(uri, mtime = nil, head = nil)
+ def fetcher.fetch_http(uri, mtime = nil, head = nil)
raise Errno::ECONNREFUSED, 'connect(2)'
end
+ url = 'http://example.com/uri'
+
e = assert_raises Gem::RemoteFetcher::FetchError do
- fetcher.fetch_path 'uri'
+ fetcher.fetch_path url
end
- assert_match %r|ECONNREFUSED:.*connect\(2\) \(uri\)\z|,
+ assert_match %r|ECONNREFUSED:.*connect\(2\) \(#{Regexp.escape url}\)\z|,
e.message
- assert_equal 'uri', e.uri
+ assert_equal url, e.uri
end
def test_fetch_path_unmodified
fetcher = Gem::RemoteFetcher.new nil
- def fetcher.open_uri_or_path(uri, mtime, head = nil)
+ def fetcher.fetch_http(uri, mtime, head = nil)
nil
end
@@ -551,16 +554,18 @@ gems:
end
end
- def test_open_uri_or_path
+ def test_fetch_http
fetcher = Gem::RemoteFetcher.new nil
+ url = 'http://gems.example.com/redirect'
conn = Object.new
def conn.started?() true end
def conn.request(req)
+ url = 'http://gems.example.com/redirect'
unless defined? @requested then
@requested = true
res = Net::HTTPMovedPermanently.new nil, 301, nil
- res.add_field 'Location', 'http://gems.example.com/real_path'
+ res.add_field 'Location', url
res
else
res = Net::HTTPOK.new nil, 200, nil
@@ -572,19 +577,21 @@ gems:
conn = { "#{Thread.current.object_id}:gems.example.com:80" => conn }
fetcher.instance_variable_set :@connections, conn
- data = fetcher.open_uri_or_path 'http://gems.example.com/redirect'
+ data = fetcher.fetch_http URI.parse(url)
assert_equal 'real_path', data
end
- def test_open_uri_or_path_limited_redirects
+ def test_fetch_http_redirects
fetcher = Gem::RemoteFetcher.new nil
+ url = 'http://gems.example.com/redirect'
conn = Object.new
def conn.started?() true end
def conn.request(req)
+ url = 'http://gems.example.com/redirect'
res = Net::HTTPMovedPermanently.new nil, 301, nil
- res.add_field 'Location', 'http://gems.example.com/redirect'
+ res.add_field 'Location', url
res
end
@@ -592,11 +599,10 @@ gems:
fetcher.instance_variable_set :@connections, conn
e = assert_raises Gem::RemoteFetcher::FetchError do
- fetcher.open_uri_or_path 'http://gems.example.com/redirect'
+ fetcher.fetch_http URI.parse(url)
end
- assert_equal 'too many redirects (http://gems.example.com/redirect)',
- e.message
+ assert_equal "too many redirects (#{url})", e.message
end
def test_request
@@ -631,6 +637,85 @@ gems:
assert_equal t.rfc2822, conn.payload['if-modified-since']
end
+ def test_user_agent
+ ua = @fetcher.user_agent
+
+ assert_match %r%^RubyGems/\S+ \S+ Ruby/\S+ \(.*?\)%, ua
+ assert_match %r%RubyGems/#{Regexp.escape Gem::VERSION}%, ua
+ assert_match %r% #{Regexp.escape Gem::Platform.local.to_s} %, ua
+ assert_match %r%Ruby/#{Regexp.escape RUBY_VERSION}%, ua
+ assert_match %r%\(#{Regexp.escape RUBY_RELEASE_DATE} %, ua
+ end
+
+ def test_user_agent_engine
+ util_save_version
+
+ Object.send :remove_const, :RUBY_ENGINE if defined?(RUBY_ENGINE)
+ Object.send :const_set, :RUBY_ENGINE, 'vroom'
+
+ ua = @fetcher.user_agent
+
+ assert_match %r%\) vroom%, ua
+ ensure
+ util_restore_version
+ end
+
+ def test_user_agent_engine_ruby
+ util_save_version
+
+ Object.send :remove_const, :RUBY_ENGINE if defined?(RUBY_ENGINE)
+ Object.send :const_set, :RUBY_ENGINE, 'ruby'
+
+ ua = @fetcher.user_agent
+
+ assert_match %r%\)%, ua
+ ensure
+ util_restore_version
+ end
+
+ def test_user_agent_patchlevel
+ util_save_version
+
+ Object.send :remove_const, :RUBY_PATCHLEVEL
+ Object.send :const_set, :RUBY_PATCHLEVEL, 5
+
+ ua = @fetcher.user_agent
+
+ assert_match %r% patchlevel 5\)%, ua
+ ensure
+ util_restore_version
+ end
+
+ def test_user_agent_revision
+ util_save_version
+
+ Object.send :remove_const, :RUBY_PATCHLEVEL
+ Object.send :const_set, :RUBY_PATCHLEVEL, -1
+ Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION)
+ Object.send :const_set, :RUBY_REVISION, 6
+
+ ua = @fetcher.user_agent
+
+ assert_match %r% revision 6\)%, ua
+ assert_match %r%Ruby/#{Regexp.escape RUBY_VERSION}dev%, ua
+ ensure
+ util_restore_version
+ end
+
+ def test_user_agent_revision_missing
+ util_save_version
+
+ Object.send :remove_const, :RUBY_PATCHLEVEL
+ Object.send :const_set, :RUBY_PATCHLEVEL, -1
+ Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION)
+
+ ua = @fetcher.user_agent
+
+ assert_match %r%\(#{Regexp.escape RUBY_RELEASE_DATE}\)%, ua
+ ensure
+ util_restore_version
+ end
+
def test_yaml_error_on_size
use_ui @ui do
self.class.enable_yaml = false
@@ -753,5 +838,24 @@ gems:
assert_equal "/home/skillet", @fetcher.correct_for_windows_path(path)
end
+ def util_save_version
+ @orig_RUBY_ENGINE = RUBY_ENGINE if defined? RUBY_ENGINE
+ @orig_RUBY_PATCHLEVEL = RUBY_PATCHLEVEL
+ @orig_RUBY_REVISION = RUBY_REVISION if defined? RUBY_REVISION
+ end
+
+ def util_restore_version
+ Object.send :remove_const, :RUBY_ENGINE if defined?(RUBY_ENGINE)
+ Object.send :const_set, :RUBY_ENGINE, @orig_RUBY_ENGINE if
+ defined?(@orig_RUBY_ENGINE)
+
+ Object.send :remove_const, :RUBY_PATCHLEVEL
+ Object.send :const_set, :RUBY_PATCHLEVEL, @orig_RUBY_PATCHLEVEL
+
+ Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION)
+ Object.send :const_set, :RUBY_REVISION, @orig_RUBY_REVISION if
+ defined?(@orig_RUBY_REVISION)
+ end
+
end
diff --git a/test/rubygems/test_gem_requirement.rb b/test/rubygems/test_gem_requirement.rb
index c8490de..b646171 100644
--- a/test/rubygems/test_gem_requirement.rb
+++ b/test/rubygems/test_gem_requirement.rb
@@ -256,6 +256,19 @@ class TestGemRequirement < Gem::TestCase
refute_satisfied_by "2.0", "~> 1.4.4"
end
+ def test_specific
+ refute req('> 1') .specific?
+ refute req('>= 1').specific?
+
+ assert req('!= 1').specific?
+ assert req('< 1') .specific?
+ assert req('<= 1').specific?
+ assert req('= 1') .specific?
+ assert req('~> 1').specific?
+
+ assert req('> 1', '> 2').specific? # GIGO
+ end
+
def test_bad
refute_satisfied_by "", "> 0.1"
refute_satisfied_by "1.2.3", "!= 1.2.3"
diff --git a/test/rubygems/test_gem_server.rb b/test/rubygems/test_gem_server.rb
index 3fad8c4..bd4d960 100644
--- a/test/rubygems/test_gem_server.rb
+++ b/test/rubygems/test_gem_server.rb
@@ -9,12 +9,10 @@ require 'rubygems/server'
require 'stringio'
class Gem::Server
- attr_accessor :source_index
attr_reader :server
end
class TestGemServer < Gem::TestCase
-
def setup
super
@@ -41,52 +39,64 @@ class TestGemServer < Gem::TestCase
data = StringIO.new "GET /Marshal.#{Gem.marshal_version} HTTP/1.0\r\n\r\n"
@req.parse data
- @server.Marshal @req, @res
+ Deprecate.skip_during do
+ @server.Marshal @req, @res
+ end
assert_equal 200, @res.status, @res.body
assert_match %r| \d\d:\d\d:\d\d |, @res['date']
assert_equal 'application/octet-stream', @res['content-type']
- si = Gem::SourceIndex.new
- si.add_specs @a1, @a2
+ Deprecate.skip_during do
+ si = Gem::SourceIndex.new
+ si.add_specs @a1, @a2
- assert_equal si, Marshal.load(@res.body)
+ assert_equal si, Marshal.load(@res.body)
+ end
end
def test_Marshal_Z
data = StringIO.new "GET /Marshal.#{Gem.marshal_version}.Z HTTP/1.0\r\n\r\n"
@req.parse data
- @server.Marshal @req, @res
+ Deprecate.skip_during do
+ @server.Marshal @req, @res
+ end
assert_equal 200, @res.status, @res.body
assert_match %r| \d\d:\d\d:\d\d |, @res['date']
assert_equal 'application/x-deflate', @res['content-type']
- si = Gem::SourceIndex.new
- si.add_specs @a1, @a2
+ Deprecate.skip_during do
+ si = Gem::SourceIndex.new
+ si.add_specs @a1, @a2
- assert_equal si, Marshal.load(Gem.inflate(@res.body))
+ assert_equal si, Marshal.load(Gem.inflate(@res.body))
+ end
end
def test_latest_specs
data = StringIO.new "GET /latest_specs.#{Gem.marshal_version} HTTP/1.0\r\n\r\n"
@req.parse data
- @server.latest_specs @req, @res
+ Deprecate.skip_during do
+ @server.latest_specs @req, @res
+ end
assert_equal 200, @res.status, @res.body
assert_match %r| \d\d:\d\d:\d\d |, @res['date']
assert_equal 'application/octet-stream', @res['content-type']
assert_equal [['a', Gem::Version.new(2), Gem::Platform::RUBY]],
- Marshal.load(@res.body)
+ Marshal.load(@res.body)
end
def test_latest_specs_gz
data = StringIO.new "GET /latest_specs.#{Gem.marshal_version}.gz HTTP/1.0\r\n\r\n"
@req.parse data
- @server.latest_specs @req, @res
+ Deprecate.skip_during do
+ @server.latest_specs @req, @res
+ end
assert_equal 200, @res.status, @res.body
assert_match %r| \d\d:\d\d:\d\d |, @res['date']
@@ -227,6 +237,4 @@ class TestGemServer < Gem::TestCase
@server.instance_variable_set :@server, webrick
end
-
end
-
diff --git a/test/rubygems/test_gem_silent_ui.rb b/test/rubygems/test_gem_silent_ui.rb
index 8005b3b..1968a89 100644
--- a/test/rubygems/test_gem_silent_ui.rb
+++ b/test/rubygems/test_gem_silent_ui.rb
@@ -55,7 +55,7 @@ class TestGemSilentUI < Gem::TestCase
assert_empty out, 'No output'
assert_empty err, 'No output'
-
+
out, err = capture_io do
use_ui @sui do
value = @sui.ask_yes_no 'Problem?', true
@@ -66,7 +66,7 @@ class TestGemSilentUI < Gem::TestCase
assert_empty err, 'No output'
assert value, 'Value is true'
-
+
out, err = capture_io do
use_ui @sui do
value = @sui.ask_yes_no 'Problem?', false
diff --git a/test/rubygems/test_gem_source_index.rb b/test/rubygems/test_gem_source_index.rb
index 89e2ea3..462ecbe 100644
--- a/test/rubygems/test_gem_source_index.rb
+++ b/test/rubygems/test_gem_source_index.rb
@@ -7,397 +7,250 @@
require 'rubygems/test_case'
require 'rubygems/source_index'
require 'rubygems/config_file'
+require 'rubygems/deprecate'
class TestGemSourceIndex < Gem::TestCase
-
def setup
super
util_setup_fake_fetcher
- end
-
- def test_self_from_gems_in
- spec_dir = File.join @gemhome, 'specifications'
-
- FileUtils.rm_r spec_dir
-
- FileUtils.mkdir_p spec_dir
-
- a1 = quick_spec 'a', '1' do |spec| spec.author = 'author 1' end
-
- spec_file = File.join spec_dir, a1.spec_name
-
- File.open spec_file, 'w' do |fp|
- fp.write a1.to_ruby
- end
-
- si = Gem::SourceIndex.from_gems_in spec_dir
-
- assert_equal [spec_dir], si.spec_dirs
- assert_equal [a1.full_name], si.gems.keys
- end
-
- def test_self_load_specification
- spec_dir = File.join @gemhome, 'specifications'
-
- FileUtils.rm_r spec_dir
-
- FileUtils.mkdir_p spec_dir
- a1 = quick_spec 'a', '1' do |spec| spec.author = 'author 1' end
-
- spec_file = File.join spec_dir, a1.spec_name
-
- File.open spec_file, 'w' do |fp|
- fp.write a1.to_ruby
- end
-
- spec = Gem::SourceIndex.load_specification spec_file
-
- assert_equal a1.author, spec.author
+ @source_index = Deprecate.skip_during { Gem.source_index }
end
- def test_self_load_specification_utf_8
- spec_dir = File.join @gemhome, 'specifications'
-
- FileUtils.rm_r spec_dir
-
- FileUtils.mkdir_p spec_dir
-
- spec_file = File.join spec_dir, "utf-8.gemspec"
- spec_data = <<-SPEC
-Gem::Specification.new do |s|
- s.name = %q{utf}
- s.version = "8"
+ def test_find_name
+ Deprecate.skip_during do
+ assert_equal [@a1, @a2, @a3a], @source_index.find_name('a')
+ assert_equal [@a2], @source_index.find_name('a', '= 2')
+ assert_equal [], @source_index.find_name('bogusstring')
+ assert_equal [], @source_index.find_name('a', '= 3')
- s.required_rubygems_version = Gem::Requirement.new(">= 0")
- s.authors = ["\317\200"]
- s.date = %q{2008-09-10}
- s.description = %q{This is a test description}
- s.email = %q{example@example.com}
- s.has_rdoc = true
- s.homepage = %q{http://example.com}
- s.require_paths = ["lib"]
- s.rubygems_version = %q{1.2.0}
- s.summary = %q{this is a summary}
+ source_index = Gem::SourceIndex.new
+ source_index.add_spec @a1
+ source_index.add_spec @a2
- if s.respond_to? :specification_version then
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
- s.specification_version = 2
+ assert_equal [@a1], source_index.find_name(@a1.name, '= 1')
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
- else
+ r1 = Gem::Requirement.create '= 1'
+ assert_equal [@a1], source_index.find_name(@a1.name, r1)
end
- else
end
-end
- SPEC
-
- spec_data.force_encoding 'UTF-8'
-
- File.open spec_file, 'w' do |io| io.write spec_data end
-
- spec = Gem::SourceIndex.load_specification spec_file
-
- pi = "\317\200"
- pi.force_encoding 'UTF-8' if pi.respond_to? :force_encoding
-
- assert_equal pi, spec.author
- end if Gem.ruby_version > Gem::Version.new('1.9')
- def test_self_load_specification_exception
- spec_dir = File.join @gemhome, 'specifications'
-
- FileUtils.mkdir_p spec_dir
-
- spec_file = File.join spec_dir, 'a-1.gemspec'
-
- File.open spec_file, 'w' do |fp|
- fp.write 'raise Exception, "epic fail"'
- end
-
- out, err = capture_io do
- assert_equal nil, Gem::SourceIndex.load_specification(spec_file)
+ def test_find_name_empty_cache
+ Deprecate.skip_during do
+ empty_source_index = Gem::SourceIndex.new
+ assert_equal [], empty_source_index.find_name("foo")
end
-
- assert_equal '', out
-
- expected = "Invalid gemspec in [#{spec_file}]: epic fail\n"
- assert_equal expected, err
end
- def test_self_load_specification_interrupt
- spec_dir = File.join @gemhome, 'specifications'
-
- FileUtils.mkdir_p spec_dir
-
- spec_file = File.join spec_dir, 'a-1.gemspec'
-
- File.open spec_file, 'w' do |fp|
- fp.write 'raise Interrupt, "^C"'
- end
-
- use_ui @ui do
- assert_raises Interrupt do
- Gem::SourceIndex.load_specification(spec_file)
+ # HACK: deprecated impl is failing tests, but I may want to port it over
+ def test_latest_specs
+ Deprecate.skip_during do
+ p1_ruby = quick_spec 'p', '1'
+ p1_platform = quick_spec 'p', '1' do |spec|
+ spec.platform = Gem::Platform::CURRENT
end
- end
-
- assert_equal '', @ui.output
- assert_equal '', @ui.error
- end
-
- def test_self_load_specification_syntax_error
- spec_dir = File.join @gemhome, 'specifications'
-
- FileUtils.mkdir_p spec_dir
-
- spec_file = File.join spec_dir, 'a-1.gemspec'
-
- File.open spec_file, 'w' do |fp|
- fp.write '1 +'
- end
-
- out, err = capture_io do
- assert_equal nil, Gem::SourceIndex.load_specification(spec_file)
- end
-
- assert_equal '', out
-
- assert_match(/syntax error/, err)
- end
-
- def test_self_load_specification_system_exit
- spec_dir = File.join @gemhome, 'specifications'
-
- FileUtils.mkdir_p spec_dir
- spec_file = File.join spec_dir, 'a-1.gemspec'
-
- File.open spec_file, 'w' do |fp|
- fp.write 'raise SystemExit, "bye-bye"'
- end
-
- use_ui @ui do
- assert_raises SystemExit do
- Gem::SourceIndex.load_specification(spec_file)
+ a1_platform = quick_spec @a1.name, (@a1.version) do |s|
+ s.platform = Gem::Platform.new 'x86-my_platform1'
end
- end
-
- assert_equal '', @ui.output
- assert_equal '', @ui.error
- end
-
- def test_create_from_directory
- # TODO
- end
- def test_find_name
- assert_equal [@a1, @a2, @a3a], @source_index.find_name('a')
- assert_equal [@a2], @source_index.find_name('a', '= 2')
- assert_equal [], @source_index.find_name('bogusstring')
- assert_equal [], @source_index.find_name('a', '= 3')
-
- source_index = Gem::SourceIndex.new
- source_index.add_spec @a1
- source_index.add_spec @a2
-
- assert_equal [@a1], source_index.find_name(@a1.name, '= 1')
-
- r1 = Gem::Requirement.create '= 1'
- assert_equal [@a1], source_index.find_name(@a1.name, r1)
- end
-
- def test_find_name_empty_cache
- empty_source_index = Gem::SourceIndex.new({})
- assert_equal [], empty_source_index.find_name("foo")
- end
-
- def test_latest_specs
- p1_ruby = quick_spec 'p', '1'
- p1_platform = quick_spec 'p', '1' do |spec|
- spec.platform = Gem::Platform::CURRENT
- end
-
- a1_platform = quick_spec @a1.name, (@a1.version) do |s|
- s.platform = Gem::Platform.new 'x86-my_platform1'
- end
+ a2_platform = quick_spec @a2.name, (@a2.version) do |s|
+ s.platform = Gem::Platform.new 'x86-my_platform1'
+ end
- a2_platform = quick_spec @a2.name, (@a2.version) do |s|
- s.platform = Gem::Platform.new 'x86-my_platform1'
- end
+ a2_platform_other = quick_spec @a2.name, (@a2.version) do |s|
+ s.platform = Gem::Platform.new 'x86-other_platform1'
+ end
- a2_platform_other = quick_spec @a2.name, (@a2.version) do |s|
- s.platform = Gem::Platform.new 'x86-other_platform1'
- end
+ a3_platform_other = quick_spec @a2.name, (@a2.version.bump) do |s|
+ s.platform = Gem::Platform.new 'x86-other_platform1'
+ end
- a3_platform_other = quick_spec @a2.name, (@a2.version.bump) do |s|
- s.platform = Gem::Platform.new 'x86-other_platform1'
+ @source_index.add_spec p1_ruby
+ @source_index.add_spec p1_platform
+ @source_index.add_spec a1_platform
+ @source_index.add_spec a2_platform
+ @source_index.add_spec a2_platform_other
+ @source_index.add_spec a3_platform_other
+
+ expected = [
+ @a2.full_name,
+ a2_platform.full_name,
+ a3_platform_other.full_name,
+ @b2.full_name,
+ @c1_2.full_name,
+ @a_evil9.full_name,
+ p1_ruby.full_name,
+ p1_platform.full_name,
+ @pl1.full_name
+ ].sort
+
+ latest_specs = @source_index.latest_specs.map { |s| s.full_name }.sort
+
+ assert_equal expected, latest_specs
end
-
- @source_index.add_spec p1_ruby
- @source_index.add_spec p1_platform
- @source_index.add_spec a1_platform
- @source_index.add_spec a2_platform
- @source_index.add_spec a2_platform_other
- @source_index.add_spec a3_platform_other
-
- expected = [
- @a2.full_name,
- a2_platform.full_name,
- a3_platform_other.full_name,
- @c1_2.full_name,
- @a_evil9.full_name,
- p1_ruby.full_name,
- p1_platform.full_name,
- ].sort
-
- latest_specs = @source_index.latest_specs.map { |s| s.full_name }.sort
-
- assert_equal expected, latest_specs
end
def test_load_gems_in
- spec_dir1 = File.join @gemhome, 'specifications'
- spec_dir2 = File.join @tempdir, 'gemhome2', 'specifications'
+ Deprecate.skip_during do
+ spec_dir1 = File.join @gemhome, 'specifications'
+ spec_dir2 = File.join @tempdir, 'gemhome2', 'specifications'
- FileUtils.rm_r spec_dir1
+ FileUtils.rm_r spec_dir1
- FileUtils.mkdir_p spec_dir1
- FileUtils.mkdir_p spec_dir2
+ FileUtils.mkdir_p spec_dir1
+ FileUtils.mkdir_p spec_dir2
- a1 = quick_spec 'a', '1' do |spec| spec.author = 'author 1' end
- a2 = quick_spec 'a', '1' do |spec| spec.author = 'author 2' end
+ a1 = quick_spec 'a', '1' do |spec| spec.author = 'author 1' end
+ a2 = quick_spec 'a', '1' do |spec| spec.author = 'author 2' end
- File.open File.join(spec_dir1, a1.spec_name), 'w' do |fp|
- fp.write a1.to_ruby
- end
+ path1 = File.join(spec_dir1, a1.spec_name)
+ path2 = File.join(spec_dir2, a2.spec_name)
- File.open File.join(spec_dir2, a2.spec_name), 'w' do |fp|
- fp.write a2.to_ruby
- end
+ File.open path1, 'w' do |fp|
+ fp.write a1.to_ruby
+ end
+
+ File.open path2, 'w' do |fp|
+ fp.write a2.to_ruby
+ end
- @source_index.load_gems_in spec_dir1, spec_dir2
+ @source_index.load_gems_in File.dirname(path1), File.dirname(path2)
- assert_equal a1.author, @source_index.specification(a1.full_name).author
+ assert_equal a1.author, @source_index.specification(a1.full_name).author
+ end
end
+ # REFACTOR: move to test_gem_commands_outdated_command.rb
def test_outdated
- util_setup_spec_fetcher
+ Deprecate.skip_during do
+ util_setup_spec_fetcher
- assert_equal [], @source_index.outdated
+ assert_equal [], @source_index.outdated
- updated = quick_spec @a2.name, (@a2.version.bump)
- util_setup_spec_fetcher updated
+ updated = quick_spec @a2.name, (@a2.version.bump)
+ util_setup_spec_fetcher updated
- assert_equal [updated.name], @source_index.outdated
+ assert_equal [updated.name], @source_index.outdated
- updated_platform = quick_spec @a2.name, (updated.version.bump) do |s|
- s.platform = Gem::Platform.new 'x86-other_platform1'
- end
+ updated_platform = quick_spec @a2.name, (updated.version.bump) do |s|
+ s.platform = Gem::Platform.new 'x86-other_platform1'
+ end
- util_setup_spec_fetcher updated, updated_platform
+ util_setup_spec_fetcher updated, updated_platform
- assert_equal [updated_platform.name], @source_index.outdated
+ assert_equal [updated_platform.name], @source_index.outdated
+ end
end
def test_prerelease_specs_kept_in_right_place
- gem_a1_alpha = quick_spec 'abba', '1.a'
- @source_index.add_spec gem_a1_alpha
-
- refute @source_index.latest_specs.include?(gem_a1_alpha)
- assert @source_index.latest_specs(true).include?(gem_a1_alpha)
- assert @source_index.find_name(gem_a1_alpha.full_name).empty?
- assert @source_index.prerelease_specs.include?(gem_a1_alpha)
+ Deprecate.skip_during do
+ gem_a1_alpha = quick_spec 'abba', '1.a'
+ @source_index.add_spec gem_a1_alpha
+
+ refute_includes @source_index.latest_specs, gem_a1_alpha
+ assert_includes @source_index.latest_specs(true), gem_a1_alpha
+ assert_empty @source_index.find_name gem_a1_alpha.full_name
+ assert_includes @source_index.prerelease_specs, gem_a1_alpha
+ end
end
def test_refresh_bang
- a1_spec = File.join @gemhome, "specifications", @a1.spec_name
-
- FileUtils.mv a1_spec, @tempdir
+ Deprecate.skip_during do
+ a1_spec = File.join @gemhome, "specifications", @a1.spec_name
- source_index = Gem::SourceIndex.from_installed_gems
+ FileUtils.mv a1_spec, @tempdir
- refute source_index.gems.include?(@a1.full_name)
+ Gem::Specification.reset
+ Gem.send :class_variable_set, :@@source_index, nil
+ source_index = Gem.source_index
- FileUtils.mv File.join(@tempdir, @a1.spec_name), a1_spec
+ refute_includes source_index.gems.keys.sort, @a1.full_name
- source_index.refresh!
-
- assert source_index.gems.include?(@a1.full_name)
- end
+ FileUtils.mv File.join(@tempdir, @a1.spec_name), a1_spec
- def test_refresh_bang_not_from_dir
- source_index = Gem::SourceIndex.new
-
- e = assert_raises RuntimeError do
source_index.refresh!
- end
- assert_equal 'source index not created from disk', e.message
+ assert source_index.gems.include?(@a1.full_name)
+ end
end
def test_remove_spec
- deleted = @source_index.remove_spec 'a-1'
+ Deprecate.skip_during do
+ si = Gem.source_index
- assert_equal %w[a-2 a-3.a a_evil-9 c-1.2],
- @source_index.all_gems.values.map { |s| s.full_name }.sort
+ expected = si.gems.keys.sort
- deleted = @source_index.remove_spec 'a-3.a'
+ expected.delete "a-1"
+ @source_index.remove_spec 'a-1'
- assert_equal %w[a-2 a_evil-9 c-1.2],
- @source_index.all_gems.values.map { |s| s.full_name }.sort
+ assert_equal expected, si.gems.keys.sort
+
+ expected.delete "a-3.a"
+ @source_index.remove_spec 'a-3.a'
+
+ assert_equal expected, si.gems.keys.sort
+ end
end
def test_search
- requirement = Gem::Requirement.create '= 9'
- with_version = Gem::Dependency.new(/^a/, requirement)
- assert_equal [@a_evil9], @source_index.search(with_version)
+ Deprecate.skip_during do
+ requirement = Gem::Requirement.create '= 9'
+ with_version = Gem::Dependency.new(/^a/, requirement)
+ assert_equal [@a_evil9], @source_index.search(with_version)
- with_default = Gem::Dependency.new(/^a/, Gem::Requirement.default)
- assert_equal [@a1, @a2, @a3a, @a_evil9], @source_index.search(with_default)
+ with_default = Gem::Dependency.new(/^a/, Gem::Requirement.default)
+ assert_equal [@a1, @a2, @a3a, @a_evil9], @source_index.search(with_default)
- c1_1_dep = Gem::Dependency.new 'c', '~> 1.1'
- assert_equal [@c1_2], @source_index.search(c1_1_dep)
+ c1_1_dep = Gem::Dependency.new 'c', '~> 1.1'
+ assert_equal [@c1_2], @source_index.search(c1_1_dep)
+ end
end
def test_search_platform
- util_set_arch 'x86-my_platform1'
+ Deprecate.skip_during do
+ util_set_arch 'x86-my_platform1'
- a1 = quick_spec 'a', '1'
- a1_mine = quick_spec 'a', '1' do |s|
- s.platform = Gem::Platform.new 'x86-my_platform1'
- end
- a1_other = quick_spec 'a', '1' do |s|
- s.platform = Gem::Platform.new 'x86-other_platform1'
- end
+ a1 = quick_spec 'a', '1'
+ a1_mine = quick_spec 'a', '1' do |s|
+ s.platform = Gem::Platform.new 'x86-my_platform1'
+ end
+ a1_other = quick_spec 'a', '1' do |s|
+ s.platform = Gem::Platform.new 'x86-other_platform1'
+ end
- si = Gem::SourceIndex.new(a1.full_name => a1, a1_mine.full_name => a1_mine,
- a1_other.full_name => a1_other)
+ si = Gem::SourceIndex.new
+ si.add_specs a1, a1_mine, a1_other
- dep = Gem::Dependency.new 'a', Gem::Requirement.new('1')
+ dep = Gem::Dependency.new 'a', Gem::Requirement.new('1')
- gems = si.search dep, true
+ gems = si.search dep, true
- assert_equal [a1, a1_mine], gems.sort
+ assert_equal [a1, a1_mine], gems.sort
+ end
end
def test_signature
- sig = @source_index.gem_signature('foo-1.2.3')
- assert_equal 64, sig.length
- assert_match(/^[a-f0-9]{64}$/, sig)
+ Deprecate.skip_during do
+ sig = @source_index.gem_signature('foo-1.2.3')
+ assert_equal 64, sig.length
+ assert_match(/^[a-f0-9]{64}$/, sig)
+ end
end
def test_specification
- assert_equal @a1, @source_index.specification(@a1.full_name)
+ Deprecate.skip_during do
+ assert_equal @a1, @source_index.specification(@a1.full_name)
- assert_nil @source_index.specification("foo-1.2.4")
+ assert_nil @source_index.specification("foo-1.2.4")
+ end
end
def test_index_signature
- sig = @source_index.index_signature
- assert_match(/^[a-f0-9]{64}$/, sig)
+ Deprecate.skip_during do
+ sig = @source_index.index_signature
+ assert_match(/^[a-f0-9]{64}$/, sig)
+ end
end
-
end
-
diff --git a/test/rubygems/test_gem_spec_fetcher.rb b/test/rubygems/test_gem_spec_fetcher.rb
index de7bd9a..073b082 100644
--- a/test/rubygems/test_gem_spec_fetcher.rb
+++ b/test/rubygems/test_gem_spec_fetcher.rb
@@ -16,43 +16,43 @@ class TestGemSpecFetcher < Gem::TestCase
util_setup_fake_fetcher
- @a_pre = quick_spec 'a', '1.a'
- @source_index.add_spec @pl1
- @source_index.add_spec @a_pre
+ @a_pre = new_spec 'a', '1.a'
- @specs = @source_index.gems.sort.map do |name, spec|
- [spec.name, spec.version, spec.original_platform]
- end.sort
+ install_specs @a_pre
- @latest_specs = @source_index.latest_specs.sort.map do |spec|
- [spec.name, spec.version, spec.original_platform]
- end
+ Gem::Specification.remove_spec @b2
- @prerelease_specs = @source_index.prerelease_gems.sort.map do |name, spec|
+ @specs = Gem::Specification.map { |spec|
[spec.name, spec.version, spec.original_platform]
- end.sort
+ }.sort
- @fetcher.data["#{@gem_repo}specs.#{Gem.marshal_version}.gz"] =
- util_gzip(Marshal.dump(@specs))
+ # TODO: couldn't all of this come from the fake spec fetcher?
+ @latest_specs = Gem::Specification.latest_specs.sort.map { |spec|
+ [spec.name, spec.version, spec.original_platform]
+ }
- @fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] =
- util_gzip(Marshal.dump(@latest_specs))
+ prerelease = Gem::Specification.find_all { |s| s.version.prerelease? }
+ @prerelease_specs = prerelease.map { |spec|
+ [spec.name, spec.version, spec.original_platform]
+ }.sort
- @fetcher.data["#{@gem_repo}prerelease_specs.#{Gem.marshal_version}.gz"] =
- util_gzip(Marshal.dump(@prerelease_specs))
+ v = Gem.marshal_version
+ s_zip = util_gzip(Marshal.dump(@specs))
+ l_zip = util_gzip(Marshal.dump(@latest_specs))
+ p_zip = util_gzip(Marshal.dump(@prerelease_specs))
+ @fetcher.data["#{@gem_repo}specs.#{v}.gz"] = s_zip
+ @fetcher.data["#{@gem_repo}latest_specs.#{v}.gz"] = l_zip
+ @fetcher.data["#{@gem_repo}prerelease_specs.#{v}.gz"] = p_zip
@sf = Gem::SpecFetcher.new
end
def test_fetch_all
- @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a1.spec_name}.rz"] =
- util_zip(Marshal.dump(@a1))
- @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a2.spec_name}.rz"] =
- util_zip(Marshal.dump(@a2))
- @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a_pre.spec_name}.rz"] =
- util_zip(Marshal.dump(@a_pre))
- @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a3a.spec_name}.rz"] =
- util_zip(Marshal.dump(@a3a))
+ d = "#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}"
+ @fetcher.data["#{d}#{@a1.spec_name}.rz"] = util_zip(Marshal.dump(@a1))
+ @fetcher.data["#{d}#{@a2.spec_name}.rz"] = util_zip(Marshal.dump(@a2))
+ @fetcher.data["#{d}#{@a_pre.spec_name}.rz"] = util_zip(Marshal.dump(@a_pre))
+ @fetcher.data["#{d}#{@a3a.spec_name}.rz"] = util_zip(Marshal.dump(@a3a))
dep = Gem::Dependency.new 'a', 1
@@ -70,12 +70,10 @@ class TestGemSpecFetcher < Gem::TestCase
end
def test_fetch_latest
- @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a1.spec_name}.rz"] =
- util_zip(Marshal.dump(@a1))
- @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a2.spec_name}.rz"] =
- util_zip(Marshal.dump(@a2))
- @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a_pre.spec_name}.rz"] =
- util_zip(Marshal.dump(@a_pre))
+ d = "#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}"
+ @fetcher.data["#{d}#{@a1.spec_name}.rz"] = util_zip(Marshal.dump(@a1))
+ @fetcher.data["#{d}#{@a2.spec_name}.rz"] = util_zip(Marshal.dump(@a2))
+ @fetcher.data["#{d}#{@a_pre.spec_name}.rz"] = util_zip(Marshal.dump(@a_pre))
dep = Gem::Dependency.new 'a', 1
specs_and_sources = @sf.fetch dep
@@ -88,15 +86,12 @@ class TestGemSpecFetcher < Gem::TestCase
end
def test_fetch_prerelease
- @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a1.spec_name}.rz"] =
- util_zip(Marshal.dump(@a1))
- @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a2.spec_name}.rz"] =
- util_zip(Marshal.dump(@a2))
- @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a_pre.spec_name}.rz"] =
- util_zip(Marshal.dump(@a_pre))
+ d = "#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}"
+ @fetcher.data["#{d}#{@a1.spec_name}.rz"] = util_zip(Marshal.dump(@a1))
+ @fetcher.data["#{d}#{@a2.spec_name}.rz"] = util_zip(Marshal.dump(@a2))
+ @fetcher.data["#{d}#{@a_pre.spec_name}.rz"] = util_zip(Marshal.dump(@a_pre))
- dep = Gem::Dependency.new 'a', '1.a'
- specs_and_sources = @sf.fetch dep, false, true, true
+ specs_and_sources = @sf.fetch dep('a', '1.a'), false, true, true
spec_names = specs_and_sources.map do |spec, source_uri|
[spec.full_name, source_uri]
@@ -293,11 +288,11 @@ class TestGemSpecFetcher < Gem::TestCase
assert_equal [@uri], specs.keys
- assert_equal([["a", Gem::Version.new("1"), "ruby"],
- ["a", Gem::Version.new("2"), "ruby"],
- ["a_evil", Gem::Version.new("9"), "ruby"],
- ["c", Gem::Version.new("1.2"), "ruby"],
- ["pl", Gem::Version.new("1"), "i386-linux"]],
+ assert_equal([["a", Gem::Version.new("1"), "ruby"],
+ ["a", Gem::Version.new("2"), "ruby"],
+ ["a_evil", Gem::Version.new("9"), "ruby"],
+ ["c", Gem::Version.new("1.2"), "ruby"],
+ ["pl", Gem::Version.new("1"), "i386-linux"]],
specs[@uri].sort)
end
@@ -347,19 +342,17 @@ class TestGemSpecFetcher < Gem::TestCase
end
def test_load_specs
- specs = @sf.load_specs @uri, 'specs'
-
expected = [
- ['a', Gem::Version.new('1.a'), Gem::Platform::RUBY],
+ ['a', Gem::Version.new('1.a'), Gem::Platform::RUBY],
['a', Gem::Version.new(1), Gem::Platform::RUBY],
['a', Gem::Version.new(2), Gem::Platform::RUBY],
- ['a', Gem::Version.new('3.a'), Gem::Platform::RUBY],
+ ['a', Gem::Version.new('3.a'), Gem::Platform::RUBY],
['a_evil', Gem::Version.new(9), Gem::Platform::RUBY],
['c', Gem::Version.new('1.2'), Gem::Platform::RUBY],
['pl', Gem::Version.new(1), 'i386-linux'],
]
- assert_equal expected, specs
+ assert_equal expected, @sf.load_specs(@uri, 'specs')
cache_dir = File.join Gem.user_home, '.gem', 'specs', 'gems.example.com%80'
assert File.exist?(cache_dir), "#{cache_dir} does not exist"
diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb
index d7f5772..ef52f0a 100644
--- a/test/rubygems/test_gem_specification.rb
+++ b/test/rubygems/test_gem_specification.rb
@@ -35,8 +35,8 @@ Gem::Specification.new do |s|
s.version = %q{0.4.0}
s.has_rdoc = true
s.summary = %q{A Hash which automatically computes keys.}
- s.files = ["lib/keyedlist.rb"]
- s.require_paths = ["lib"]
+ s.files = [%q{lib/keyedlist.rb}]
+ s.require_paths = [%q{lib}]
s.autorequire = %q{keyedlist}
s.author = %q{Florian Gross}
s.email = %q{flgr@ccan.de}
@@ -46,11 +46,9 @@ end
def setup
super
- # TODO: there is no reason why the spec tests need to write to disk
- @a1 = quick_gem 'a', '1' do |s|
+ @a1 = quick_spec 'a', '1' do |s|
s.executable = 'exec'
s.extensions << 'ext/a/extconf.rb'
- s.has_rdoc = 'true'
s.test_file = 'test/suite.rb'
s.requirements << 'A working computer'
s.rubyforge_project = 'example'
@@ -64,15 +62,10 @@ end
s.files = %w[lib/code.rb]
end
- @a2 = quick_gem 'a', '2' do |s|
+ @a2 = quick_spec 'a', '2' do |s|
s.files = %w[lib/code.rb]
end
- FileUtils.mkdir_p File.join(@tempdir, 'bin')
- File.open File.join(@tempdir, 'bin', 'exec'), 'w' do |fp|
- fp.puts "#!#{Gem.ruby}"
- end
-
@current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
end
@@ -83,7 +76,6 @@ end
bindir
cert_chain
date
- default_executable
dependencies
description
email
@@ -91,7 +83,6 @@ end
extensions
extra_rdoc_files
files
- has_rdoc
homepage
licenses
name
@@ -129,18 +120,39 @@ end
assert_equal @current_version, new_spec.specification_version
end
+ def test_self_from_yaml_syck_bug
+ # This is equivalent to (and totally valid) psych 1.0 output and
+ # causes parse errors on syck.
+ yaml = @a1.to_yaml
+ yaml.sub!(/^date:.*/, "date: 2011-04-26 00:00:00.000000000Z")
+
+ new_spec = with_syck do
+ Gem::Specification.from_yaml yaml
+ end
+
+ assert_kind_of Time, @a1.date
+ assert_kind_of Time, new_spec.date
+ end
+
def test_self_load
- spec = File.join @gemhome, 'specifications', @a2.spec_name
- gs = Gem::Specification.load spec
+ full_path = @a2.spec_file
+ write_file full_path do |io|
+ io.write @a2.to_ruby_for_cache
+ end
+
+ spec = Gem::Specification.load full_path
+
+ @a2.files.clear
- assert_equal @a2, gs
+ assert_equal @a2, spec
end
def test_self_load_legacy_ruby
- spec = eval LEGACY_RUBY_SPEC
+ spec = Deprecate.skip_during do
+ eval LEGACY_RUBY_SPEC
+ end
assert_equal 'keyedlist', spec.name
assert_equal '0.4.0', spec.version.to_s
- assert_equal true, spec.has_rdoc?
assert_equal Gem::Specification::TODAY, spec.date
assert spec.required_ruby_version.satisfied_by?(Gem::Version.new('1'))
assert_equal false, spec.has_unit_tests?
@@ -195,8 +207,6 @@ end
assert_equal [], spec.requirements
assert_equal [], spec.dependencies
assert_equal 'bin', spec.bindir
- assert_equal true, spec.has_rdoc
- assert_equal true, spec.has_rdoc?
assert_equal '>= 0', spec.required_ruby_version.to_s
assert_equal '>= 0', spec.required_rubygems_version.to_s
end
@@ -279,9 +289,6 @@ end
assert_equal 'bin', spec.bindir
assert_same spec.bindir, new_spec.bindir
- assert_equal true, spec.has_rdoc
- assert_same spec.has_rdoc, new_spec.has_rdoc
-
assert_equal '>= 0', spec.required_ruby_version.to_s
assert_same spec.required_ruby_version, new_spec.required_ruby_version
@@ -290,6 +297,23 @@ end
new_spec.required_rubygems_version
end
+ def test_initialize_copy_broken
+ spec = Gem::Specification.new do |s|
+ s.name = 'a'
+ s.version = '1'
+ end
+
+ spec.instance_variable_set :@licenses, :blah
+ spec.loaded_from = '/path/to/file'
+
+ e = assert_raises Gem::FormatException do
+ spec.dup
+ end
+
+ assert_equal 'a-1 has an invalid value for @licenses', e.message
+ assert_equal '/path/to/file', e.file_path
+ end
+
def test__dump
@a2.platform = Gem::Platform.local
@a2.instance_variable_set :@original_platform, 'old_platform'
@@ -338,37 +362,33 @@ end
def test_date_equals_date
@a1.date = Date.new(2003, 9, 17)
- assert_equal Time.local(2003, 9, 17, 0,0,0), @a1.date
+ assert_equal Time.utc(2003, 9, 17, 0,0,0), @a1.date
end
def test_date_equals_string
@a1.date = '2003-09-17'
- assert_equal Time.local(2003, 9, 17, 0,0,0), @a1.date
+ assert_equal Time.utc(2003, 9, 17, 0,0,0), @a1.date
+ end
+
+ def test_date_equals_string_bad
+ assert_raises Gem::InvalidSpecificationException do
+ @a1.date = '9/11/2003'
+ end
end
def test_date_equals_time
@a1.date = Time.local(2003, 9, 17, 0,0,0)
- assert_equal Time.local(2003, 9, 17, 0,0,0), @a1.date
+ assert_equal Time.utc(2003, 9, 17, 0,0,0), @a1.date
end
def test_date_equals_time_local
- # HACK PDT
- @a1.date = Time.local(2003, 9, 17, 19,50,0)
- assert_equal Time.local(2003, 9, 17, 0,0,0), @a1.date
+ @a1.date = Time.local(2003, 9, 17, 19,50,0) # may not pass in utc >= +4
+ assert_equal Time.utc(2003, 9, 17, 0,0,0), @a1.date
end
def test_date_equals_time_utc
- # HACK PDT
- @a1.date = Time.local(2003, 9, 17, 19,50,0)
- assert_equal Time.local(2003, 9, 17, 0,0,0), @a1.date
- end
-
- def test_default_executable
- assert_equal 'exec', @a1.default_executable
-
- @a1.default_executable = nil
- @a1.instance_variable_set :@executables, nil
- assert_equal nil, @a1.default_executable
+ @a1.date = Time.utc(2003, 9, 17, 19,50,0)
+ assert_equal Time.utc(2003, 9, 17, 0,0,0), @a1.date
end
def test_dependencies
@@ -391,60 +411,20 @@ end
end
def test_eql_eh
- g1 = quick_spec 'gem'
- g2 = quick_spec 'gem'
+ g1 = new_spec 'gem', 1
+ g2 = new_spec 'gem', 1
assert_equal g1, g2
assert_equal g1.hash, g2.hash
assert_equal true, g1.eql?(g2)
end
- def test_equals2
- assert_equal @a1, @a1
- assert_equal @a1, @a1.dup
- refute_equal @a1, @a2
- refute_equal @a1, Object.new
- end
-
- # The cgikit specification was reported to be causing trouble in at least
- # one version of RubyGems, so we test explicitly for it.
- def test_equals2_cgikit
- cgikit = Gem::Specification.new do |s|
- s.name = %q{cgikit}
- s.version = "1.1.0"
- s.date = %q{2004-03-13}
- s.summary = %q{CGIKit is a componented-oriented web application } +
- %q{framework like Apple Computers WebObjects. } +
- %{This framework services Model-View-Controller architecture } +
- %q{programming by components based on a HTML file, a definition } +
- %q{file and a Ruby source. }
- s.email = %q{info@spice-of-life.net}
- s.homepage = %q{http://www.spice-of-life.net/download/cgikit/}
- s.autorequire = %q{cgikit}
- s.bindir = nil
- s.has_rdoc = true
- s.required_ruby_version = nil
- s.platform = nil
- s.files = ["lib/cgikit", "lib/cgikit.rb", "lib/cgikit/components", "..."]
- end
-
- assert_equal cgikit, cgikit
- end
-
- def test_equals2_default_executable
- spec = @a1.dup
- spec.default_executable = 'xx'
-
- refute_equal @a1, spec
- refute_equal spec, @a1
- end
-
- def test_equals2_extensions
+ def test_eql_eh_extensions
spec = @a1.dup
spec.extensions = 'xx'
- refute_equal @a1, spec
- refute_equal spec, @a1
+ refute_operator @a1, :eql?, spec
+ refute_operator spec, :eql?, @a1
end
def test_executables
@@ -542,9 +522,26 @@ end
assert_kind_of Integer, @a1.hash
end
+ def test_for_cache
+ @a2.add_runtime_dependency 'b', '1'
+ @a2.dependencies.first.instance_variable_set :@type, nil
+ @a2.required_rubygems_version = Gem::Requirement.new '> 0'
+ @a2.test_files = %w[test/test_b.rb]
+
+ refute_empty @a2.files
+ refute_empty @a2.test_files
+
+ spec = @a2.for_cache
+
+ assert_empty spec.files
+ assert_empty spec.test_files
+
+ refute_empty @a2.files
+ refute_empty @a2.test_files
+ end
+
def test_full_gem_path
- assert_equal File.join(@gemhome, 'gems', @a1.full_name),
- @a1.full_gem_path
+ assert_equal File.join(@gemhome, 'gems', @a1.full_name), @a1.full_gem_path
@a1.original_platform = 'mswin32'
@@ -553,11 +550,11 @@ end
end
def test_full_gem_path_double_slash
- gemhome = @gemhome.sub(/\w\//, '\&/')
- @a1.loaded_from = File.join gemhome, 'specifications', @a1.spec_name
+ gemhome = @gemhome.to_s.sub(/\w\//, '\&/')
+ @a1.loaded_from = File.join gemhome, "specifications", @a1.spec_name
- assert_equal File.join(@gemhome, 'gems', @a1.full_name),
- @a1.full_gem_path
+ expected = File.join @gemhome, "gems", @a1.full_name
+ assert_equal expected, @a1.full_gem_path
end
def test_full_name
@@ -589,21 +586,6 @@ end
end
end
- def test_has_rdoc_eh
- assert @a1.has_rdoc?
- end
-
- def test_has_rdoc_equals
-
- use_ui @ui do
- @a1.has_rdoc = false
- end
-
- assert_equal '', @ui.output
-
- assert_equal true, @a1.has_rdoc
- end
-
def test_hash
assert_equal @a1.hash, @a1.hash
assert_equal @a1.hash, @a1.dup.hash
@@ -611,15 +593,14 @@ end
end
def test_installation_path
- assert_equal @gemhome, @a1.installation_path
+ Deprecate.skip_during do
+ assert_equal @gemhome, @a1.installation_path
- @a1.instance_variable_set :@loaded_from, nil
+ @a1.instance_variable_set :@loaded_from, nil
+ @a1.instance_variable_set :@loaded, false
- e = assert_raises Gem::Exception do
- @a1.installation_path
+ assert_nil @a1.installation_path
end
-
- assert_equal 'spec a-1 is not from an installed gem', e.message
end
def test_lib_files
@@ -717,8 +698,8 @@ end
end
def test_spaceship_name
- s1 = quick_spec 'a', '1'
- s2 = quick_spec 'b', '1'
+ s1 = new_spec 'a', '1'
+ s2 = new_spec 'b', '1'
assert_equal(-1, (s1 <=> s2))
assert_equal( 0, (s1 <=> s1))
@@ -726,8 +707,8 @@ end
end
def test_spaceship_platform
- s1 = quick_spec 'a', '1'
- s2 = quick_spec 'a', '1' do |s|
+ s1 = new_spec 'a', '1'
+ s2 = new_spec 'a', '1' do |s|
s.platform = Gem::Platform.new 'x86-my_platform1'
end
@@ -737,8 +718,8 @@ end
end
def test_spaceship_version
- s1 = quick_spec 'a', '1'
- s2 = quick_spec 'a', '2'
+ s1 = new_spec 'a', '1'
+ s2 = new_spec 'a', '2'
assert_equal( -1, (s1 <=> s2))
assert_equal( 0, (s1 <=> s1))
@@ -773,13 +754,13 @@ Gem::Specification.new do |s|
s.version = \"2\"
s.required_rubygems_version = Gem::Requirement.new(\"> 0\") if s.respond_to? :required_rubygems_version=
- s.authors = [\"A User\"]
+ s.authors = [%q{A User}]
s.date = %q{#{Gem::Specification::TODAY.strftime "%Y-%m-%d"}}
s.description = %q{This is a test description}
s.email = %q{example@example.com}
- s.files = [\"lib/code.rb\"]
+ s.files = [%q{lib/code.rb}]
s.homepage = %q{http://example.com}
- s.require_paths = [\"lib\"]
+ s.require_paths = [%q{lib}]
s.rubygems_version = %q{#{Gem::VERSION}}
s.summary = %q{this is a summary}
@@ -820,12 +801,12 @@ Gem::Specification.new do |s|
s.version = \"2\"
s.required_rubygems_version = Gem::Requirement.new(\"> 0\") if s.respond_to? :required_rubygems_version=
- s.authors = [\"A User\"]
+ s.authors = [%q{A User}]
s.date = %q{#{Gem::Specification::TODAY.strftime "%Y-%m-%d"}}
s.description = %q{This is a test description}
s.email = %q{example@example.com}
s.homepage = %q{http://example.com}
- s.require_paths = [\"lib\"]
+ s.require_paths = [%q{lib}]
s.rubygems_version = %q{#{Gem::VERSION}}
s.summary = %q{this is a summary}
@@ -868,22 +849,21 @@ Gem::Specification.new do |s|
s.platform = Gem::Platform.new(#{expected_platform})
s.required_rubygems_version = Gem::Requirement.new(\">= 0\") if s.respond_to? :required_rubygems_version=
- s.authors = [\"A User\"]
+ s.authors = [%q{A User}]
s.date = %q{#{Gem::Specification::TODAY.strftime "%Y-%m-%d"}}
- s.default_executable = %q{exec}
s.description = %q{This is a test description}
s.email = %q{example@example.com}
- s.executables = [\"exec\"]
- s.extensions = [\"ext/a/extconf.rb\"]
- s.files = [\"lib/code.rb\", \"test/suite.rb\", \"bin/exec\", \"ext/a/extconf.rb\"]
+ s.executables = [%q{exec}]
+ s.extensions = [%q{ext/a/extconf.rb}]
+ s.files = [%q{lib/code.rb}, %q{test/suite.rb}, %q{bin/exec}, %q{ext/a/extconf.rb}]
s.homepage = %q{http://example.com}
- s.licenses = [\"MIT\"]
- s.require_paths = [\"lib\"]
- s.requirements = [\"A working computer\"]
+ s.licenses = [%q{MIT}]
+ s.require_paths = [%q{lib}]
+ s.requirements = [%q{A working computer}]
s.rubyforge_project = %q{example}
s.rubygems_version = %q{#{Gem::VERSION}}
s.summary = %q{this is a summary}
- s.test_files = [\"test/suite.rb\"]
+ s.test_files = [%q{test/suite.rb}]
if s.respond_to? :specification_version then
s.specification_version = 3
@@ -913,7 +893,9 @@ end
end
def test_to_ruby_legacy
- gemspec1 = eval LEGACY_RUBY_SPEC
+ gemspec1 = Deprecate.skip_during do
+ eval LEGACY_RUBY_SPEC
+ end
ruby_code = gemspec1.to_ruby
gemspec2 = eval ruby_code
@@ -936,7 +918,7 @@ end
refute_match '!!null', yaml_str
- same_spec = YAML.load(yaml_str)
+ same_spec = Gem::Specification.from_yaml(yaml_str)
assert_equal @a1, same_spec
end
@@ -945,7 +927,7 @@ end
@a1.platform = Gem::Platform.local
yaml_str = @a1.to_yaml
- same_spec = YAML.load(yaml_str)
+ same_spec = Gem::Specification.from_yaml(yaml_str)
assert_equal Gem::Platform.local, same_spec.platform
@@ -984,41 +966,48 @@ end
end
end
+ def x s; s.gsub(/xxx/, ''); end
+ def w; x "WARxxxNING"; end
+ def t; x "TOxxxDO"; end
+ def f; x "FxxxIXME"; end
+
def test_validate_authors
util_setup_validate
Dir.chdir @tempdir do
- @a1.authors = []
+ @a1.authors = [""]
use_ui @ui do
@a1.validate
end
- assert_equal "WARNING: no author specified\n", @ui.error, 'error'
+ assert_equal "#{w}: no author specified\n", @ui.error, 'error'
@a1.authors = [Object.new]
+ assert_equal [], @a1.authors
+
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
- assert_equal 'authors must be Array of Strings', e.message
+ assert_equal "authors may not be empty", e.message
- @a1.authors = ['FIXME (who is writing this software)']
+ @a1.authors = ["#{f} (who is writing this software)"]
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
- assert_equal '"FIXME" or "TODO" is not an author', e.message
+ assert_equal %{"#{f}" or "#{t}" is not an author}, e.message
- @a1.authors = ['TODO (who is writing this software)']
+ @a1.authors = ["#{t} (who is writing this software)"]
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
- assert_equal '"FIXME" or "TODO" is not an author', e.message
+ assert_equal %{"#{f}" or "#{t}" is not an author}, e.message
end
end
@@ -1032,7 +1021,7 @@ end
@a1.validate
end
- assert_equal "WARNING: deprecated autorequire specified\n",
+ assert_equal "#{w}: deprecated autorequire specified\n",
@ui.error, 'error'
end
end
@@ -1047,34 +1036,34 @@ end
@a1.validate
end
- assert_equal "WARNING: no description specified\n", @ui.error, 'error'
+ assert_equal "#{w}: no description specified\n", @ui.error, "error"
@ui = Gem::MockGemUi.new
- @a1.summary = 'this is my summary'
+ @a1.summary = "this is my summary"
@a1.description = @a1.summary
use_ui @ui do
@a1.validate
end
- assert_equal "WARNING: description and summary are identical\n",
- @ui.error, 'error'
+ assert_equal "#{w}: description and summary are identical\n",
+ @ui.error, "error"
- @a1.description = 'FIXME (describe your package)'
+ @a1.description = "#{f} (describe your package)"
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
- assert_equal '"FIXME" or "TODO" is not a description', e.message
+ assert_equal %{"#{f}" or "#{t}" is not a description}, e.message
- @a1.description = 'TODO (describe your package)'
+ @a1.description = "#{t} (describe your package)"
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
- assert_equal '"FIXME" or "TODO" is not a description', e.message
+ assert_equal %{"#{f}" or "#{t}" is not a description}, e.message
end
end
@@ -1082,35 +1071,33 @@ end
util_setup_validate
Dir.chdir @tempdir do
- @a1.email = ''
+ @a1.email = ""
use_ui @ui do
@a1.validate
end
- assert_equal "WARNING: no email specified\n", @ui.error, 'error'
+ assert_equal "#{w}: no email specified\n", @ui.error, "error"
- @a1.email = 'FIXME (your e-mail)'
+ @a1.email = "FIxxxXME (your e-mail)".sub(/xxx/, "")
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
- assert_equal '"FIXME" or "TODO" is not an email address', e.message
+ assert_equal %{"#{f}" or "#{t}" is not an email}, e.message
- @a1.email = 'TODO (your e-mail)'
+ @a1.email = "#{t} (your e-mail)"
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
- assert_equal '"FIXME" or "TODO" is not an email address', e.message
+ assert_equal %{"#{f}" or "#{t}" is not an email}, e.message
end
end
def test_validate_empty
- util_setup_validate
-
e = assert_raises Gem::InvalidSpecificationException do
Gem::Specification.new.validate
end
@@ -1134,7 +1121,7 @@ end
assert_equal %w[exec], @a1.executables
assert_equal '', @ui.output, 'output'
- assert_equal "WARNING: bin/exec is missing #! line\n", @ui.error, 'error'
+ assert_equal "#{w}: bin/exec is missing #! line\n", @ui.error, 'error'
end
def test_validate_empty_require_paths
@@ -1183,7 +1170,7 @@ end
@a1.validate
end
- assert_equal "WARNING: no homepage specified\n", @ui.error, 'error'
+ assert_equal "#{w}: no homepage specified\n", @ui.error, 'error'
@ui = Gem::MockGemUi.new
@@ -1193,7 +1180,7 @@ end
@a1.validate
end
- assert_equal "WARNING: no homepage specified\n", @ui.error, 'error'
+ assert_equal "#{w}: no homepage specified\n", @ui.error, 'error'
@a1.homepage = 'over at my cool site'
@@ -1216,6 +1203,26 @@ end
assert_equal 'invalid value for attribute name: ":json"', e.message
end
+ def test_validate_non_nil
+ util_setup_validate
+
+ Dir.chdir @tempdir do
+ assert @a1.validate
+
+ Gem::Specification.non_nil_attributes.each do |name|
+ next if name == :files # set by #normalize
+ spec = @a1.dup
+ spec.instance_variable_set "@#{name}", nil
+
+ e = assert_raises Gem::InvalidSpecificationException do
+ spec.validate
+ end
+
+ assert_match %r%^#{name}%, e.message
+ end
+ end
+ end
+
def test_validate_platform_legacy
util_setup_validate
@@ -1270,23 +1277,23 @@ end
@a1.validate
end
- assert_equal "WARNING: no summary specified\n", @ui.error, 'error'
+ assert_equal "#{w}: no summary specified\n", @ui.error, 'error'
- @a1.summary = 'FIXME (describe your package)'
+ @a1.summary = "#{f} (describe your package)"
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
- assert_equal '"FIXME" or "TODO" is not a summary', e.message
+ assert_equal %{"#{f}" or "#{t}" is not a summary}, e.message
- @a1.summary = 'TODO (describe your package)'
+ @a1.summary = "#{t} (describe your package)"
e = assert_raises Gem::InvalidSpecificationException do
@a1.validate
end
- assert_equal '"FIXME" or "TODO" is not a summary', e.message
+ assert_equal %{"#{f}" or "#{t}" is not a summary}, e.message
end
end
@@ -1310,6 +1317,67 @@ end
specfile.delete
end
+ ##
+ # KEEP p-1-x86-darwin-8
+ # KEEP p-1
+ # KEEP c-1.2
+ # KEEP a_evil-9
+ # a-1
+ # a-1-x86-my_platform-1
+ # KEEP a-2
+ # a-2-x86-other_platform-1
+ # KEEP a-2-x86-my_platform-1
+ # a-3.a
+ # KEEP a-3-x86-other_platform-1
+
+ def test_latest_specs
+ util_clear_gems
+ util_setup_fake_fetcher
+
+ quick_spec 'p', '1'
+
+ p1_curr = quick_spec 'p', '1' do |spec|
+ spec.platform = Gem::Platform::CURRENT
+ end
+
+ quick_spec @a1.name, @a1.version do |s|
+ s.platform = Gem::Platform.new 'x86-my_platform1'
+ end
+
+ quick_spec @a1.name, @a1.version do |s|
+ s.platform = Gem::Platform.new 'x86-third_platform1'
+ end
+
+ quick_spec @a2.name, @a2.version do |s|
+ s.platform = Gem::Platform.new 'x86-my_platform1'
+ end
+
+ quick_spec @a2.name, @a2.version do |s|
+ s.platform = Gem::Platform.new 'x86-other_platform1'
+ end
+
+ quick_spec @a2.name, @a2.version.bump do |s|
+ s.platform = Gem::Platform.new 'x86-other_platform1'
+ end
+
+ Gem::Specification.remove_spec @b2
+ Gem::Specification.remove_spec @pl1
+
+ expected = %W[
+ a-2
+ a-2-x86-my_platform-1
+ a-3-x86-other_platform-1
+ a_evil-9
+ c-1.2
+ p-1
+ #{p1_curr.full_name}
+ ]
+
+ latest_specs = Gem::Specification.latest_specs.map(&:full_name).sort
+
+ assert_equal expected, latest_specs
+ end
+
def util_setup_deps
@gem = quick_spec "awesome", "1.0" do |awesome|
awesome.add_runtime_dependency "bonobo", []
@@ -1322,13 +1390,36 @@ end
def util_setup_validate
Dir.chdir @tempdir do
- FileUtils.mkdir_p File.join('ext', 'a')
- FileUtils.mkdir_p 'lib'
- FileUtils.mkdir_p 'test'
+ FileUtils.mkdir_p File.join("ext", "a")
+ FileUtils.mkdir_p "lib"
+ FileUtils.mkdir_p "test"
+ FileUtils.mkdir_p "bin"
+
+ FileUtils.touch File.join("ext", "a", "extconf.rb")
+ FileUtils.touch File.join("lib", "code.rb")
+ FileUtils.touch File.join("test", "suite.rb")
- FileUtils.touch File.join('ext', 'a', 'extconf.rb')
- FileUtils.touch File.join('lib', 'code.rb')
- FileUtils.touch File.join('test', 'suite.rb')
+ File.open "bin/exec", "w" do |fp|
+ fp.puts "#!#{Gem.ruby}"
+ end
+ end
+ end
+
+ def with_syck
+ begin
+ require "yaml"
+ old_engine = YAML::ENGINE.yamler
+ YAML::ENGINE.yamler = 'syck'
+ rescue NameError
+ # probably on 1.8, ignore
+ end
+
+ yield
+ ensure
+ begin
+ YAML::ENGINE.yamler = old_engine
+ rescue NameError
+ # ignore
end
end
end
diff --git a/test/rubygems/test_gem_text.rb b/test/rubygems/test_gem_text.rb
index 775f1e9..7324e42 100644
--- a/test/rubygems/test_gem_text.rb
+++ b/test/rubygems/test_gem_text.rb
@@ -26,6 +26,21 @@ class TestGemText < Gem::TestCase
assert_equal " text to wrap", format_text("text to wrap", 40, 2)
end
+ def test_format_text_trailing # for two spaces after .
+ text = <<-TEXT
+This line is really, really long. So long, in fact, that it is more than eighty characters long! The purpose of this line is for testing wrapping behavior because sometimes people don't wrap their text to eighty characters. Without the wrapping, the text might not look good in the RSS feed.
+ TEXT
+
+ expected = <<-EXPECTED
+This line is really, really long. So long, in fact, that it is more than
+eighty characters long! The purpose of this line is for testing wrapping
+behavior because sometimes people don't wrap their text to eighty characters.
+Without the wrapping, the text might not look good in the RSS feed.
+ EXPECTED
+
+ assert_equal expected, format_text(text, 78)
+ end
+
def test_levenshtein_distance_add
assert_equal 2, levenshtein_distance("zentest", "zntst")
assert_equal 2, levenshtein_distance("zntst", "zentest")
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
diff --git a/test/rubygems/test_kernel.rb b/test/rubygems/test_kernel.rb
index d3714a2..32658c5 100644
--- a/test/rubygems/test_kernel.rb
+++ b/test/rubygems/test_kernel.rb
@@ -46,10 +46,9 @@ class TestKernel < Gem::TestCase
gem 'a', '= 2'
end
- assert_match(/activate a \(= 2\)/, ex.message)
+ assert_equal "can't activate a-2, already activated a-1", ex.message
assert_match(/activated a-1/, ex.message)
assert_equal 'a', ex.name
- assert_equal Gem::Requirement.new('= 2'), ex.requirement
assert $:.any? { |p| %r{a-1/lib} =~ p }
refute $:.any? { |p| %r{a-2/lib} =~ p }