summaryrefslogtreecommitdiff
path: root/test/rubygems/test_gem.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/rubygems/test_gem.rb')
-rw-r--r--test/rubygems/test_gem.rb277
1 files changed, 132 insertions, 145 deletions
diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb
index 118066b957..96077117e2 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