summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/rubygems/simple_gem.rb2
-rw-r--r--test/rubygems/test_gem.rb65
-rw-r--r--test/rubygems/test_gem_available_set.rb3
-rw-r--r--test/rubygems/test_gem_commands_cleanup_command.rb11
-rw-r--r--test/rubygems/test_gem_commands_dependency_command.rb10
-rw-r--r--test/rubygems/test_gem_commands_install_command.rb44
-rw-r--r--test/rubygems/test_gem_commands_mirror.rb13
-rw-r--r--test/rubygems/test_gem_commands_outdated_command.rb5
-rw-r--r--test/rubygems/test_gem_commands_pristine_command.rb14
-rw-r--r--test/rubygems/test_gem_commands_query_command.rb281
-rw-r--r--test/rubygems/test_gem_commands_specification_command.rb8
-rw-r--r--test/rubygems/test_gem_commands_stale_command.rb2
-rw-r--r--test/rubygems/test_gem_commands_uninstall_command.rb8
-rw-r--r--test/rubygems/test_gem_commands_unpack_command.rb10
-rw-r--r--test/rubygems/test_gem_commands_update_command.rb74
-rw-r--r--test/rubygems/test_gem_commands_which_command.rb1
-rw-r--r--test/rubygems/test_gem_dependency.rb10
-rw-r--r--test/rubygems/test_gem_dependency_installer.rb10
-rw-r--r--test/rubygems/test_gem_doctor.rb2
-rw-r--r--test/rubygems/test_gem_ext_configure_builder.rb12
-rw-r--r--test/rubygems/test_gem_ext_ext_conf_builder.rb40
-rw-r--r--test/rubygems/test_gem_indexer.rb2
-rw-r--r--test/rubygems/test_gem_install_update_options.rb4
-rw-r--r--test/rubygems/test_gem_installer.rb58
-rw-r--r--test/rubygems/test_gem_package.rb47
-rw-r--r--test/rubygems/test_gem_package_tar_reader_entry.rb9
-rw-r--r--test/rubygems/test_gem_package_tar_writer.rb11
-rw-r--r--test/rubygems/test_gem_request_connection_pools.rb9
-rw-r--r--test/rubygems/test_gem_request_set.rb13
-rw-r--r--test/rubygems/test_gem_request_set_lockfile.rb6
-rw-r--r--test/rubygems/test_gem_resolver.rb43
-rw-r--r--test/rubygems/test_gem_resolver_installer_set.rb18
-rw-r--r--test/rubygems/test_gem_resolver_lock_specification.rb5
-rw-r--r--test/rubygems/test_gem_specification.rb334
-rw-r--r--test/rubygems/test_gem_stub_specification.rb27
-rw-r--r--test/rubygems/test_gem_uninstaller.rb3
-rw-r--r--test/rubygems/test_gem_util.rb8
-rw-r--r--test/rubygems/test_require.rb251
38 files changed, 883 insertions, 590 deletions
diff --git a/test/rubygems/simple_gem.rb b/test/rubygems/simple_gem.rb
index d7c0356..c40002e 100644
--- a/test/rubygems/simple_gem.rb
+++ b/test/rubygems/simple_gem.rb
@@ -16,7 +16,7 @@ SIMPLE_GEM = <<-GEMDATA
@directory = options[:directory] || Gem.dir
@force = options[:force]
- gem = Gem::Installer.new(__FILE__).install(@force, @directory)
+ gem = Gem::Installer.at(__FILE__).install(@force, @directory)
if options[:gen_rdoc]
Gem::DocManager.new(gem).generate_rdoc
end
diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb
index 0428bea..0c5ac51 100644
--- a/test/rubygems/test_gem.rb
+++ b/test/rubygems/test_gem.rb
@@ -37,7 +37,7 @@ class TestGem < Gem::TestCase
c1 = new_spec "c", "1"
c2 = new_spec "c", "2"
- install_specs a1, b1, b2, c1, c2
+ install_specs c1, c2, b1, b2, a1
a1.activate
@@ -61,7 +61,7 @@ class TestGem < Gem::TestCase
d1 = new_spec "d", "1", { "c" => "< 2" }, "lib/d.rb"
d2 = new_spec "d", "2", { "c" => "< 2" }, "lib/d.rb" # this
- install_specs a1, b1, b2, c1, c2, d1, d2
+ install_specs c1, c2, b1, b2, d1, d2, a1
a1.activate
@@ -90,6 +90,23 @@ class TestGem < Gem::TestCase
assert_path_exists File.join(gemhome2, 'gems', 'a-1')
end
+ def test_self_install_in_rescue
+ spec_fetcher do |f|
+ f.gem 'a', 1
+ f.spec 'a', 2
+ end
+
+ gemhome2 = "#{@gemhome}2"
+
+ installed =
+ begin
+ raise 'Error'
+ rescue StandardError
+ Gem.install 'a', '= 1', :install_dir => gemhome2
+ end
+ assert_equal %w[a-1], installed.map { |spec| spec.full_name }
+ end
+
def test_require_missing
save_loaded_features do
assert_raises ::LoadError do
@@ -135,12 +152,12 @@ class TestGem < Gem::TestCase
end
def test_self_bin_path_bin_name
- util_exec_gem
+ install_specs util_exec_gem
assert_equal @abin_path, Gem.bin_path('a', 'abin')
end
def test_self_bin_path_bin_name_version
- util_exec_gem
+ install_specs util_exec_gem
assert_equal @abin_path, Gem.bin_path('a', 'abin', '4')
end
@@ -167,10 +184,11 @@ class TestGem < Gem::TestCase
end
def test_self_bin_path_bin_file_gone_in_latest
- util_exec_gem
- util_spec 'a', '10' do |s|
+ install_specs util_exec_gem
+ spec = util_spec 'a', '10' do |s|
s.executables = []
end
+ install_specs spec
# Should not find a-10's non-abin (bug)
assert_equal @abin_path, Gem.bin_path('a', 'abin')
end
@@ -881,9 +899,23 @@ class TestGem < Gem::TestCase
assert_equal %w[http://gems.example.com/], Gem.sources
end
+ def test_try_activate_returns_true_for_activated_specs
+ b = util_spec 'b', '1.0' do |spec|
+ spec.files << 'lib/b.rb'
+ end
+ install_specs b
+
+ assert Gem.try_activate('b'), 'try_activate should return true'
+ assert Gem.try_activate('b'), 'try_activate should still return true'
+ end
+
def test_self_try_activate_missing_dep
+ b = util_spec 'b', '1.0'
a = util_spec 'a', '1.0', 'b' => '>= 1.0'
+ install_specs b, a
+ uninstall_gem b
+
a_file = File.join a.gem_dir, 'lib', 'a_file.rb'
write_file a_file do |io|
@@ -898,12 +930,17 @@ class TestGem < Gem::TestCase
end
def test_self_try_activate_missing_extensions
- util_spec 'ext', '1' do |s|
+ spec = util_spec 'ext', '1' do |s|
s.extensions = %w[ext/extconf.rb]
s.mark_version
s.installed_by_version = v('2.2')
end
+ # write the spec without install to simulate a failed install
+ write_file spec.spec_file do |io|
+ io.write spec.to_ruby_for_cache
+ end
+
_, err = capture_io do
refute Gem.try_activate 'nonexistent'
end
@@ -944,7 +981,7 @@ class TestGem < Gem::TestCase
b = util_spec "b", "1", "c" => nil
c = util_spec "c", "2"
- install_specs a, b, c
+ install_specs a, c, b
Gem.needs do |r|
r.gem "a"
@@ -966,7 +1003,7 @@ class TestGem < Gem::TestCase
d = new_spec "d", "1", {'e' => '= 1'}, "lib/d.rb"
e = util_spec "e", "1"
- install_specs a, b, c, d, e
+ install_specs a, c, b, e, d
Gem.needs do |r|
r.gem "a"
@@ -1372,16 +1409,21 @@ class TestGem < Gem::TestCase
def test_use_gemdeps
gem_deps_file = 'gem.deps.rb'.untaint
spec = util_spec 'a', 1
+ install_specs spec
+ spec = Gem::Specification.find { |s| s == spec }
refute spec.activated?
open gem_deps_file, 'w' do |io|
io.write 'gem "a"'
end
+ assert_nil Gem.gemdeps
+
Gem.use_gemdeps gem_deps_file
assert spec.activated?
+ refute_nil Gem.gemdeps
end
def test_use_gemdeps_ENV
@@ -1430,6 +1472,8 @@ class TestGem < Gem::TestCase
rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], '-'
spec = util_spec 'a', 1
+ install_specs spec
+ spec = Gem::Specification.find { |s| s == spec }
refute spec.activated?
@@ -1499,7 +1543,9 @@ You may need to `gem install -g` to install missing gems
rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], 'x'
spec = util_spec 'a', 1
+ install_specs spec
+ spec = Gem::Specification.find { |s| s == spec }
refute spec.activated?
open 'x', 'w' do |io|
@@ -1560,6 +1606,7 @@ You may need to `gem install -g` to install missing gems
@exec_path = File.join spec.full_gem_path, spec.bindir, 'exec'
@abin_path = File.join spec.full_gem_path, spec.bindir, 'abin'
+ spec
end
def util_remove_interrupt_command
diff --git a/test/rubygems/test_gem_available_set.rb b/test/rubygems/test_gem_available_set.rb
index 2b51544..8b01112 100644
--- a/test/rubygems/test_gem_available_set.rb
+++ b/test/rubygems/test_gem_available_set.rb
@@ -79,7 +79,8 @@ class TestGemAvailableSet < Gem::TestCase
end
def test_remove_installed_bang
- a1, _ = util_gem 'a', '1'
+ a1, _ = util_spec 'a', '1'
+ install_specs a1
a1.activate
diff --git a/test/rubygems/test_gem_commands_cleanup_command.rb b/test/rubygems/test_gem_commands_cleanup_command.rb
index fdaac54..e8ad35f 100644
--- a/test/rubygems/test_gem_commands_cleanup_command.rb
+++ b/test/rubygems/test_gem_commands_cleanup_command.rb
@@ -1,5 +1,6 @@
require 'rubygems/test_case'
require 'rubygems/commands/cleanup_command'
+require 'rubygems/installer'
class TestGemCommandsCleanupCommand < Gem::TestCase
@@ -78,8 +79,8 @@ class TestGemCommandsCleanupCommand < Gem::TestCase
end
def test_execute_all_user
- @a_1_1 = util_spec 'a', '1.1'
- @a_1_1 = install_gem_user @a_1_1 # pick up user install path
+ @a_1_1, = util_gem 'a', '1.1'
+ @a_1_1 = install_gem @a_1_1 # pick up user install path
Gem::Specification.dirs = [Gem.dir, Gem.user_dir]
@@ -97,8 +98,8 @@ class TestGemCommandsCleanupCommand < Gem::TestCase
def test_execute_all_user_no_sudo
FileUtils.chmod 0555, @gemhome
- @a_1_1 = util_spec 'a', '1.1'
- @a_1_1 = install_gem_user @a_1_1 # pick up user install path
+ @a_1_1, = util_gem 'a', '1.1'
+ @a_1_1 = install_gem @a_1_1, :user_install => true # pick up user install path
Gem::Specification.dirs = [Gem.dir, Gem.user_dir]
@@ -132,9 +133,9 @@ class TestGemCommandsCleanupCommand < Gem::TestCase
s.add_dependency 'b', '1'
end
- install_gem @c
install_gem @b_1
install_gem @b_2
+ install_gem @c
@cmd.options[:args] = []
diff --git a/test/rubygems/test_gem_commands_dependency_command.rb b/test/rubygems/test_gem_commands_dependency_command.rb
index e22b240..1409162 100644
--- a/test/rubygems/test_gem_commands_dependency_command.rb
+++ b/test/rubygems/test_gem_commands_dependency_command.rb
@@ -28,6 +28,8 @@ class TestGemCommandsDependencyCommand < Gem::TestCase
end
def test_execute_no_args
+ install_specs new_spec 'x', '2'
+
spec_fetcher do |fetcher|
fetcher.spec 'a', 1
fetcher.spec 'a', '2.a'
@@ -51,6 +53,8 @@ Gem dep_x-1
Gem pl-1-x86-linux
+Gem x-2
+
EOF
assert_equal expected, @ui.output
@@ -71,9 +75,11 @@ Gem pl-1-x86-linux
end
def test_execute_pipe_format
- util_spec 'foo' do |gem|
+ spec = util_spec 'foo' do |gem|
gem.add_dependency 'bar', '> 1'
end
+ install_specs util_spec 'bar', 2
+ install_specs spec
@cmd.options[:args] = %w[foo]
@cmd.options[:pipe_format] = true
@@ -164,6 +170,8 @@ ERROR: Only reverse dependencies for local gems are supported.
end
def test_execute_remote
+ install_specs new_spec 'bar', '2'
+
spec_fetcher do |fetcher|
fetcher.spec 'foo', 2, 'bar' => '> 1'
end
diff --git a/test/rubygems/test_gem_commands_install_command.rb b/test/rubygems/test_gem_commands_install_command.rb
index f03285a..b3062b4 100644
--- a/test/rubygems/test_gem_commands_install_command.rb
+++ b/test/rubygems/test_gem_commands_install_command.rb
@@ -251,8 +251,7 @@ ERROR: Possible alternatives: non_existent_with_hint
correctly_spelled = "nonexistent-with_hint"
spec_fetcher do |fetcher|
- fetcher.spec correctly_spelled, 2
- fetcher.clear
+ fetcher.download correctly_spelled, 2
end
@cmd.options[:args] = [misspelled]
@@ -310,9 +309,8 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_execute_prerelease_wins_over_previous_ver
spec_fetcher do |fetcher|
- fetcher.gem 'a', 1
- fetcher.gem 'a', '2.a'
- fetcher.clear
+ fetcher.download 'a', 1
+ fetcher.download 'a', '2.a'
end
@cmd.options[:prerelease] = true
@@ -535,9 +533,7 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_execute_conservative
spec_fetcher do |fetcher|
- fetcher.gem 'b', 2
-
- fetcher.clear
+ fetcher.download 'b', 2
fetcher.gem 'a', 2
end
@@ -665,8 +661,7 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_show_source_problems_even_on_success
spec_fetcher do |fetcher|
- fetcher.gem 'a', 2
- fetcher.clear
+ fetcher.download 'a', 2
end
Gem.sources << "http://nonexistent.example"
@@ -738,8 +733,7 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_execute_installs_from_a_gemdeps_with_conservative
spec_fetcher do |fetcher|
- fetcher.gem 'a', 2
- fetcher.clear
+ fetcher.download 'a', 2
fetcher.gem 'a', 1
end
@@ -763,8 +757,7 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_execute_installs_from_a_gemdeps
spec_fetcher do |fetcher|
- fetcher.gem 'a', 2
- fetcher.clear
+ fetcher.download 'a', 2
end
File.open @gemdeps, "w" do |f|
@@ -786,9 +779,8 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_execute_installs_deps_a_gemdeps
spec_fetcher do |fetcher|
- fetcher.gem 'q', '1.0'
- fetcher.gem 'r', '2.0', 'q' => nil
- fetcher.clear
+ fetcher.download 'q', '1.0'
+ fetcher.download 'r', '2.0', 'q' => nil
end
File.open @gemdeps, "w" do |f|
@@ -813,9 +805,7 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_execute_uses_deps_a_gemdeps
spec_fetcher do |fetcher|
- fetcher.gem 'r', '2.0', 'q' => nil
-
- fetcher.clear
+ fetcher.download 'r', '2.0', 'q' => nil
fetcher.spec 'q', '1.0'
end
@@ -842,9 +832,8 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_execute_installs_deps_a_gemdeps_into_a_path
spec_fetcher do |fetcher|
- fetcher.gem 'q', '1.0'
- fetcher.gem 'r', '2.0', 'q' => nil
- fetcher.clear
+ fetcher.download 'q', '1.0'
+ fetcher.download 'r', '2.0', 'q' => nil
end
File.open @gemdeps, "w" do |f|
@@ -873,12 +862,11 @@ ERROR: Possible alternatives: non_existent_with_hint
def test_execute_with_gemdeps_path_ignores_system
specs = spec_fetcher do |fetcher|
- fetcher.gem 'q', '1.0'
- fetcher.gem 'r', '2.0', 'q' => nil
- fetcher.clear
+ fetcher.download 'q', '1.0'
+ fetcher.download 'r', '2.0', 'q' => nil
end
- Gem::Specification.add_specs specs['q-1.0']
+ install_specs specs['q-1.0']
File.open @gemdeps, "w" do |f|
f << "gem 'r'"
@@ -910,7 +898,7 @@ ERROR: Possible alternatives: non_existent_with_hint
fetcher.gem 'r', '2.0', 'q' => nil
end
- i = Gem::Installer.new specs['q-1.0'].cache_file, :install_dir => "gf-path"
+ i = Gem::Installer.at specs['q-1.0'].cache_file, :install_dir => "gf-path"
i.install
assert File.file?("gf-path/specifications/q-1.0.gemspec"), "not installed"
diff --git a/test/rubygems/test_gem_commands_mirror.rb b/test/rubygems/test_gem_commands_mirror.rb
index 2f6fe52..3b01ab3 100644
--- a/test/rubygems/test_gem_commands_mirror.rb
+++ b/test/rubygems/test_gem_commands_mirror.rb
@@ -2,23 +2,10 @@ require 'rubygems/test_case'
require 'rubygems/commands/mirror_command'
class TestGemCommandsMirrorCommand < Gem::TestCase
-
def setup
super
@cmd = Gem::Commands::MirrorCommand.new
-
- @mirror_specs = Gem::Specification.find_all_by_name('rubygems-mirror').each do |spec|
- Gem::Specification.remove_spec spec
- end
- end
-
- def teardown
- @mirror_specs.each do |spec|
- Gem::Specification.add_spec spec
- end
-
- super
end
def test_execute
diff --git a/test/rubygems/test_gem_commands_outdated_command.rb b/test/rubygems/test_gem_commands_outdated_command.rb
index d369c6b..1bc5acc 100644
--- a/test/rubygems/test_gem_commands_outdated_command.rb
+++ b/test/rubygems/test_gem_commands_outdated_command.rb
@@ -15,9 +15,8 @@ class TestGemCommandsOutdatedCommand < Gem::TestCase
def test_execute
spec_fetcher do |fetcher|
- fetcher.spec 'foo', '1.0'
- fetcher.spec 'foo', '2.0'
- fetcher.clear
+ fetcher.download 'foo', '1.0'
+ fetcher.download 'foo', '2.0'
fetcher.gem 'foo', '0.1'
fetcher.gem 'foo', '0.2'
end
diff --git a/test/rubygems/test_gem_commands_pristine_command.rb b/test/rubygems/test_gem_commands_pristine_command.rb
index ec5f3ad..7c0109b 100644
--- a/test/rubygems/test_gem_commands_pristine_command.rb
+++ b/test/rubygems/test_gem_commands_pristine_command.rb
@@ -103,10 +103,12 @@ class TestGemCommandsPristineCommand < Gem::TestCase
assert_path_exists gem_exec
+ ruby_exec = sprintf Gem.default_exec_format, 'ruby'
+
if win_platform?
- assert_match %r%\A#!\s*ruby%, File.read(gem_exec)
+ assert_match %r%\A#!\s*#{ruby_exec}%, File.read(gem_exec)
else
- assert_match %r%\A#!\s*/usr/bin/env ruby%, File.read(gem_exec)
+ assert_match %r%\A#!\s*/usr/bin/env #{ruby_exec}%, File.read(gem_exec)
end
end
@@ -151,10 +153,11 @@ class TestGemCommandsPristineCommand < Gem::TestCase
ext_path = File.join @tempdir, 'ext', 'a', 'extconf.rb'
write_file ext_path do |io|
- io.write '# extconf.rb'
+ io.write "# extconf.rb\nrequire 'mkmf'; create_makefile 'a'"
end
util_build_gem a
+ install_gem a
@cmd.options[:args] = %w[a]
@cmd.options[:extensions] = false
@@ -403,7 +406,7 @@ class TestGemCommandsPristineCommand < Gem::TestCase
end
def test_execute_unknown_gem_at_remote_source
- util_spec 'a'
+ install_specs util_spec 'a'
@cmd.options[:args] = %w[a]
@@ -442,9 +445,10 @@ class TestGemCommandsPristineCommand < Gem::TestCase
def test_execute_bundled_gem_on_old_rubies
util_set_RUBY_VERSION '1.9.3', 551
- util_spec 'bigdecimal', '1.1.0' do |s|
+ spec = util_spec 'bigdecimal', '1.1.0' do |s|
s.summary = "This bigdecimal is bundled with Ruby"
end
+ install_specs spec
@cmd.options[:args] = %w[bigdecimal]
diff --git a/test/rubygems/test_gem_commands_query_command.rb b/test/rubygems/test_gem_commands_query_command.rb
index 43fa825..50cedbb 100644
--- a/test/rubygems/test_gem_commands_query_command.rb
+++ b/test/rubygems/test_gem_commands_query_command.rb
@@ -1,23 +1,22 @@
require 'rubygems/test_case'
require 'rubygems/commands/query_command'
-class TestGemCommandsQueryCommand < Gem::TestCase
-
+module TestGemCommandsQueryCommandSetup
def setup
super
@cmd = Gem::Commands::QueryCommand.new
- @specs = spec_fetcher do |fetcher|
- fetcher.spec 'a', 1
- fetcher.spec 'a', 2
- fetcher.spec 'a', '3.a'
- end
+ @specs = add_gems_to_fetcher
@fetcher.data["#{@gem_repo}Marshal.#{Gem.marshal_version}"] = proc do
raise Gem::RemoteFetcher::FetchError
end
end
+end
+
+class TestGemCommandsQueryCommandWithInstalledGems < Gem::TestCase
+ include TestGemCommandsQueryCommandSetup
def test_execute
spec_fetcher do |fetcher|
@@ -42,37 +41,6 @@ pl (1 i386-linux)
assert_equal '', @ui.error
end
- def test_execute_platform
- spec_fetcher do |fetcher|
- fetcher.clear
-
- fetcher.spec 'a', 1
- fetcher.spec 'a', 1 do |s|
- s.platform = 'x86-linux'
- end
-
- fetcher.spec 'a', 2 do |s|
- s.platform = 'universal-darwin'
- end
- end
-
- @cmd.handle_options %w[-r -a]
-
- use_ui @ui do
- @cmd.execute
- end
-
- expected = <<-EOF
-
-*** REMOTE GEMS ***
-
-a (2 universal-darwin, 1 ruby x86-linux)
- EOF
-
- assert_equal expected, @ui.output
- assert_equal '', @ui.error
- end
-
def test_execute_all
spec_fetcher do |fetcher|
fetcher.legacy_platform
@@ -159,56 +127,6 @@ pl (1)
assert_equal '', @ui.error
end
- def test_execute_details_platform
- spec_fetcher do |fetcher|
- fetcher.clear
-
- fetcher.spec 'a', 1 do |s|
- s.platform = 'x86-linux'
- end
-
- fetcher.spec 'a', 2 do |s|
- s.summary = 'This is a lot of text. ' * 4
- s.authors = ['Abraham Lincoln', 'Hirohito']
- s.homepage = 'http://a.example.com/'
- s.platform = 'universal-darwin'
- end
-
- fetcher.legacy_platform
- end
-
- @cmd.handle_options %w[-r -d]
-
- use_ui @ui do
- @cmd.execute
- end
-
- expected = <<-EOF
-
-*** REMOTE GEMS ***
-
-a (2, 1)
- Platforms:
- 1: x86-linux
- 2: universal-darwin
- Authors: Abraham Lincoln, Hirohito
- Homepage: http://a.example.com/
-
- This is a lot of text. This is a lot of text. This is a lot of text.
- This is a lot of text.
-
-pl (1)
- Platform: i386-linux
- Author: A User
- Homepage: http://example.com
-
- this is a summary
- EOF
-
- assert_equal expected, @ui.output
- assert_equal '', @ui.error
- end
-
def test_execute_installed
@cmd.handle_options %w[-n a --installed]
@@ -526,67 +444,100 @@ pl (1 i386-linux)
assert_equal '', @ui.error
end
- def test_execute_local_details
+ def test_make_entry
+ a_2_name = @specs['a-2'].original_name
+
+ @fetcher.data.delete \
+ "#{@gem_repo}quick/Marshal.#{Gem.marshal_version}/#{a_2_name}.gemspec.rz"
+
+ a2 = @specs['a-2']
+ entry_tuples = [
+ [Gem::NameTuple.new(a2.name, a2.version, a2.platform),
+ Gem.sources.first],
+ ]
+
+ platforms = { a2.version => [a2.platform] }
+
+ entry = @cmd.send :make_entry, entry_tuples, platforms
+
+ assert_equal 'a (2)', entry
+ end
+
+ # Test for multiple args handling!
+ def test_execute_multiple_args
spec_fetcher do |fetcher|
- fetcher.clear
+ fetcher.legacy_platform
+ end
+
+ @cmd.handle_options %w[a pl]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+ assert_match %r%^a %, @ui.output
+ assert_match %r%^pl %, @ui.output
+ assert_equal '', @ui.error
+ end
+
+ def test_show_gems
+ @cmd.options[:name] = //
+ @cmd.options[:domain] = :remote
+
+ use_ui @ui do
+ @cmd.send :show_gems, /a/i, false
+ end
+
+ assert_match %r%^a %, @ui.output
+ refute_match %r%^pl %, @ui.output
+ assert_empty @ui.error
+ end
+
+ private
+
+ def add_gems_to_fetcher
+ spec_fetcher do |fetcher|
+ fetcher.spec 'a', 1
+ fetcher.spec 'a', 2
+ fetcher.spec 'a', '3.a'
+ end
+ end
+end
+
+class TestGemCommandsQueryCommandWithoutInstalledGems < Gem::TestCase
+ include TestGemCommandsQueryCommandSetup
+
+ def test_execute_platform
+ spec_fetcher do |fetcher|
+ fetcher.spec 'a', 1
fetcher.spec 'a', 1 do |s|
s.platform = 'x86-linux'
end
fetcher.spec 'a', 2 do |s|
- s.summary = 'This is a lot of text. ' * 4
- s.authors = ['Abraham Lincoln', 'Hirohito']
- s.homepage = 'http://a.example.com/'
s.platform = 'universal-darwin'
end
-
- fetcher.legacy_platform
end
- @cmd.handle_options %w[-l -d]
+ @cmd.handle_options %w[-r -a]
use_ui @ui do
@cmd.execute
end
- str = @ui.output
-
- str.gsub!(/\(\d\): [^\n]*/, "-")
- str.gsub!(/at: [^\n]*/, "at: -")
-
expected = <<-EOF
-*** LOCAL GEMS ***
-
-a (2, 1)
- Platforms:
- 1: x86-linux
- 2: universal-darwin
- Authors: Abraham Lincoln, Hirohito
- Homepage: http://a.example.com/
- Installed at -
- -
-
- This is a lot of text. This is a lot of text. This is a lot of text.
- This is a lot of text.
-
-pl (1)
- Platform: i386-linux
- Author: A User
- Homepage: http://example.com
- Installed at: -
+*** REMOTE GEMS ***
- this is a summary
+a (2 universal-darwin, 1 ruby x86-linux)
EOF
assert_equal expected, @ui.output
+ assert_equal '', @ui.error
end
def test_execute_default_details
spec_fetcher do |fetcher|
- fetcher.clear
-
fetcher.spec 'a', 2
end
@@ -615,54 +566,68 @@ a (2, 1)
assert_equal expected, @ui.output
end
- def test_make_entry
- a_2_name = @specs['a-2'].original_name
-
- @fetcher.data.delete \
- "#{@gem_repo}quick/Marshal.#{Gem.marshal_version}/#{a_2_name}.gemspec.rz"
-
- a2 = @specs['a-2']
- entry_tuples = [
- [Gem::NameTuple.new(a2.name, a2.version, a2.platform),
- Gem.sources.first],
- ]
-
- platforms = { a2.version => [a2.platform] }
-
- entry = @cmd.send :make_entry, entry_tuples, platforms
+ def test_execute_local_details
+ spec_fetcher do |fetcher|
+ fetcher.spec 'a', 1 do |s|
+ s.platform = 'x86-linux'
+ end
- assert_equal 'a (2)', entry
- end
+ fetcher.spec 'a', 2 do |s|
+ s.summary = 'This is a lot of text. ' * 4
+ s.authors = ['Abraham Lincoln', 'Hirohito']
+ s.homepage = 'http://a.example.com/'
+ s.platform = 'universal-darwin'
+ end
- # Test for multiple args handling!
- def test_execute_multiple_args
- spec_fetcher do |fetcher|
fetcher.legacy_platform
end
- @cmd.handle_options %w[a pl]
+ @cmd.handle_options %w[-l -d]
use_ui @ui do
@cmd.execute
end
- assert_match %r%^a %, @ui.output
- assert_match %r%^pl %, @ui.output
- assert_equal '', @ui.error
- end
+ str = @ui.output
- def test_show_gems
- @cmd.options[:name] = //
- @cmd.options[:domain] = :remote
+ str.gsub!(/\(\d\): [^\n]*/, "-")
+ str.gsub!(/at: [^\n]*/, "at: -")
- use_ui @ui do
- @cmd.send :show_gems, /a/i, false
- end
+ expected = <<-EOF
- assert_match %r%^a %, @ui.output
- refute_match %r%^pl %, @ui.output
- assert_empty @ui.error
+*** LOCAL GEMS ***
+
+a (2, 1)
+ Platforms:
+ 1: x86-linux
+ 2: universal-darwin
+ Authors: Abraham Lincoln, Hirohito
+ Homepage: http://a.example.com/
+ Installed at -
+ -
+
+ This is a lot of text. This is a lot of text. This is a lot of text.
+ This is a lot of text.
+
+pl (1)
+ Platform: i386-linux
+ Author: A User
+ Homepage: http://example.com
+ Installed at: -
+
+ this is a summary
+ EOF
+
+ assert_equal expected, @ui.output
end
-end
+ private
+ def add_gems_to_fetcher
+ spec_fetcher do |fetcher|
+ fetcher.download 'a', 1
+ fetcher.download 'a', 2
+ fetcher.download 'a', '3.a'
+ end
+ end
+end
diff --git a/test/rubygems/test_gem_commands_specification_command.rb b/test/rubygems/test_gem_commands_specification_command.rb
index 80564f9..ccc2dbb 100644
--- a/test/rubygems/test_gem_commands_specification_command.rb
+++ b/test/rubygems/test_gem_commands_specification_command.rb
@@ -26,8 +26,8 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase
end
def test_execute_all
- util_spec 'foo', '0.0.1'
- util_spec 'foo', '0.0.2'
+ install_specs util_spec 'foo', '0.0.1'
+ install_specs util_spec 'foo', '0.0.2'
@cmd.options[:args] = %w[foo]
@cmd.options[:all] = true
@@ -89,8 +89,8 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase
end
def test_execute_exact_match
- util_spec 'foo'
- util_spec 'foo_bar'
+ install_specs util_spec 'foo'
+ install_specs util_spec 'foo_bar'
@cmd.options[:args] = %w[foo]
diff --git a/test/rubygems/test_gem_commands_stale_command.rb b/test/rubygems/test_gem_commands_stale_command.rb
index ca80784..69b1e29 100644
--- a/test/rubygems/test_gem_commands_stale_command.rb
+++ b/test/rubygems/test_gem_commands_stale_command.rb
@@ -13,10 +13,12 @@ class TestGemCommandsStaleCommand < Gem::TestCase
foo_bar = util_spec 'foo_bar' do |gem|
gem.files = files
end
+ install_specs foo_bar
bar_baz = util_spec 'bar_baz' do |gem|
gem.files = files
end
+ install_specs bar_baz
files.each do |file|
filename = File.join(bar_baz.full_gem_path, file)
diff --git a/test/rubygems/test_gem_commands_uninstall_command.rb b/test/rubygems/test_gem_commands_uninstall_command.rb
index 4f045c5..2e32e39 100644
--- a/test/rubygems/test_gem_commands_uninstall_command.rb
+++ b/test/rubygems/test_gem_commands_uninstall_command.rb
@@ -24,7 +24,7 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
gemhome2 = "#{@gemhome}2"
- a_4 = util_spec 'a', 4
+ a_4, = util_gem 'a', 4
install_gem a_4, :install_dir => gemhome2
Gem::Specification.dirs = [@gemhome, gemhome2]
@@ -41,7 +41,7 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
@cmd.execute
end
- assert_equal %w[a-4 a_evil-9 b-2 c-1.2 default-1 dep_x-1 pl-1-x86-linux x-1],
+ assert_equal %w[a_evil-9 b-2 c-1.2 default-1 dep_x-1 pl-1-x86-linux x-1],
Gem::Specification.all_names.sort
end
@@ -213,7 +213,7 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
gemhome2 = "#{@gemhome}2"
- a_4 = util_spec 'a', 4
+ a_4, = util_gem 'a', 4
install_gem a_4, :install_dir => gemhome2
Gem::Specification.dirs = [@gemhome, gemhome2]
@@ -229,7 +229,7 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
@cmd.execute
end
- assert_equal %w[a-4 default-1], Gem::Specification.all_names.sort
+ assert_equal %w[default-1], Gem::Specification.all_names.sort
end
def test_handle_options
diff --git a/test/rubygems/test_gem_commands_unpack_command.rb b/test/rubygems/test_gem_commands_unpack_command.rb
index 9264b3f..05002f8 100644
--- a/test/rubygems/test_gem_commands_unpack_command.rb
+++ b/test/rubygems/test_gem_commands_unpack_command.rb
@@ -101,10 +101,8 @@ class TestGemCommandsUnpackCommand < Gem::TestCase
def test_execute_remote
spec_fetcher do |fetcher|
- fetcher.spec 'a', 1
- fetcher.gem 'a', 2
-
- fetcher.clear
+ fetcher.download 'a', 1
+ fetcher.download 'a', 2
end
Gem.configuration.verbose = :really
@@ -184,8 +182,8 @@ class TestGemCommandsUnpackCommand < Gem::TestCase
foo_path = File.join(@tempdir, "#{foo_spec.full_name}.gem")
foo_bar_path = File.join(@tempdir, "#{foo_bar_spec.full_name}.gem")
- Gem::Installer.new(foo_path).install
- Gem::Installer.new(foo_bar_path).install
+ Gem::Installer.at(foo_path).install
+ Gem::Installer.at(foo_bar_path).install
@cmd.options[:args] = %w[foo]
diff --git a/test/rubygems/test_gem_commands_update_command.rb b/test/rubygems/test_gem_commands_update_command.rb
index 6a32706..03894d7 100644
--- a/test/rubygems/test_gem_commands_update_command.rb
+++ b/test/rubygems/test_gem_commands_update_command.rb
@@ -18,11 +18,9 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
@cmd.options[:document] = []
@specs = spec_fetcher do |fetcher|
- fetcher.gem 'a', 1
- fetcher.gem 'a', 2
- fetcher.gem 'a', '3.a'
-
- fetcher.clear
+ fetcher.download 'a', 1
+ fetcher.download 'a', 2
+ fetcher.download 'a', '3.a'
end
@a1_path = @specs['a-1'].cache_file
@@ -32,10 +30,7 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
def test_execute
spec_fetcher do |fetcher|
- fetcher.gem 'a', 2
-
- fetcher.clear
-
+ fetcher.download 'a', 2
fetcher.spec 'a', 1
end
@@ -54,10 +49,8 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
def test_execute_multiple
spec_fetcher do |fetcher|
- fetcher.gem 'a', 2
- fetcher.gem 'ab', 2
-
- fetcher.clear
+ fetcher.download 'a', 2
+ fetcher.download 'ab', 2
fetcher.spec 'a', 1
fetcher.spec 'ab', 1
@@ -78,9 +71,7 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
def test_execute_system
spec_fetcher do |fetcher|
- fetcher.gem 'rubygems-update', 9 do |s| s.files = %w[setup.rb] end
-
- fetcher.clear
+ fetcher.download 'rubygems-update', 9 do |s| s.files = %w[setup.rb] end
end
@cmd.options[:args] = []
@@ -100,11 +91,9 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
def test_execute_system_at_latest
spec_fetcher do |fetcher|
- fetcher.gem 'rubygems-update', Gem::VERSION do |s|
+ fetcher.download 'rubygems-update', Gem::VERSION do |s|
s.files = %w[setup.rb]
end
-
- fetcher.clear
end
@cmd.options[:args] = []
@@ -123,10 +112,8 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
def test_execute_system_multiple
spec_fetcher do |fetcher|
- fetcher.gem 'rubygems-update', 8 do |s| s.files = %w[setup.rb] end
- fetcher.gem 'rubygems-update', 9 do |s| s.files = %w[setup.rb] end
-
- fetcher.clear
+ fetcher.download 'rubygems-update', 8 do |s| s.files = %w[setup.rb] end
+ fetcher.download 'rubygems-update', 9 do |s| s.files = %w[setup.rb] end
end
@cmd.options[:args] = []
@@ -146,10 +133,8 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
def test_execute_system_specific
spec_fetcher do |fetcher|
- fetcher.gem 'rubygems-update', 8 do |s| s.files = %w[setup.rb] end
- fetcher.gem 'rubygems-update', 9 do |s| s.files = %w[setup.rb] end
-
- fetcher.clear
+ fetcher.download 'rubygems-update', 8 do |s| s.files = %w[setup.rb] end
+ fetcher.download 'rubygems-update', 9 do |s| s.files = %w[setup.rb] end
end
@cmd.options[:args] = []
@@ -169,10 +154,8 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
def test_execute_system_specifically_to_latest_version
spec_fetcher do |fetcher|
- fetcher.gem 'rubygems-update', 8 do |s| s.files = %w[setup.rb] end
- fetcher.gem 'rubygems-update', 9 do |s| s.files = %w[setup.rb] end
-
- fetcher.clear
+ fetcher.download 'rubygems-update', 8 do |s| s.files = %w[setup.rb] end
+ fetcher.download 'rubygems-update', 9 do |s| s.files = %w[setup.rb] end
end
@cmd.options[:args] = []
@@ -213,11 +196,9 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
def test_execute_dependencies
spec_fetcher do |fetcher|
- fetcher.gem 'a', 2, 'b' => 2, 'c' => 2
- fetcher.gem 'b', 2
- fetcher.gem 'c', 2
-
- fetcher.clear
+ fetcher.download 'a', 2, 'b' => 2, 'c' => 2
+ fetcher.download 'b', 2
+ fetcher.download 'c', 2
fetcher.spec 'a', 1, 'c' => '1.2'
fetcher.spec 'c', '1.2'
@@ -243,10 +224,7 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
def test_execute_rdoc
skip if RUBY_VERSION <= "1.8.7"
spec_fetcher do |fetcher|
- fetcher.gem 'a', 2
-
- fetcher.clear
-
+ fetcher.download 'a', 2
fetcher.spec 'a', 1
end
@@ -269,9 +247,7 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
def test_execute_named
spec_fetcher do |fetcher|
- fetcher.gem 'a', 2
-
- fetcher.clear
+ fetcher.download 'a', 2
fetcher.spec 'a', 1
end
@@ -292,8 +268,7 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
def test_execute_named_some_up_to_date
spec_fetcher do |fetcher|
- fetcher.gem 'a', 2
- fetcher.clear
+ fetcher.download 'a', 2
fetcher.spec 'a', 1
fetcher.spec 'b', 2
@@ -334,9 +309,7 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
def test_execute_named_up_to_date_prerelease
spec_fetcher do |fetcher|
- fetcher.gem 'a', '3.a'
-
- fetcher.clear
+ fetcher.download 'a', '3.a'
fetcher.gem 'a', 2
end
@@ -376,10 +349,7 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
def test_execute_user_install
spec_fetcher do |fetcher|
- fetcher.gem 'a', 2
-
- fetcher.clear
-
+ fetcher.download 'a', 2
fetcher.spec 'a', 1
end
diff --git a/test/rubygems/test_gem_commands_which_command.rb b/test/rubygems/test_gem_commands_which_command.rb
index 7ce26c8..5c6afe9 100644
--- a/test/rubygems/test_gem_commands_which_command.rb
+++ b/test/rubygems/test_gem_commands_which_command.rb
@@ -73,6 +73,7 @@ class TestGemCommandsWhichCommand < Gem::TestCase
@foo_bar = util_spec 'foo_bar' do |gem|
gem.files = files
end
+ install_specs @foo_bar
files.each do |file|
filename = File.join(@foo_bar.full_gem_path, file)
diff --git a/test/rubygems/test_gem_dependency.rb b/test/rubygems/test_gem_dependency.rb
index c43ff0e..4c27ce7 100644
--- a/test/rubygems/test_gem_dependency.rb
+++ b/test/rubygems/test_gem_dependency.rb
@@ -294,10 +294,11 @@ class TestGemDependency < Gem::TestCase
end
def test_to_spec
- util_spec 'a', '1'
+ a_1 = util_spec 'a', '1'
a_2 = util_spec 'a', '2'
a_dep = dep 'a', '>= 0'
+ install_specs a_1, a_2
assert_equal a_2, a_dep.to_spec
end
@@ -307,6 +308,7 @@ class TestGemDependency < Gem::TestCase
a_1_1_a = util_spec 'a', '1.1.a'
a_dep = dep 'a', '>= 0'
+ install_specs a_1, a_1_1_a
assert_equal a_1, a_dep.to_spec
@@ -317,7 +319,8 @@ class TestGemDependency < Gem::TestCase
end
def test_to_specs_suggests_other_versions
- a = util_spec 'a', '1.0', 'b' => '>= 1.0'
+ a = util_spec 'a', '1.0'
+ install_specs a
a_file = File.join a.gem_dir, 'lib', 'a_file.rb'
@@ -335,7 +338,8 @@ class TestGemDependency < Gem::TestCase
end
def test_to_specs_indicates_total_gem_set_size
- a = util_spec 'a', '1.0', 'b' => '>= 1.0'
+ a = util_spec 'a', '1.0'
+ install_specs a
a_file = File.join a.gem_dir, 'lib', 'a_file.rb'
diff --git a/test/rubygems/test_gem_dependency_installer.rb b/test/rubygems/test_gem_dependency_installer.rb
index 8264006..03bcd04 100644
--- a/test/rubygems/test_gem_dependency_installer.rb
+++ b/test/rubygems/test_gem_dependency_installer.rb
@@ -406,7 +406,7 @@ class TestGemDependencyInstaller < Gem::TestCase
def test_install_dependency_existing
util_setup_gems
- Gem::Installer.new(@a1_gem).install
+ Gem::Installer.at(@a1_gem).install
FileUtils.mv @a1_gem, @tempdir
FileUtils.mv @b1_gem, @tempdir
inst = nil
@@ -437,7 +437,7 @@ class TestGemDependencyInstaller < Gem::TestCase
_, f1_gem = util_gem 'f', '1', 'e' => nil
- Gem::Installer.new(e1_gem).install
+ Gem::Installer.at(e1_gem).install
FileUtils.rm_r e1.extension_dir
FileUtils.mv e1_gem, @tempdir
@@ -525,7 +525,7 @@ class TestGemDependencyInstaller < Gem::TestCase
inst = nil
Dir.chdir @tempdir do
- Gem::Installer.new('a-1.gem').install
+ Gem::Installer.at('a-1.gem').install
inst = Gem::DependencyInstaller.new :domain => :local
inst.install 'b-1.gem'
@@ -669,7 +669,7 @@ class TestGemDependencyInstaller < Gem::TestCase
FileUtils.mv @a1_gem, @tempdir
FileUtils.mv @b1_gem, @tempdir
- inst = Gem::Installer.new @a1.file_name
+ inst = Gem::Installer.at @a1.file_name
inst.install
gemhome2 = File.join @tempdir, 'gemhome2'
@@ -799,7 +799,7 @@ class TestGemDependencyInstaller < Gem::TestCase
def test_install_reinstall
util_setup_gems
- Gem::Installer.new(@a1_gem).install
+ Gem::Installer.at(@a1_gem).install
FileUtils.mv @a1_gem, @tempdir
inst = nil
diff --git a/test/rubygems/test_gem_doctor.rb b/test/rubygems/test_gem_doctor.rb
index f4d4659..1097528 100644
--- a/test/rubygems/test_gem_doctor.rb
+++ b/test/rubygems/test_gem_doctor.rb
@@ -157,7 +157,7 @@ This directory does not appear to be a RubyGems repository, skipping
refute doctor.gem_repository?, 'no gems installed'
- util_spec 'a'
+ install_specs util_spec 'a'
doctor = Gem::Doctor.new @gemhome
diff --git a/test/rubygems/test_gem_ext_configure_builder.rb b/test/rubygems/test_gem_ext_configure_builder.rb
index 34e9fcc..610d60a 100644
--- a/test/rubygems/test_gem_ext_configure_builder.rb
+++ b/test/rubygems/test_gem_ext_configure_builder.rb
@@ -29,12 +29,16 @@ class TestGemExtConfigureBuilder < Gem::TestCase
Gem::Ext::ConfigureBuilder.build nil, nil, @dest_path, output
end
+ assert_match(/^current directory:/, output.shift)
assert_equal "sh ./configure --prefix=#{@dest_path}", output.shift
assert_equal "", output.shift
+ assert_match(/^current directory:/, output.shift)
assert_contains_make_command 'clean', output.shift
assert_match(/^ok$/m, output.shift)
+ assert_match(/^current directory:/, output.shift)
assert_contains_make_command '', output.shift
assert_match(/^ok$/m, output.shift)
+ assert_match(/^current directory:/, output.shift)
assert_contains_make_command 'install', output.shift
assert_match(/^ok$/m, output.shift)
end
@@ -54,6 +58,7 @@ class TestGemExtConfigureBuilder < Gem::TestCase
assert_match 'configure failed', error.message
+ assert_match(/^current directory:/, output.shift)
assert_equal "#{sh_prefix_configure}#{@dest_path}", output.shift
assert_match %r(#{shell_error_msg}), output.shift
assert_equal true, output.empty?
@@ -73,10 +78,9 @@ class TestGemExtConfigureBuilder < Gem::TestCase
Gem::Ext::ConfigureBuilder.build nil, nil, @dest_path, output
end
- assert_contains_make_command 'clean', output[0]
- assert_contains_make_command '', output[2]
- assert_contains_make_command 'install', output[4]
+ assert_contains_make_command 'clean', output[1]
+ assert_contains_make_command '', output[4]
+ assert_contains_make_command 'install', output[7]
end
end
-
diff --git a/test/rubygems/test_gem_ext_ext_conf_builder.rb b/test/rubygems/test_gem_ext_ext_conf_builder.rb
index f2f467e..908dbde 100644
--- a/test/rubygems/test_gem_ext_ext_conf_builder.rb
+++ b/test/rubygems/test_gem_ext_ext_conf_builder.rb
@@ -33,11 +33,13 @@ class TestGemExtExtConfBuilder < Gem::TestCase
assert_same result, output
end
- assert_match(/^#{Gem.ruby}.* extconf.rb/, output[0])
- assert_equal "creating Makefile\n", output[1]
- assert_contains_make_command 'clean', output[2]
- assert_contains_make_command '', output[4]
- assert_contains_make_command 'install', output[6]
+ assert_match(/^current directory:/, output[0])
+ assert_match(/^#{Gem.ruby}.* extconf.rb/, output[1])
+ assert_equal "creating Makefile\n", output[2]
+ assert_match(/^current directory:/, output[3])
+ assert_contains_make_command 'clean', output[4]
+ assert_contains_make_command '', output[7]
+ assert_contains_make_command 'install', output[10]
assert_empty Dir.glob(File.join(@ext, 'siteconf*.rb'))
end
@@ -54,10 +56,10 @@ class TestGemExtExtConfBuilder < Gem::TestCase
Gem::Ext::ExtConfBuilder.build 'extconf.rb', nil, @dest_path, output
end
- assert_equal "creating Makefile\n", output[1]
- assert_contains_make_command 'clean', output[2]
- assert_contains_make_command '', output[4]
- assert_contains_make_command 'install', output[6]
+ assert_equal "creating Makefile\n", output[2]
+ assert_contains_make_command 'clean', output[4]
+ assert_contains_make_command '', output[7]
+ assert_contains_make_command 'install', output[10]
end
end
@@ -78,8 +80,8 @@ class TestGemExtExtConfBuilder < Gem::TestCase
end
end
- assert_equal "creating Makefile\n", output[1]
- assert_contains_make_command 'clean', output[2]
+ assert_equal "creating Makefile\n", output[2]
+ assert_contains_make_command 'clean', output[4]
end
ensure
ENV['make'] = env_make
@@ -106,7 +108,9 @@ class TestGemExtExtConfBuilder < Gem::TestCase
assert_equal 'extconf failed, exit code 1', error.message
- assert_match(/^#{Gem.ruby}.* extconf.rb/, output[0])
+ assert_match(/^#{Gem.ruby}.* extconf.rb/, output[1])
+ assert_match(File.join(@dest_path, 'mkmf.log'), output[4])
+
assert_path_exists File.join @dest_path, 'mkmf.log'
end
@@ -147,9 +151,9 @@ end
Gem::Ext::ExtConfBuilder.build 'extconf.rb', nil, @dest_path, output
end
- assert_contains_make_command 'clean', output[2]
- assert_contains_make_command '', output[4]
- assert_contains_make_command 'install', output[6]
+ assert_contains_make_command 'clean', output[4]
+ assert_contains_make_command '', output[7]
+ assert_contains_make_command 'install', output[10]
assert_empty Dir.glob(File.join(@ext, 'siteconf*.rb'))
end
@@ -173,9 +177,9 @@ end
Gem::Ext::ExtConfBuilder.make @ext, output
end
- assert_contains_make_command 'clean', output[0]
- assert_contains_make_command '', output[2]
- assert_contains_make_command 'install', output[4]
+ assert_contains_make_command 'clean', output[1]
+ assert_contains_make_command '', output[4]
+ assert_contains_make_command 'install', output[7]
end
def test_class_make_no_Makefile
diff --git a/test/rubygems/test_gem_indexer.rb b/test/rubygems/test_gem_indexer.rb
index 8b505ef..9622cd1 100644
--- a/test/rubygems/test_gem_indexer.rb
+++ b/test/rubygems/test_gem_indexer.rb
@@ -294,7 +294,7 @@ class TestGemIndexer < Gem::TestCase
sys_gem = util_spec 'systemgem', '1.0'
util_build_gem sys_gem
- Gem::Specification.add_spec sys_gem
+ install_default_gems sys_gem
yield
util_remove_gem sys_gem
end
diff --git a/test/rubygems/test_gem_install_update_options.rb b/test/rubygems/test_gem_install_update_options.rb
index de09d7a..e7dc52a 100644
--- a/test/rubygems/test_gem_install_update_options.rb
+++ b/test/rubygems/test_gem_install_update_options.rb
@@ -129,7 +129,7 @@ class TestGemInstallUpdateOptions < Gem::InstallerTestCase
assert @cmd.options[:user_install]
- @installer = Gem::Installer.new @gem, @cmd.options
+ @installer = Gem::Installer.at @gem, @cmd.options
@installer.install
assert_path_exists File.join(Gem.user_dir, 'gems')
assert_path_exists File.join(Gem.user_dir, 'gems', @spec.full_name)
@@ -149,7 +149,7 @@ class TestGemInstallUpdateOptions < Gem::InstallerTestCase
Gem.use_paths @gemhome, @userhome
assert_raises(Gem::FilePermissionError) do
- Gem::Installer.new(@gem, @cmd.options).install
+ Gem::Installer.at(@gem, @cmd.options).install
end
end
ensure
diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb
index 701fda1..2e5ac6a 100644
--- a/test/rubygems/test_gem_installer.rb
+++ b/test/rubygems/test_gem_installer.rb
@@ -36,7 +36,7 @@ class TestGemInstaller < Gem::InstallerTestCase
require 'rubygems'
-version = \">= 0\"
+version = \">= 0.a\"
if ARGV.first
str = ARGV.first
@@ -257,7 +257,7 @@ gem 'other', version
s.add_dependency 'garbage ~> 5'
end
- installer = Gem::Installer.new a_gem
+ installer = Gem::Installer.at a_gem
e = assert_raises Gem::InstallError do
installer.ensure_loadable_spec
@@ -275,7 +275,7 @@ gem 'other', version
end
policy = Gem::Security::HighSecurity
- installer = Gem::Installer.new a_gem, :security_policy => policy
+ installer = Gem::Installer.at a_gem, :security_policy => policy
assert_raises Gem::Security::Exception do
installer.ensure_loadable_spec
@@ -322,7 +322,7 @@ gem 'other', version
:install_dir => "/non/existent"
}
- inst = Gem::Installer.new '', options
+ inst = Gem::Installer.at '', options
Gem::Installer.path_warning = false
@@ -575,8 +575,8 @@ gem 'other', version
util_make_exec
one = @spec.dup
one.version = 1
+ @installer = Gem::Installer.for_spec spec
@installer.gem_dir = util_gem_dir one
- @installer.spec = spec
@installer.generate_bin
@@ -672,14 +672,14 @@ gem 'other', version
util_build_gem spec
FileUtils.mv spec.cache_file, @tempdir
- installer = Gem::Installer.new gem
+ installer = Gem::Installer.at gem
assert_equal File.join(@gemhome, 'gems', spec.full_name), installer.gem_dir
assert_equal File.join(@gemhome, 'bin'), installer.bin_dir
end
def test_initialize_user_install
- installer = Gem::Installer.new @gem, :user_install => true
+ installer = Gem::Installer.at @gem, :user_install => true
assert_equal File.join(Gem.user_dir, 'gems', @spec.full_name),
installer.gem_dir
@@ -688,7 +688,7 @@ gem 'other', version
def test_initialize_user_install_bin_dir
installer =
- Gem::Installer.new @gem, :user_install => true, :bin_dir => @tempdir
+ Gem::Installer.at @gem, :user_install => true, :bin_dir => @tempdir
assert_equal File.join(Gem.user_dir, 'gems', @spec.full_name),
installer.gem_dir
@@ -870,7 +870,7 @@ gem 'other', version
Gem::Package.build @spec
end
end
- @installer = Gem::Installer.new @gem
+ @installer = Gem::Installer.at @gem
build_rake_in do
use_ui @ui do
assert_equal @spec, @installer.install
@@ -884,7 +884,7 @@ gem 'other', version
def test_install_force
use_ui @ui do
- installer = Gem::Installer.new old_ruby_required, :force => true
+ installer = Gem::Installer.at old_ruby_required, :force => true
installer.install
end
@@ -993,7 +993,7 @@ gem 'other', version
use_ui @ui do
path = Gem::Package.build @spec
- @installer = Gem::Installer.new path
+ @installer = Gem::Installer.at path
@installer.install
end
@@ -1016,7 +1016,7 @@ gem 'other', version
use_ui @ui do
path = Gem::Package.build @spec
- installer = Gem::Installer.new path, :install_dir => gemhome2
+ installer = Gem::Installer.at path, :install_dir => gemhome2
installer.install
end
@@ -1056,7 +1056,7 @@ gem 'other', version
use_ui @ui do
path = Gem::Package.build @spec
- @installer = Gem::Installer.new path
+ @installer = Gem::Installer.at path
@installer.install
end
assert_path_exists File.join @spec.gem_dir, rb
@@ -1097,7 +1097,7 @@ gem 'other', version
use_ui @ui do
path = Gem::Package.build @spec
- @installer = Gem::Installer.new path
+ @installer = Gem::Installer.at path
@installer.install
end
assert_path_exists so
@@ -1175,7 +1175,7 @@ gem 'other', version
# that it work everything out on it's own.
Gem::Specification.reset
- installer = Gem::Installer.new gem, :install_dir => gemhome2
+ installer = Gem::Installer.at gem, :install_dir => gemhome2
build_rake_in do
use_ui @ui do
@@ -1186,7 +1186,7 @@ gem 'other', version
def test_pre_install_checks_ruby_version
use_ui @ui do
- installer = Gem::Installer.new old_ruby_required
+ installer = Gem::Installer.at old_ruby_required
e = assert_raises Gem::InstallError do
installer.pre_install_checks
end
@@ -1205,7 +1205,7 @@ gem 'other', version
gem = File.join(@gemhome, 'cache', spec.file_name)
use_ui @ui do
- @installer = Gem::Installer.new gem
+ @installer = Gem::Installer.at gem
e = assert_raises Gem::InstallError do
@installer.pre_install_checks
end
@@ -1231,7 +1231,7 @@ gem 'other', version
def test_process_options_build_root
build_root = File.join @tempdir, 'build_root'
- @installer = Gem::Installer.new @gem, :build_root => build_root
+ @installer = Gem::Installer.at @gem, :build_root => build_root
assert_equal Pathname(build_root), @installer.build_root
assert_equal File.join(build_root, @gemhome, 'bin'), @installer.bin_dir
@@ -1406,7 +1406,7 @@ gem 'other', version
end
def test_write_build_info_file_install_dir
- installer = Gem::Installer.new @gem, :install_dir => "#{@gemhome}2"
+ installer = Gem::Installer.at @gem, :install_dir => "#{@gemhome}2"
installer.build_args = %w[
--with-libyaml-dir /usr/local/Cellar/libyaml/0.1.4
@@ -1426,8 +1426,7 @@ gem 'other', version
FileUtils.mv cache_file, gem
refute_path_exists cache_file
- installer = Gem::Installer.new gem
- installer.spec = @spec
+ installer = Gem::Installer.at gem
installer.gem_home = @gemhome
installer.write_cache_file
@@ -1439,7 +1438,7 @@ gem 'other', version
FileUtils.rm @spec.spec_file
refute_path_exists @spec.spec_file
- @installer.spec = @spec
+ @installer = Gem::Installer.for_spec @spec
@installer.gem_home = @gemhome
@installer.write_spec
@@ -1459,7 +1458,7 @@ gem 'other', version
@spec.files = %w[a.rb b.rb c.rb]
- @installer.spec = @spec
+ @installer = Gem::Installer.for_spec @spec
@installer.gem_home = @gemhome
@installer.write_spec
@@ -1474,6 +1473,13 @@ gem 'other', version
assert_match %r!/gemhome/gems/a-2$!, @installer.dir
end
+ def test_default_gem_loaded_from
+ spec = util_spec 'a'
+ installer = Gem::Installer.for_spec spec, :install_as_default => true
+ installer.install
+ assert_predicate spec, :default_gem?
+ end
+
def test_default_gem
FileUtils.rm_f File.join(Gem.dir, 'specifications')
@@ -1490,10 +1496,10 @@ gem 'other', version
installed_exec = File.join util_inst_bindir, 'executable'
assert_path_exists installed_exec
- assert File.directory? File.join(Gem.dir, 'specifications')
- assert File.directory? File.join(Gem.dir, 'specifications', 'default')
+ assert File.directory? File.join(Gem.default_dir, 'specifications')
+ assert File.directory? File.join(Gem.default_dir, 'specifications', 'default')
- default_spec = eval File.read File.join(Gem.dir, 'specifications', 'default', 'a-2.gemspec')
+ default_spec = eval File.read File.join(Gem.default_dir, 'specifications', 'default', 'a-2.gemspec')
assert_equal Gem::Version.new("2"), default_spec.version
assert_equal ['bin/executable'], default_spec.files
end
diff --git a/test/rubygems/test_gem_package.rb b/test/rubygems/test_gem_package.rb
index 9d9c224..bbb036d 100644
--- a/test/rubygems/test_gem_package.rb
+++ b/test/rubygems/test_gem_package.rb
@@ -132,6 +132,37 @@ class TestGemPackage < Gem::Package::TarTestCase
assert_equal %w[lib/code.rb], files
end
+ def test_add_files_symlink
+ skip 'symlink not supported' if Gem.win_platform?
+
+ spec = Gem::Specification.new
+ spec.files = %w[lib/code.rb lib/code_sym.rb]
+
+ FileUtils.mkdir_p 'lib'
+ open 'lib/code.rb', 'w' do |io| io.write '# lib/code.rb' end
+ File.symlink('lib/code.rb', 'lib/code_sym.rb')
+
+ package = Gem::Package.new 'bogus.gem'
+ package.spec = spec
+
+ tar = util_tar do |tar_io|
+ package.add_files tar_io
+ end
+
+ tar.rewind
+
+ files, symlinks = [], []
+
+ Gem::Package::TarReader.new tar do |tar_io|
+ tar_io.each_entry do |entry|
+ (entry.symlink? ? symlinks : files) << entry.full_name
+ end
+ end
+
+ assert_equal %w[lib/code.rb], files
+ assert_equal %w[lib/code_sym.rb], symlinks
+ end
+
def test_build
spec = Gem::Specification.new 'build', '1'
spec.summary = 'build'
@@ -396,6 +427,21 @@ class TestGemPackage < Gem::Package::TarTestCase
"#{@destination} is not allowed", e.message)
end
+ def test_extract_tar_gz_symlink_absolute
+ package = Gem::Package.new @gem
+
+ tgz_io = util_tar_gz do |tar|
+ tar.add_symlink 'code.rb', '/absolute.rb', 0644
+ end
+
+ e = assert_raises Gem::Package::PathError do
+ package.extract_tar_gz tgz_io, @destination
+ end
+
+ assert_equal("installing into parent path /absolute.rb of " +
+ "#{@destination} is not allowed", e.message)
+ end
+
def test_extract_tar_gz_directory
package = Gem::Package.new @gem
@@ -821,4 +867,3 @@ class TestGemPackage < Gem::Package::TarTestCase
end
end
-
diff --git a/test/rubygems/test_gem_package_tar_reader_entry.rb b/test/rubygems/test_gem_package_tar_reader_entry.rb
index 1143187..335601b 100644
--- a/test/rubygems/test_gem_package_tar_reader_entry.rb
+++ b/test/rubygems/test_gem_package_tar_reader_entry.rb
@@ -92,6 +92,14 @@ class TestGemPackageTarReaderEntry < Gem::Package::TarTestCase
close_util_entry(dir_ent) if dir_ent
end
+ def test_symlink_eh
+ assert_equal false, @entry.symlink?
+ symlink_ent = util_symlink_entry
+ assert_equal true, symlink_ent.symlink?
+ ensure
+ close_util_entry(symlink_ent) if symlink_ent
+ end
+
def test_file_eh
assert_equal true, @entry.file?
dir_ent = util_dir_entry
@@ -131,4 +139,3 @@ class TestGemPackageTarReaderEntry < Gem::Package::TarTestCase
end
end
-
diff --git a/test/rubygems/test_gem_package_tar_writer.rb b/test/rubygems/test_gem_package_tar_writer.rb
index f087df3..dac9a54 100644
--- a/test/rubygems/test_gem_package_tar_writer.rb
+++ b/test/rubygems/test_gem_package_tar_writer.rb
@@ -30,6 +30,16 @@ class TestGemPackageTarWriter < Gem::Package::TarTestCase
assert_equal 1024, @io.pos
end
+ def test_add_symlink
+ Time.stub :now, Time.at(1458518157) do
+ @tar_writer.add_symlink 'x', 'y', 0644
+
+ assert_headers_equal(tar_symlink_header('x', '', 0644, Time.now, 'y'),
+ @io.string[0, 512])
+ end
+ assert_equal 512, @io.pos
+ end
+
def test_add_file_digest
digest_algorithms = Digest::SHA1, Digest::SHA512
@@ -251,4 +261,3 @@ class TestGemPackageTarWriter < Gem::Package::TarTestCase
end
end
-
diff --git a/test/rubygems/test_gem_request_connection_pools.rb b/test/rubygems/test_gem_request_connection_pools.rb
index 1cf6b27..403f767 100644
--- a/test/rubygems/test_gem_request_connection_pools.rb
+++ b/test/rubygems/test_gem_request_connection_pools.rb
@@ -80,6 +80,15 @@ class TestGemRequestConnectionPool < Gem::TestCase
assert_equal ['example', 80], net_http_args
end
+ def test_net_http_args_ipv6
+ pools = Gem::Request::ConnectionPools.new nil, []
+
+ net_http_args = pools.send :net_http_args, URI('http://[::1]'), nil
+
+ expected_host = RUBY_VERSION >= "1.9.3" ? "::1" : "[::1]"
+ assert_equal [expected_host, 80], net_http_args
+ end
+
def test_net_http_args_proxy
pools = Gem::Request::ConnectionPools.new nil, []
diff --git a/test/rubygems/test_gem_request_set.rb b/test/rubygems/test_gem_request_set.rb
index 3c1d5ac..8afab65 100644
--- a/test/rubygems/test_gem_request_set.rb
+++ b/test/rubygems/test_gem_request_set.rb
@@ -141,10 +141,9 @@ Gems to install:
def test_install_from_gemdeps_lockfile
spec_fetcher do |fetcher|
- fetcher.gem 'a', 1
- fetcher.gem 'a', 2
- fetcher.gem 'b', 1, 'a' => '>= 0'
- fetcher.clear
+ fetcher.download 'a', 1
+ fetcher.download 'a', 2
+ fetcher.download 'b', 1, 'a' => '>= 0'
end
rs = Gem::RequestSet.new
@@ -445,10 +444,8 @@ ruby "0"
end
spec_fetcher do |fetcher|
- fetcher.gem "a", "1", "b" => "= 1"
- fetcher.gem "b", "1"
-
- fetcher.clear
+ fetcher.download "a", "1", "b" => "= 1"
+ fetcher.download "b", "1"
end
rs = Gem::RequestSet.new
diff --git a/test/rubygems/test_gem_request_set_lockfile.rb b/test/rubygems/test_gem_request_set_lockfile.rb
index 6d5b4de..3b85e25 100644
--- a/test/rubygems/test_gem_request_set_lockfile.rb
+++ b/test/rubygems/test_gem_request_set_lockfile.rb
@@ -338,13 +338,11 @@ DEPENDENCIES
def test_to_s_gem_source
spec_fetcher do |fetcher|
- fetcher.spec 'a', 2
- fetcher.clear
+ fetcher.download 'a', 2
end
spec_fetcher 'http://other.example/' do |fetcher|
- fetcher.spec 'b', 2
- fetcher.clear
+ fetcher.download 'b', 2
end
Gem.sources << 'http://other.example/'
diff --git a/test/rubygems/test_gem_resolver.rb b/test/rubygems/test_gem_resolver.rb
index 2b9e9fe..c4b5251 100644
--- a/test/rubygems/test_gem_resolver.rb
+++ b/test/rubygems/test_gem_resolver.rb
@@ -95,24 +95,6 @@ class TestGemResolver < Gem::TestCase
assert_same index_set, composed
end
- def test_handle_conflict
- a1 = util_spec 'a', 1
-
- r1 = Gem::Resolver::DependencyRequest.new dep('a', '= 1'), nil
- r2 = Gem::Resolver::DependencyRequest.new dep('a', '= 2'), nil
- r3 = Gem::Resolver::DependencyRequest.new dep('a', '= 3'), nil
-
- existing = Gem::Resolver::ActivationRequest.new a1, r1, false
-
- res = Gem::Resolver.new [a1]
-
- res.handle_conflict r2, existing
- res.handle_conflict r2, existing
- res.handle_conflict r3, existing
-
- assert_equal 2, res.conflicts.length
- end
-
def test_requests
a1 = util_spec 'a', 1, 'b' => 2
@@ -122,11 +104,11 @@ class TestGemResolver < Gem::TestCase
res = Gem::Resolver.new [a1]
- reqs = Gem::Resolver::RequirementList.new
+ reqs = []
res.requests a1, act, reqs
- assert_equal ['b (= 2)'], reqs.to_a.map { |req| req.to_s }
+ assert_equal ['b (= 2)'], reqs.map { |req| req.to_s }
end
def test_requests_development
@@ -144,11 +126,11 @@ class TestGemResolver < Gem::TestCase
res = Gem::Resolver.new [act]
res.development = true
- reqs = Gem::Resolver::RequirementList.new
+ reqs = []
res.requests spec, act, reqs
- assert_equal ['b (= 2)'], reqs.to_a.map { |req| req.to_s }
+ assert_equal ['b (= 2)'], reqs.map { |req| req.to_s }
assert spec.instance_variable_defined? :@called
end
@@ -163,7 +145,7 @@ class TestGemResolver < Gem::TestCase
res = Gem::Resolver.new [a1]
res.ignore_dependencies = true
- reqs = Gem::Resolver::RequirementList.new
+ reqs = []
res.requests a1, act, reqs
@@ -438,19 +420,19 @@ class TestGemResolver < Gem::TestCase
r.resolve
end
- deps = [make_dep("c", "= 1"), make_dep("c", "= 2")]
+ deps = [make_dep("c", "= 2"), make_dep("c", "= 1")]
assert_equal deps, e.conflicting_dependencies
con = e.conflict
act = con.activated
- assert_equal "c-2", act.spec.full_name
+ assert_equal "c-1", act.spec.full_name
parent = act.parent
- assert_equal "b-1", parent.spec.full_name
+ assert_equal "a-1", parent.spec.full_name
act = con.requester
- assert_equal "a-1", act.spec.full_name
+ assert_equal "b-1", act.spec.full_name
end
def test_raises_when_a_gem_is_missing
@@ -538,11 +520,11 @@ class TestGemResolver < Gem::TestCase
assert_equal req('>= 0'), dependency.requirement
activated = e.conflict.activated
- assert_equal 'c-1', activated.full_name
+ assert_equal 'c-2', activated.full_name
- assert_equal dep('c', '= 1'), activated.request.dependency
+ assert_equal dep('c', '>= 2'), activated.request.dependency
- assert_equal [dep('c', '>= 2'), dep('c', '= 1')],
+ assert_equal [dep('c', '= 1'), dep('c', '>= 2')],
e.conflict.conflicting_dependencies
end
@@ -730,4 +712,3 @@ class TestGemResolver < Gem::TestCase
end
end
-
diff --git a/test/rubygems/test_gem_resolver_installer_set.rb b/test/rubygems/test_gem_resolver_installer_set.rb
index d7b917b..039582e 100644
--- a/test/rubygems/test_gem_resolver_installer_set.rb
+++ b/test/rubygems/test_gem_resolver_installer_set.rb
@@ -4,9 +4,8 @@ class TestGemResolverInstallerSet < Gem::TestCase
def test_add_always_install
spec_fetcher do |fetcher|
- fetcher.spec 'a', 1
- fetcher.spec 'a', 2
- fetcher.clear
+ fetcher.download 'a', 1
+ fetcher.download 'a', 2
end
util_gem 'a', 1
@@ -39,11 +38,10 @@ class TestGemResolverInstallerSet < Gem::TestCase
def test_add_always_install_platform
spec_fetcher do |fetcher|
- fetcher.spec 'a', 1
- fetcher.spec 'a', 2 do |s|
+ fetcher.download 'a', 1
+ fetcher.download 'a', 2 do |s|
s.platform = Gem::Platform.new 'x86-freebsd-9'
end
- fetcher.clear
end
set = Gem::Resolver::InstallerSet.new :both
@@ -139,8 +137,7 @@ class TestGemResolverInstallerSet < Gem::TestCase
def test_find_all_always_install
spec_fetcher do |fetcher|
- fetcher.spec 'a', 2
- fetcher.clear
+ fetcher.download 'a', 2
end
util_gem 'a', 1
@@ -156,9 +153,8 @@ class TestGemResolverInstallerSet < Gem::TestCase
def test_find_all_prerelease
spec_fetcher do |fetcher|
- fetcher.spec 'a', '1'
- fetcher.spec 'a', '1.a'
- fetcher.clear
+ fetcher.download 'a', '1'
+ fetcher.download 'a', '1.a'
end
set = Gem::Resolver::InstallerSet.new :both
diff --git a/test/rubygems/test_gem_resolver_lock_specification.rb b/test/rubygems/test_gem_resolver_lock_specification.rb
index f8a336e..9324035 100644
--- a/test/rubygems/test_gem_resolver_lock_specification.rb
+++ b/test/rubygems/test_gem_resolver_lock_specification.rb
@@ -1,4 +1,5 @@
require 'rubygems/test_case'
+require 'rubygems/installer'
require 'rubygems/resolver'
class TestGemResolverLockSpecification < Gem::TestCase
@@ -34,8 +35,7 @@ class TestGemResolverLockSpecification < Gem::TestCase
def test_install
spec_fetcher do |fetcher|
- fetcher.gem 'a', 2
- fetcher.clear
+ fetcher.download 'a', 2
end
spec = @LS.new @set, 'a', v(2), @source, Gem::Platform::RUBY
@@ -85,6 +85,7 @@ class TestGemResolverLockSpecification < Gem::TestCase
def test_spec_loaded
real_spec = util_spec 'a', 2
+ install_specs real_spec
real_spec.activate
version = v(2)
diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb
index 2765083..5784fa5 100644
--- a/test/rubygems/test_gem_specification.rb
+++ b/test/rubygems/test_gem_specification.rb
@@ -1,8 +1,10 @@
+require 'benchmark'
require 'rubygems/test_case'
require 'pathname'
require 'stringio'
require 'rubygems/ext'
require 'rubygems/specification'
+require 'rubygems/installer'
class TestGemSpecification < Gem::TestCase
@@ -112,7 +114,7 @@ end
c2 = new_spec "c", "2"
Gem::Specification.reset
- install_specs a1, b1, b2, c1, c2
+ install_specs c1, c2, b1, b2, a1
a1.activate
assert_equal %w(a-1), loaded_spec_names
@@ -125,6 +127,32 @@ end
end
end
+ def test_find_in_unresolved_tree_is_not_exponentiental
+ save_loaded_features do
+ num_of_pkg = 7
+ num_of_version_per_pkg = 3
+ packages = (0..num_of_pkg).map do |pkgi|
+ (0..num_of_version_per_pkg).map do |pkg_version|
+ deps = Hash[((pkgi + 1)..num_of_pkg).map { |deppkgi|
+ ["pkg#{deppkgi}", ">= 0"]
+ }]
+ new_spec "pkg#{pkgi}", pkg_version.to_s, deps
+ end
+ end
+ base = new_spec "pkg_base", "1", {"pkg0" => ">= 0"}
+
+ Gem::Specification.reset
+ install_specs(*packages.flatten.reverse)
+ install_specs base
+ base.activate
+
+ tms = Benchmark.measure {
+ assert_raises(LoadError) { require 'no_such_file_foo' }
+ }
+ assert_operator tms.total, :<=, 10
+ end
+ end
+
def test_self_activate_ambiguous_indirect
save_loaded_features do
a1 = new_spec "a", "1", "b" => "> 0"
@@ -133,7 +161,7 @@ end
c1 = new_spec "c", "1", nil, "lib/d.rb"
c2 = new_spec "c", "2", nil, "lib/d.rb"
- install_specs a1, b1, b2, c1, c2
+ install_specs c1, c2, b1, b2, a1
a1.activate
assert_equal %w(a-1), loaded_spec_names
@@ -155,7 +183,7 @@ end
c1 = new_spec "c", "1", nil, "lib/d.rb"
c2 = new_spec("c", "2", { "a" => "1" }, "lib/d.rb") # conflicts with a-2
- install_specs a1, a2, b1, b2, c1, c2
+ install_specs c1, b1, a1, a2, c2, b2
a2.activate
assert_equal %w(a-2), loaded_spec_names
@@ -177,7 +205,7 @@ end
c2 = new_spec "c", "2"
d1 = new_spec "d", "1", nil, "lib/d.rb"
- install_specs a1, b1, b2, c1, c2, d1
+ install_specs d1, c1, c2, b1, b2, a1
a1.activate
assert_equal %w(a-1), loaded_spec_names
@@ -190,6 +218,155 @@ end
end
end
+ def test_require_should_prefer_latest_gem_level1
+ save_loaded_features do
+ a1 = new_spec "a", "1", "b" => "> 0"
+ b1 = new_spec "b", "1", "c" => ">= 0" # unresolved
+ b2 = new_spec "b", "2", "c" => ">= 0"
+ c1 = new_spec "c", "1", nil, "lib/c.rb" # 1st level
+ c2 = new_spec "c", "2", nil, "lib/c.rb"
+
+ install_specs c1, c2, b1, b2, a1
+
+ a1.activate
+
+ require "c"
+
+ assert_equal %w(a-1 b-2 c-2), loaded_spec_names
+ end
+ end
+
+ def test_require_should_prefer_latest_gem_level2
+ save_loaded_features do
+ a1 = new_spec "a", "1", "b" => "> 0"
+ b1 = new_spec "b", "1", "c" => ">= 0" # unresolved
+ b2 = new_spec "b", "2", "c" => ">= 0"
+ c1 = new_spec "c", "1", "d" => ">= 0" # 1st level
+ c2 = new_spec "c", "2", "d" => ">= 0"
+ d1 = new_spec "d", "1", nil, "lib/d.rb" # 2nd level
+ d2 = new_spec "d", "2", nil, "lib/d.rb"
+
+ install_specs d1, d2, c1, c2, b1, b2, a1
+
+ a1.activate
+
+ require "d"
+
+ assert_equal %w(a-1 b-2 c-2 d-2), loaded_spec_names
+ end
+ end
+
+ def test_require_finds_in_2nd_level_indirect
+ save_loaded_features do
+ a1 = new_spec "a", "1", "b" => "> 0"
+ b1 = new_spec "b", "1", "c" => ">= 0" # unresolved
+ b2 = new_spec "b", "2", "c" => ">= 0"
+ c1 = new_spec "c", "1", "d" => "<= 2" # 1st level
+ c2 = new_spec "c", "2", "d" => "<= 2"
+ d1 = new_spec "d", "1", nil, "lib/d.rb" # 2nd level
+ d2 = new_spec "d", "2", nil, "lib/d.rb"
+ d3 = new_spec "d", "3", nil, "lib/d.rb"
+
+ install_specs d1, d2, d3, c1, c2, b1, b2, a1
+
+ a1.activate
+
+ require "d"
+
+ assert_equal %w(a-1 b-2 c-2 d-2), loaded_spec_names
+ end
+ end
+
+ def test_require_should_prefer_reachable_gems
+ save_loaded_features do
+ a1 = new_spec "a", "1", "b" => "> 0"
+ b1 = new_spec "b", "1", "c" => ">= 0" # unresolved
+ b2 = new_spec "b", "2", "c" => ">= 0"
+ c1 = new_spec "c", "1", "d" => "<= 2" # 1st level
+ c2 = new_spec "c", "2", "d" => "<= 2"
+ d1 = new_spec "d", "1", nil, "lib/d.rb" # 2nd level
+ d2 = new_spec "d", "2", nil, "lib/d.rb"
+ d3 = new_spec "d", "3", nil, "lib/d.rb"
+ e = new_spec "anti_d", "1", nil, "lib/d.rb"
+
+ install_specs d1, d2, d3, e, c1, c2, b1, b2, a1
+
+ a1.activate
+
+ require "d"
+
+ assert_equal %w(a-1 b-2 c-2 d-2), loaded_spec_names
+ end
+ end
+
+ def test_require_should_not_conflict
+ save_loaded_features do
+ base = new_spec "0", "1", "A" => ">= 1"
+ a1 = new_spec "A", "1", {"c" => ">= 2", "b" => "> 0"}, "lib/a.rb"
+ a2 = new_spec "A", "2", {"c" => ">= 2", "b" => "> 0"}, "lib/a.rb"
+ b1 = new_spec "b", "1", {"c" => "= 1"}, "lib/d.rb"
+ b2 = new_spec "b", "2", {"c" => "= 2"}, "lib/d.rb"
+ c1 = new_spec "c", "1", {}, "lib/c.rb"
+ c2 = new_spec "c", "2", {}, "lib/c.rb"
+ c3 = new_spec "c", "3", {}, "lib/c.rb"
+
+ install_specs c1, c2, c3, b1, b2, a1, a2, base
+
+ base.activate
+ assert_equal %w(0-1), loaded_spec_names
+ assert_equal ["A (>= 1)"], unresolved_names
+
+ require "d"
+
+ assert_equal %w(0-1 A-2 b-2 c-2), loaded_spec_names
+ assert_equal [], unresolved_names
+ end
+ end
+
+ def test_inner_clonflict_in_indirect_gems
+ save_loaded_features do
+ a1 = new_spec "a", "1", "b" => "> 0"
+ b1 = new_spec "b", "1", "c" => ">= 1" # unresolved
+ b2 = new_spec "b", "2", "c" => ">= 1", "d" => "< 3"
+ c1 = new_spec "c", "1", "d" => "<= 2" # 1st level
+ c2 = new_spec "c", "2", "d" => "<= 2"
+ c3 = new_spec "c", "3", "d" => "<= 3"
+ d1 = new_spec "d", "1", nil, "lib/d.rb" # 2nd level
+ d2 = new_spec "d", "2", nil, "lib/d.rb"
+ d3 = new_spec "d", "3", nil, "lib/d.rb"
+
+ install_specs d1, d2, d3, c1, c2, c3, b1, b2, a1
+
+ a1.activate
+
+ require "d"
+
+ assert_includes [%w(a-1 b-2 c-3 d-2),%w(a-1 b-2 d-2)], loaded_spec_names
+ end
+ end
+
+ def test_inner_clonflict_in_indirect_gems_reversed
+ save_loaded_features do
+ a1 = new_spec "a", "1", "b" => "> 0"
+ b1 = new_spec "b", "1", "xc" => ">= 1" # unresolved
+ b2 = new_spec "b", "2", "xc" => ">= 1", "d" => "< 3"
+ c1 = new_spec "xc", "1", "d" => "<= 3" # 1st level
+ c2 = new_spec "xc", "2", "d" => "<= 2"
+ c3 = new_spec "xc", "3", "d" => "<= 3"
+ d1 = new_spec "d", "1", nil, "lib/d.rb" # 2nd level
+ d2 = new_spec "d", "2", nil, "lib/d.rb"
+ d3 = new_spec "d", "3", nil, "lib/d.rb"
+
+ install_specs d1, d2, d3, c1, c2, c3, b1, b2, a1
+
+ a1.activate
+
+ require "d"
+
+ assert_includes [%w(a-1 b-2 d-2 xc-3), %w(a-1 b-2 d-2)], loaded_spec_names
+ end
+ end
+
##
# [A] depends on
# [C] = 1.0 depends on
@@ -197,13 +374,14 @@ end
# [B] ~> 1.0 (satisfied by 1.0)
def test_self_activate_checks_dependencies
- a, _ = util_spec 'a', '1.0'
+ a = util_spec 'a', '1.0'
a.add_dependency 'c', '= 1.0'
a.add_dependency 'b', '~> 1.0'
- util_spec 'b', '1.0'
- util_spec 'b', '2.0'
- c, _ = util_spec 'c', '1.0', 'b' => '= 2.0'
+ b1 = util_spec 'b', '1.0'
+ b2 = util_spec 'b', '2.0'
+ c = util_spec 'c', '1.0', 'b' => '= 2.0'
+ install_specs b1, b2, c, a
e = assert_raises Gem::LoadError do
assert_activate nil, a, c, "b"
@@ -220,10 +398,12 @@ end
# [B] = 2.0
def test_self_activate_divergent
- a, _ = util_spec 'a', '1.0', 'b' => '~> 1.0', 'c' => '= 1.0'
- util_spec 'b', '1.0'
- util_spec 'b', '2.0'
- c, _ = util_spec 'c', '1.0', 'b' => '= 2.0'
+ a = util_spec 'a', '1.0', 'b' => '~> 1.0', 'c' => '= 1.0'
+ b1 = util_spec 'b', '1.0'
+ b2 = util_spec 'b', '2.0'
+ c = util_spec 'c', '1.0', 'b' => '= 2.0'
+
+ install_specs b1, b2, c, a
e = assert_raises Gem::ConflictError do
assert_activate nil, a, c, "b"
@@ -241,6 +421,8 @@ end
@d1 = util_spec 'd', '1'
@d2 = util_spec 'd', '2'
+ install_specs @d1, @d2, e1
+
assert_activate %w[d-1 e-1], e1, "d"
end
@@ -259,6 +441,7 @@ end
@w1 = util_spec 'w', '1', 'x' => nil
util_set_arch 'cpu-my_platform1'
+ install_specs @x1_m, @x1_o, @w1
assert_activate %w[x-1-cpu-my_platform-1 w-1], @w1, @x1_m
end
@@ -274,6 +457,7 @@ end
end
@z1 = util_spec 'z', '1', 'y' => nil
+ install_specs @y1, @y1_1_p, @z1
assert_activate %w[y-1 z-1], @z1, @y1
end
@@ -291,6 +475,7 @@ end
s.add_dependency 'a'
s.add_development_dependency 'aa'
end
+ install_specs @a1_pre, @b1, @c1_pre
assert_activate %w[a-1.a b-1 c-1.a], @c1_pre, @a1_pre, @b1
end
@@ -300,7 +485,7 @@ end
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
+ install_specs b1, b2, a1
a1.activate
save_loaded_features do
@@ -320,7 +505,7 @@ end
d1 = new_spec "d", "1", { "c" => "< 2" }, "lib/d.rb"
d2 = new_spec "d", "2", { "c" => "< 2" }, "lib/d.rb" # this
- install_specs a1, b1, b2, c1, c2, d1, d2
+ install_specs c1, c2, b1, b2, d1, d2, a1
a1.activate
@@ -347,7 +532,7 @@ end
c1 = new_spec "c", "1"
c2 = new_spec "c", "2"
- install_specs a1, b1, b2, c1, c2
+ install_specs c1, c2, b1, b2, a1
a1.activate
assert_equal %w(a-1 b-1 c-1), loaded_spec_names
@@ -367,8 +552,9 @@ end
def test_self_activate_unrelated
a = util_spec 'a', '1.0', 'b' => '>= 1.0'
- util_spec 'b', '1.0'
+ b = util_spec 'b', '1.0'
c = util_spec 'c', '1.0'
+ install_specs b, c, a
assert_activate %w[b-1.0 c-1.0 a-1.0], a, c, "b"
end
@@ -384,10 +570,11 @@ end
def test_self_activate_over
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'
+ install_specs util_spec 'b', '1.0'
+ install_specs util_spec 'b', '1.1'
+ install_specs util_spec 'b', '2.0'
+ install_specs util_spec 'c', '1.0', 'b' => '~> 1.0'
+ install_specs a
a.activate
@@ -407,10 +594,12 @@ end
# first resolve through a dependency that is later pruned.
def test_self_activate_under
- a, _ = util_spec 'a', '1.0', 'b' => '~> 1.0', 'c' => '= 1.0'
- util_spec 'b', '1.0'
- util_spec 'b', '1.1'
- c, _ = util_spec 'c', '1.0', 'b' => '= 1.0'
+ a = util_spec 'a', '1.0', 'b' => '~> 1.0', 'c' => '= 1.0'
+ b1 = util_spec 'b', '1.0'
+ b1_1 = util_spec 'b', '1.1'
+ c = util_spec 'c', '1.0', 'b' => '= 1.0'
+
+ install_specs b1, b1_1, c, a
assert_activate %w[b-1.0 c-1.0 a-1.0], a, c, "b"
end
@@ -424,10 +613,11 @@ end
# [C1] depends on nothing
def test_self_activate_dropped
- a1, = util_spec 'a', '1', 'b' => nil
- util_spec 'b', '1', 'c' => nil
- util_spec 'b', '2'
- util_spec 'c', '1'
+ a1 = util_spec 'a', '1', 'b' => nil
+ b1 = util_spec 'b', '1', 'c' => nil
+ b2 = util_spec 'b', '2'
+ c1 = util_spec 'c', '1'
+ install_specs c1, b1, b2, a1
assert_activate %w[b-2 a-1], a1, "b"
end
@@ -443,17 +633,20 @@ end
# resolve.
def test_self_activate_raggi_the_edgecase_generator
- a, _ = util_spec 'a', '1.0', 'b' => '>= 1.0', 'c' => '>= 1.0'
- util_spec 'b', '1.0'
- util_spec 'b', '1.1', 'z' => '>= 1.0'
- c, _ = util_spec 'c', '1.0', 'b' => '= 1.0'
+ a = util_spec 'a', '1.0', 'b' => '>= 1.0', 'c' => '>= 1.0'
+ b1 = util_spec 'b', '1.0'
+ b1_0 = util_spec 'b', '1.1', 'z' => '>= 1.0'
+ c = util_spec 'c', '1.0', 'b' => '= 1.0'
+ z = util_spec 'z', '1'
+
+ install_specs z, b1, b1_0, c, z
assert_activate %w[b-1.0 c-1.0 a-1.0], a, c, "b"
end
def test_self_activate_conflict
- util_spec 'b', '1.0'
- util_spec 'b', '2.0'
+ install_specs util_spec 'b', '1.0'
+ install_specs util_spec 'b', '2.0'
gem "b", "= 1.0"
@@ -465,6 +658,7 @@ end
def test_self_all_equals
a = new_spec "foo", "1", nil, "lib/foo.rb"
+ install_specs a
Gem::Specification.all = [a]
assert_equal a, Gem::Specification.find_inactive_by_path('foo')
@@ -854,9 +1048,7 @@ dependencies: []
def test_self_outdated
spec_fetcher do |fetcher|
- fetcher.spec 'a', 4
-
- fetcher.clear
+ fetcher.download 'a', 4
fetcher.spec 'a', 3
end
@@ -866,10 +1058,8 @@ dependencies: []
def test_self_outdated_and_latest_remotes
specs = spec_fetcher do |fetcher|
- fetcher.spec 'a', 4
- fetcher.spec 'b', 3
-
- fetcher.clear
+ fetcher.download 'a', 4
+ fetcher.download 'b', 3
fetcher.spec 'a', '3.a'
fetcher.spec 'b', 2
@@ -884,10 +1074,13 @@ dependencies: []
end
def test_self_remove_spec
+ install_specs @a1
+
assert_includes Gem::Specification.all_names, 'a-1'
assert_includes Gem::Specification.stubs.map { |s| s.full_name }, 'a-1'
- Gem::Specification.remove_spec @a1
+ uninstall_gem @a1
+ Gem::Specification.reset
refute_includes Gem::Specification.all_names, 'a-1'
refute_includes Gem::Specification.stubs.map { |s| s.full_name }, 'a-1'
@@ -902,7 +1095,7 @@ dependencies: []
FileUtils.rm @a1.spec_file # bug #698
- Gem::Specification.remove_spec @a1
+ Gem::Specification.reset
refute_includes Gem::Specification.all_names, 'a-1'
refute_includes Gem::Specification.stubs.map { |s| s.full_name }, 'a-1'
@@ -1183,6 +1376,17 @@ dependencies: []
assert_path_exists @ext.extension_dir
end
+ def test_default_spec_stub_is_marked_default
+ default = new_default_spec 'default', 2
+ install_default_gems default
+
+ stub = Gem::Specification.stubs.find { |s| s.name == 'default' }
+ assert_predicate stub, :default_gem?
+
+ stub = Gem::Specification.find_all_by_name('default').first
+ assert_predicate stub, :default_gem?
+ end
+
def test_build_extensions_built
ext_spec
@@ -1419,7 +1623,9 @@ dependencies: []
assert_empty @gem.dependent_gems
- bonobo = util_spec 'bonobo'
+ bonobo = util_spec 'bonobo', 1
+ install_gem bonobo
+ install_gem @gem
expected = [
[@gem, @bonobo, [bonobo]],
@@ -1932,7 +2138,7 @@ dependencies: []
c1 = new_spec "c", "1", nil, "lib/d.rb"
c2 = new_spec("c", "2", { "a" => "1" }, "lib/d.rb") # conflicts with a-2
- install_specs a1, a2, b1, b2, c1, c2
+ install_specs c1, b1, a1, a2, c2, b2
a1.activate
c1.activate
@@ -2014,6 +2220,19 @@ dependencies: []
assert_equal ['test/suite.rb'], @a1.test_files
end
+ def test_runtime_predicate_true
+ @a2.add_runtime_dependency 'b', '1'
+ assert_predicate @a2.dependencies.first, :runtime?
+
+ @a2.dependencies.first.instance_variable_set :@type, nil
+ assert_predicate @a2.dependencies.first, :runtime?
+ end
+
+ def test_runtime_predicate_false
+ @a2.add_development_dependency 'b', '1'
+ refute_predicate @a2.dependencies.first, :runtime?
+ end
+
def test_to_ruby
@a2.add_runtime_dependency 'b', '1'
@a2.dependencies.first.instance_variable_set :@type, nil
@@ -2533,13 +2752,13 @@ duplicate dependency on b (>= 1.2.3), (~> 1.2) use:
@a1.extensions << 'ext/a/extconf.rb'
Dir.chdir @tempdir do
- FileUtils.ln_s '/root/path', 'lib2' unless vc_windows?
+ FileUtils.ln_s 'lib/code.rb', 'lib2' unless vc_windows?
- e = assert_raises Gem::InvalidSpecificationException do
+ use_ui @ui do
@a1.validate
end
- assert_equal '["lib2"] are not files', e.message
+ assert_match 'WARNING: lib2 is a symlink, which is not supported on all platforms', @ui.error
end
assert_equal %w[bin/exec ext/a/extconf.rb lib/code.rb lib2 test/suite.rb].sort,
@@ -2656,6 +2875,20 @@ http://opensource.org/licenses/alphabetical
end
end
+ def test_validate_permissions_of_missing_file_non_packaging
+ skip 'chmod not supported' if Gem.win_platform?
+
+ util_setup_validate
+
+ Dir.chdir @tempdir do
+ File.delete File.join('lib', 'code.rb')
+
+ use_ui @ui do
+ assert @a1.validate(false)
+ end
+ end
+ end
+
def test_validate_platform_legacy
util_setup_validate
@@ -2992,7 +3225,8 @@ end
end
def test_find_by_name
- util_spec "a"
+ install_specs util_spec "a"
+ install_specs util_spec "a", 1
assert Gem::Specification.find_by_name "a"
assert Gem::Specification.find_by_name "a", "1"
@@ -3008,6 +3242,8 @@ end
b.activate
+ install_specs b
+
assert Gem::Specification.find_by_name "b"
assert_raises Gem::LoadError do
diff --git a/test/rubygems/test_gem_stub_specification.rb b/test/rubygems/test_gem_stub_specification.rb
index 9d27312..e1ab834 100644
--- a/test/rubygems/test_gem_stub_specification.rb
+++ b/test/rubygems/test_gem_stub_specification.rb
@@ -9,7 +9,7 @@ class TestStubSpecification < Gem::TestCase
def setup
super
- @foo = Gem::StubSpecification.new FOO
+ @foo = Gem::StubSpecification.gemspec_stub FOO
end
def test_initialize
@@ -31,7 +31,7 @@ class TestStubSpecification < Gem::TestCase
end
def test_initialize_missing_stubline
- stub = Gem::StubSpecification.new(BAR)
+ stub = Gem::StubSpecification.gemspec_stub(BAR)
assert_equal "bar", stub.name
assert_equal Gem::Version.new("0.0.2"), stub.version
assert_equal Gem::Platform.new("ruby"), stub.platform
@@ -72,6 +72,21 @@ class TestStubSpecification < Gem::TestCase
assert_equal expected, stub.full_require_paths
end
+ def test_lib_dirs_glob
+ stub = stub_without_extension
+
+ assert_equal File.join(stub.full_gem_path, 'lib'), stub.lib_dirs_glob
+ end
+
+ def test_matches_for_glob
+ stub = stub_without_extension
+ code_rb = File.join stub.gem_dir, 'lib', 'code.rb'
+ FileUtils.mkdir_p File.dirname code_rb
+ FileUtils.touch code_rb
+
+ assert_equal code_rb, stub.matches_for_glob('code*').first
+ end
+
def test_missing_extensions_eh
stub = stub_with_extension do |s|
extconf_rb = File.join s.gem_dir, s.extensions.first
@@ -103,7 +118,7 @@ class TestStubSpecification < Gem::TestCase
io.write spec.to_ruby_for_cache
end
- default_spec = Gem::StubSpecification.new spec.loaded_from
+ default_spec = Gem::StubSpecification.gemspec_stub spec.loaded_from
refute default_spec.missing_extensions?
end
@@ -125,7 +140,7 @@ class TestStubSpecification < Gem::TestCase
def test_to_spec_with_other_specs_loaded_does_not_warn
real_foo = util_spec @foo.name, @foo.version
real_foo.activate
- bar = Gem::StubSpecification.new BAR
+ bar = Gem::StubSpecification.gemspec_stub BAR
refute_predicate Gem.loaded_specs, :empty?
assert bar.to_spec
end
@@ -164,7 +179,7 @@ end
io.flush
- stub = Gem::StubSpecification.new io.path
+ stub = Gem::StubSpecification.gemspec_stub io.path
yield stub if block_given?
@@ -187,7 +202,7 @@ end
io.flush
- stub = Gem::StubSpecification.new io.path
+ stub = Gem::StubSpecification.gemspec_stub io.path
yield stub if block_given?
diff --git a/test/rubygems/test_gem_uninstaller.rb b/test/rubygems/test_gem_uninstaller.rb
index 774fbe5..c682f72 100644
--- a/test/rubygems/test_gem_uninstaller.rb
+++ b/test/rubygems/test_gem_uninstaller.rb
@@ -158,6 +158,7 @@ class TestGemUninstaller < Gem::InstallerTestCase
uninstaller = Gem::Uninstaller.new nil
@spec.loaded_from = @spec.loaded_from.gsub @spec.full_name, '\&-legacy'
+ @spec.internal_init # blow out cache. but why did ^^ depend on cache?
@spec.platform = 'legacy'
assert_equal true, uninstaller.path_ok?(@gemhome, @spec)
@@ -236,7 +237,7 @@ create_makefile '#{@spec.name}'
use_ui @ui do
path = Gem::Package.build @spec
- installer = Gem::Installer.new path
+ installer = Gem::Installer.at path
installer.install
end
diff --git a/test/rubygems/test_gem_util.rb b/test/rubygems/test_gem_util.rb
index 414487a..2546262 100644
--- a/test/rubygems/test_gem_util.rb
+++ b/test/rubygems/test_gem_util.rb
@@ -27,5 +27,13 @@ class TestGemUtil < Gem::TestCase
assert_equal File.join(@tempdir, 'a'), enum.next
end
+ def test_linked_list_find
+ list = [1,2,3,4,5].inject(Gem::List.new(0)) { |m,o|
+ Gem::List.new o, m
+ }
+ assert_equal 5, list.find { |x| x == 5 }
+ assert_equal 4, list.find { |x| x == 4 }
+ end
+
end
diff --git a/test/rubygems/test_require.rb b/test/rubygems/test_require.rb
index dec5285..9690659 100644
--- a/test/rubygems/test_require.rb
+++ b/test/rubygems/test_require.rb
@@ -26,11 +26,11 @@ class TestGemRequire < Gem::TestCase
def setup
super
+ @old_loaded_features = $LOADED_FEATURES.dup
assert_raises LoadError do
- save_loaded_features do
- require 'test_gem_require_a'
- end
+ require 'test_gem_require_a'
end
+ $LOADED_FEATURES.replace @old_loaded_features
end
def assert_require(path)
@@ -49,6 +49,36 @@ class TestGemRequire < Gem::TestCase
end
end
+ # Providing -I on the commandline should always beat gems
+ def test_dash_i_beats_gems
+ a1 = new_spec "a", "1", {"b" => "= 1"}, "lib/test_gem_require_a.rb"
+ b1 = new_spec "b", "1", {"c" => "> 0"}, "lib/b/c.rb"
+ c1 = new_spec "c", "1", nil, "lib/c/c.rb"
+ c2 = new_spec "c", "2", nil, "lib/c/c.rb"
+
+ install_specs c1, c2, b1, a1
+
+ dir = Dir.mktmpdir
+ dash_i_arg = File.join dir, 'lib'
+
+ c_rb = File.join dash_i_arg, 'b', 'c.rb'
+
+ FileUtils.mkdir_p File.dirname c_rb
+ File.open(c_rb, 'w') { |f| f.write "class Object; HELLO = 'world' end" }
+
+ lp = $LOAD_PATH.dup
+
+ # Pretend to provide a commandline argument that overrides a file in gem b
+ $LOAD_PATH.unshift dash_i_arg
+
+ assert_require 'test_gem_require_a'
+ assert_require 'b/c' # this should be required from -I
+ assert_equal "world", ::Object::HELLO
+ ensure
+ $LOAD_PATH.replace lp
+ Object.send :remove_const, :HELLO if Object.const_defined? :HELLO
+ end
+
def test_concurrent_require
Object.const_set :FILE_ENTERED_LATCH, Latch.new(2)
Object.const_set :FILE_EXIT_LATCH, Latch.new(1)
@@ -82,16 +112,14 @@ class TestGemRequire < Gem::TestCase
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
+ install_specs b1, b2, a1
- save_loaded_features do
- assert_require 'test_gem_require_a'
- assert_equal %w(a-1 b-1), loaded_spec_names
- assert_equal unresolved_names, []
+ assert_require 'test_gem_require_a'
+ assert_equal %w(a-1 b-1), loaded_spec_names
+ assert_equal unresolved_names, []
- assert_require "b/c"
- assert_equal %w(a-1 b-1), loaded_spec_names
- end
+ assert_require "b/c"
+ assert_equal %w(a-1 b-1), loaded_spec_names
end
def test_require_is_lazy_with_inexact_req
@@ -99,32 +127,28 @@ class TestGemRequire < Gem::TestCase
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
+ install_specs b1, b2, a1
- save_loaded_features do
- assert_require 'test_gem_require_a'
- assert_equal %w(a-1), loaded_spec_names
- assert_equal unresolved_names, ["b (>= 1)"]
+ assert_require 'test_gem_require_a'
+ assert_equal %w(a-1), loaded_spec_names
+ assert_equal unresolved_names, ["b (>= 1)"]
- assert_require "b/c"
- assert_equal %w(a-1 b-2), loaded_spec_names
- end
+ assert_require "b/c"
+ assert_equal %w(a-1 b-2), loaded_spec_names
end
def test_require_is_not_lazy_with_one_possible
a1 = new_spec "a", "1", {"b" => ">= 1"}, "lib/test_gem_require_a.rb"
b1 = new_spec "b", "1", nil, "lib/b/c.rb"
- install_specs a1, b1
+ install_specs b1, a1
- save_loaded_features do
- assert_require 'test_gem_require_a'
- assert_equal %w(a-1 b-1), loaded_spec_names
- assert_equal unresolved_names, []
+ assert_require 'test_gem_require_a'
+ assert_equal %w(a-1 b-1), loaded_spec_names
+ assert_equal unresolved_names, []
- assert_require "b/c"
- assert_equal %w(a-1 b-1), loaded_spec_names
- end
+ assert_require "b/c"
+ assert_equal %w(a-1 b-1), loaded_spec_names
end
def test_require_can_use_a_pathname_object
@@ -132,129 +156,114 @@ class TestGemRequire < Gem::TestCase
install_specs a1
- save_loaded_features do
- assert_require Pathname.new 'test_gem_require_a'
- assert_equal %w(a-1), loaded_spec_names
- assert_equal unresolved_names, []
- end
+ assert_require Pathname.new 'test_gem_require_a'
+ assert_equal %w(a-1), loaded_spec_names
+ assert_equal unresolved_names, []
end
def test_activate_via_require_respects_loaded_files
- require 'benchmark' # stdlib
- save_loaded_features do
- a1 = new_spec "a", "1", {"b" => ">= 1"}, "lib/test_gem_require_a.rb"
- b1 = new_spec "b", "1", nil, "lib/benchmark.rb"
- b2 = new_spec "b", "2", nil, "lib/benchmark.rb"
+ a1 = new_spec "a", "1", {"b" => ">= 1"}, "lib/test_gem_require_a.rb"
+ b1 = new_spec "b", "1", nil, "lib/benchmark.rb"
+ b2 = new_spec "b", "2", nil, "lib/benchmark.rb"
- install_specs a1, b1, b2
+ install_specs b1, b2, a1
- require 'test_gem_require_a'
- assert_equal unresolved_names, ["b (>= 1)"]
+ require 'test_gem_require_a'
+ assert_equal unresolved_names, ["b (>= 1)"]
- refute require('benchmark'), "benchmark should have already been loaded"
+ refute require('benchmark'), "benchmark should have already been loaded"
- # We detected that we should activate b-2, so we did so, but
- # then original_require decided "I've already got benchmark.rb" loaded.
- # This case is fine because our lazy loading is provided exactly
- # the same behavior as eager loading would have.
+ # We detected that we should activate b-2, so we did so, but
+ # then original_require decided "I've already got benchmark.rb" loaded.
+ # This case is fine because our lazy loading is provided exactly
+ # the same behavior as eager loading would have.
- assert_equal %w(a-1 b-2), loaded_spec_names
- end
+ assert_equal %w(a-1 b-2), loaded_spec_names
end
def test_already_activated_direct_conflict
- save_loaded_features do
- a1 = new_spec "a", "1", { "b" => "> 0" }
- b1 = new_spec "b", "1", { "c" => ">= 1" }, "lib/ib.rb"
- b2 = new_spec "b", "2", { "c" => ">= 2" }, "lib/ib.rb"
- c1 = new_spec "c", "1", nil, "lib/d.rb"
- c2 = new_spec("c", "2", nil, "lib/d.rb")
+ a1 = new_spec "a", "1", { "b" => "> 0" }
+ b1 = new_spec "b", "1", { "c" => ">= 1" }, "lib/ib.rb"
+ b2 = new_spec "b", "2", { "c" => ">= 2" }, "lib/ib.rb"
+ c1 = new_spec "c", "1", nil, "lib/d.rb"
+ c2 = new_spec("c", "2", nil, "lib/d.rb")
- install_specs a1, b1, b2, c1, c2
+ install_specs c1, c2, b1, b2, a1
- a1.activate
- c1.activate
- assert_equal %w(a-1 c-1), loaded_spec_names
- assert_equal ["b (> 0)"], unresolved_names
+ a1.activate
+ c1.activate
+ assert_equal %w(a-1 c-1), loaded_spec_names
+ assert_equal ["b (> 0)"], unresolved_names
- assert require("ib")
+ assert require("ib")
- assert_equal %w(a-1 b-1 c-1), loaded_spec_names
- assert_equal [], unresolved_names
- end
+ assert_equal %w(a-1 b-1 c-1), loaded_spec_names
+ assert_equal [], unresolved_names
end
def test_multiple_gems_with_the_same_path
- save_loaded_features do
- a1 = new_spec "a", "1", { "b" => "> 0", "x" => "> 0" }
- b1 = new_spec "b", "1", { "c" => ">= 1" }, "lib/ib.rb"
- b2 = new_spec "b", "2", { "c" => ">= 2" }, "lib/ib.rb"
- x1 = new_spec "x", "1", nil, "lib/ib.rb"
- x2 = new_spec "x", "2", nil, "lib/ib.rb"
- c1 = new_spec "c", "1", nil, "lib/d.rb"
- c2 = new_spec("c", "2", nil, "lib/d.rb")
-
- install_specs a1, b1, b2, c1, c2, x1, x2
-
- a1.activate
- c1.activate
- assert_equal %w(a-1 c-1), loaded_spec_names
- assert_equal ["b (> 0)", "x (> 0)"], unresolved_names
-
- e = assert_raises(Gem::LoadError) do
- require("ib")
- end
-
- assert_equal "ib found in multiple gems: b, x", e.message
+ a1 = new_spec "a", "1", { "b" => "> 0", "x" => "> 0" }
+ b1 = new_spec "b", "1", { "c" => ">= 1" }, "lib/ib.rb"
+ b2 = new_spec "b", "2", { "c" => ">= 2" }, "lib/ib.rb"
+ x1 = new_spec "x", "1", nil, "lib/ib.rb"
+ x2 = new_spec "x", "2", nil, "lib/ib.rb"
+ c1 = new_spec "c", "1", nil, "lib/d.rb"
+ c2 = new_spec("c", "2", nil, "lib/d.rb")
+
+ install_specs c1, c2, x1, x2, b1, b2, a1
+
+ a1.activate
+ c1.activate
+ assert_equal %w(a-1 c-1), loaded_spec_names
+ assert_equal ["b (> 0)", "x (> 0)"], unresolved_names
+
+ e = assert_raises(Gem::LoadError) do
+ require("ib")
end
+
+ assert_equal "ib found in multiple gems: b, x", e.message
end
def test_unable_to_find_good_unresolved_version
- save_loaded_features do
- a1 = new_spec "a", "1", { "b" => "> 0" }
- b1 = new_spec "b", "1", { "c" => ">= 2" }, "lib/ib.rb"
- b2 = new_spec "b", "2", { "c" => ">= 3" }, "lib/ib.rb"
+ a1 = new_spec "a", "1", { "b" => "> 0" }
+ b1 = new_spec "b", "1", { "c" => ">= 2" }, "lib/ib.rb"
+ b2 = new_spec "b", "2", { "c" => ">= 3" }, "lib/ib.rb"
- c1 = new_spec "c", "1", nil, "lib/d.rb"
- c2 = new_spec "c", "2", nil, "lib/d.rb"
- c3 = new_spec "c", "3", nil, "lib/d.rb"
+ c1 = new_spec "c", "1", nil, "lib/d.rb"
+ c2 = new_spec "c", "2", nil, "lib/d.rb"
+ c3 = new_spec "c", "3", nil, "lib/d.rb"
- install_specs a1, b1, b2, c1, c2, c3
+ install_specs c1, c2, c3, b1, b2, a1
- a1.activate
- c1.activate
- assert_equal %w(a-1 c-1), loaded_spec_names
- assert_equal ["b (> 0)"], unresolved_names
+ a1.activate
+ c1.activate
+ assert_equal %w(a-1 c-1), loaded_spec_names
+ assert_equal ["b (> 0)"], unresolved_names
- e = assert_raises(Gem::LoadError) do
- require("ib")
- end
-
- assert_equal "unable to find a version of 'b' to activate", e.message
+ e = assert_raises(Gem::LoadError) do
+ require("ib")
end
+
+ assert_equal "unable to find a version of 'b' to activate", e.message
end
def test_default_gem_only
- save_loaded_features do
- default_gem_spec = new_default_spec("default", "2.0.0.0",
- nil, "default/gem.rb")
- install_default_specs(default_gem_spec)
- assert_require "default/gem"
- assert_equal %w(default-2.0.0.0), loaded_spec_names
- end
+ default_gem_spec = new_default_spec("default", "2.0.0.0",
+ nil, "default/gem.rb")
+ install_default_specs(default_gem_spec)
+ assert_require "default/gem"
+ assert_equal %w(default-2.0.0.0), loaded_spec_names
end
def test_default_gem_and_normal_gem
- save_loaded_features do
- default_gem_spec = new_default_spec("default", "2.0.0.0",
- nil, "default/gem.rb")
- install_default_specs(default_gem_spec)
- normal_gem_spec = new_spec("default", "3.0", nil,
- "lib/default/gem.rb")
- install_specs(normal_gem_spec)
- assert_require "default/gem"
- assert_equal %w(default-3.0), loaded_spec_names
- end
+ default_gem_spec = new_default_spec("default", "2.0.0.0",
+ nil, "default/gem.rb")
+ install_default_specs(default_gem_spec)
+ normal_gem_spec = new_spec("default", "3.0", nil,
+ "lib/default/gem.rb")
+ install_specs(normal_gem_spec)
+ assert_require "default/gem"
+ assert_equal %w(default-3.0), loaded_spec_names
end
def loaded_spec_names
@@ -264,12 +273,4 @@ class TestGemRequire < Gem::TestCase
def unresolved_names
Gem::Specification.unresolved_deps.values.map(&:to_s).sort
end
-
- def save_loaded_features
- old_loaded_features = $LOADED_FEATURES.dup
- yield
- ensure
- $LOADED_FEATURES.replace old_loaded_features
- end
-
end