summaryrefslogtreecommitdiff
path: root/test/rubygems
diff options
context:
space:
mode:
Diffstat (limited to 'test/rubygems')
-rw-r--r--test/rubygems/gemutilities.rb13
-rw-r--r--test/rubygems/test_gem.rb79
-rw-r--r--test/rubygems/test_gem_commands_environment_command.rb2
-rw-r--r--test/rubygems/test_gem_commands_query_command.rb11
-rw-r--r--test/rubygems/test_gem_commands_sources_command.rb2
-rw-r--r--test/rubygems/test_gem_commands_update_command.rb1
-rw-r--r--test/rubygems/test_gem_dependency_installer.rb2
-rw-r--r--test/rubygems/test_gem_remote_fetcher.rb5
-rw-r--r--test/rubygems/test_gem_server.rb2
-rw-r--r--test/rubygems/test_gem_source_index.rb22
-rw-r--r--test/rubygems/test_gem_source_info_cache.rb23
-rw-r--r--test/rubygems/test_open_uri.rb13
12 files changed, 131 insertions, 44 deletions
diff --git a/test/rubygems/gemutilities.rb b/test/rubygems/gemutilities.rb
index f12f4e88a5..967e3dc34d 100644
--- a/test/rubygems/gemutilities.rb
+++ b/test/rubygems/gemutilities.rb
@@ -61,6 +61,8 @@ class FakeFetcher
name = "#{spec.full_name}.gem"
path = File.join(install_dir, 'cache', name)
+ Gem.ensure_gem_subdirectories install_dir
+
if source_uri =~ /^http/ then
File.open(path, "wb") do |f|
f.write fetch_path(File.join(source_uri, "gems", name))
@@ -369,6 +371,17 @@ class RubyGemTestCase < Test::Unit::TestCase
Gem.win_platform?
end
+ # NOTE Allow tests to use a random (but controlled) port number instead of
+ # a hardcoded one. This helps CI tools when running parallels builds on
+ # the same builder slave.
+ def self.process_based_port
+ @@process_based_port ||= 8000 + $$ % 1000
+ end
+
+ def process_based_port
+ self.class.process_based_port
+ end
+
end
class TempIO
diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb
index b04d69d509..ab147abe65 100644
--- a/test/rubygems/test_gem.rb
+++ b/test/rubygems/test_gem.rb
@@ -237,23 +237,25 @@ class TestGem < RubyGemTestCase
assert_equal [Gem.dir], Gem.path
end
- def test_self_path_APPLE_GEM_HOME
- Gem.clear_paths
- Gem.const_set :APPLE_GEM_HOME, '/tmp/apple_gem_home'
-
- assert Gem.path.include?('/tmp/apple_gem_home')
- ensure
- Gem.send :remove_const, :APPLE_GEM_HOME
- end
-
- def test_self_path_APPLE_GEM_HOME_GEM_PATH
- Gem.clear_paths
- ENV['GEM_PATH'] = @gemhome
- Gem.const_set :APPLE_GEM_HOME, '/tmp/apple_gem_home'
-
- assert !Gem.path.include?('/tmp/apple_gem_home')
- ensure
- Gem.send :remove_const, :APPLE_GEM_HOME
+ unless win_platform?
+ def test_self_path_APPLE_GEM_HOME
+ Gem.clear_paths
+ Gem.const_set :APPLE_GEM_HOME, '/tmp/apple_gem_home'
+
+ assert Gem.path.include?('/tmp/apple_gem_home')
+ ensure
+ Gem.send :remove_const, :APPLE_GEM_HOME
+ end
+
+ def test_self_path_APPLE_GEM_HOME_GEM_PATH
+ Gem.clear_paths
+ ENV['GEM_PATH'] = @gemhome
+ Gem.const_set :APPLE_GEM_HOME, '/tmp/apple_gem_home'
+
+ assert !Gem.path.include?('/tmp/apple_gem_home')
+ ensure
+ Gem.send :remove_const, :APPLE_GEM_HOME
+ end
end
def test_self_path_ENV_PATH
@@ -303,21 +305,56 @@ class TestGem < RubyGemTestCase
def test_self_prefix
file_name = File.expand_path __FILE__
- assert_equal File.dirname(File.dirname(file_name)), Gem.prefix
+
+ prefix = File.dirname File.dirname(file_name)
+ prefix = File.dirname prefix if File.basename(prefix) == 'test'
+
+ assert_equal prefix, Gem.prefix
+ end
+
+ def test_self_prefix_libdir
+ orig_libdir = Gem::ConfigMap[:libdir]
+
+ file_name = File.expand_path __FILE__
+ prefix = File.dirname File.dirname(file_name)
+
+ Gem::ConfigMap[:libdir] = prefix
+
+ assert_nil Gem.prefix
+ ensure
+ Gem::ConfigMap[:libdir] = orig_libdir
end
- def test_self_prefix_odd
+ def test_self_prefix_sitelibdir
orig_sitelibdir = Gem::ConfigMap[:sitelibdir]
file_name = File.expand_path __FILE__
- prefix = File.join File.dirname(File.dirname(file_name)), 'lib'
- Gem::ConfigMap[:sitelibdir] = prefix.sub(/[\w]\//, '\&/')
+ prefix = File.dirname File.dirname(file_name)
+
+ Gem::ConfigMap[:sitelibdir] = prefix
assert_nil Gem.prefix
ensure
Gem::ConfigMap[:sitelibdir] = orig_sitelibdir
end
+ def test_self_refresh
+ util_make_gems
+
+ a1_spec = File.join @gemhome, "specifications", "#{@a1.full_name}.gemspec"
+
+ FileUtils.mv a1_spec, @tempdir
+
+ assert !Gem.source_index.gems.include?(@a1.full_name)
+
+ FileUtils.mv File.join(@tempdir, "#{@a1.full_name}.gemspec"), a1_spec
+
+ Gem.refresh
+
+ assert Gem.source_index.gems.include?(@a1.full_name)
+ assert_equal nil, Gem.instance_variable_get(:@searcher)
+ end
+
def test_self_required_location
util_make_gems
diff --git a/test/rubygems/test_gem_commands_environment_command.rb b/test/rubygems/test_gem_commands_environment_command.rb
index 5568478652..7cbb53bd88 100644
--- a/test/rubygems/test_gem_commands_environment_command.rb
+++ b/test/rubygems/test_gem_commands_environment_command.rb
@@ -20,7 +20,7 @@ class TestGemCommandsEnvironmentCommand < RubyGemTestCase
@cmd.execute
end
- assert_match %r|RUBYGEMS VERSION: (\d\.)+\d \((\d\.)+\d\)|, @ui.output
+ assert_match %r|RUBYGEMS VERSION: (\d\.)+\d|, @ui.output
assert_match %r|RUBY VERSION: \d\.\d\.\d \(.*\) \[.*\]|, @ui.output
assert_match %r|INSTALLATION DIRECTORY: #{Regexp.escape @gemhome}|,
@ui.output
diff --git a/test/rubygems/test_gem_commands_query_command.rb b/test/rubygems/test_gem_commands_query_command.rb
index 7e71419089..3c86c69a41 100644
--- a/test/rubygems/test_gem_commands_query_command.rb
+++ b/test/rubygems/test_gem_commands_query_command.rb
@@ -26,6 +26,7 @@ class TestGemCommandsQueryCommand < RubyGemTestCase
cache.update
cache.write_cache
cache.reset_cache_data
+ Gem::SourceInfoCache.reset
a2_name = @a2.full_name
@fetcher.data["#{@gem_repo}/quick/latest_index.rz"] = util_zip a2_name
@@ -43,6 +44,9 @@ class TestGemCommandsQueryCommand < RubyGemTestCase
*** REMOTE GEMS ***
+Updating metadata for 1 gems from http://gems.example.com/
+.
+complete
a (2)
EOF
@@ -55,6 +59,7 @@ a (2)
cache.update
cache.write_cache
cache.reset_cache_data
+ Gem::SourceInfoCache.reset
a1_name = @a1.full_name
a2_name = @a2.full_name
@@ -76,8 +81,8 @@ a (2)
*** REMOTE GEMS ***
-Updating metadata for 1 gems from http://gems.example.com/
-.
+Updating metadata for 2 gems from http://gems.example.com/
+..
complete
a (2, 1)
EOF
@@ -97,7 +102,7 @@ a (2, 1)
*** REMOTE GEMS ***
-a (2, 1)
+a (2)
This is a lot of text. This is a lot of text. This is a lot of text.
This is a lot of text.
diff --git a/test/rubygems/test_gem_commands_sources_command.rb b/test/rubygems/test_gem_commands_sources_command.rb
index 7ba88fad98..f15d44dfe8 100644
--- a/test/rubygems/test_gem_commands_sources_command.rb
+++ b/test/rubygems/test_gem_commands_sources_command.rb
@@ -181,6 +181,8 @@ beta-gems.example.com is not a URI
@cmd.handle_options %w[--update]
util_setup_source_info_cache
+ Gem::SourceInfoCache.reset
+
util_setup_fake_fetcher
si = Gem::SourceIndex.new
si.add_spec @a1
diff --git a/test/rubygems/test_gem_commands_update_command.rb b/test/rubygems/test_gem_commands_update_command.rb
index 1fcec6a075..6aeb53d25a 100644
--- a/test/rubygems/test_gem_commands_update_command.rb
+++ b/test/rubygems/test_gem_commands_update_command.rb
@@ -97,6 +97,7 @@ class TestGemCommandsUpdateCommand < RubyGemTestCase
assert_equal "Updating installed gems", out.shift
assert_match %r|Bulk updating|, out.shift
assert_equal "Updating #{@a2.name}", out.shift
+ assert_match %r|Bulk updating|, out.shift
assert_equal "Successfully installed #{@c2.full_name}", out.shift
assert_equal "Successfully installed #{@b2.full_name}", out.shift
assert_equal "Successfully installed #{@a2.full_name}", out.shift
diff --git a/test/rubygems/test_gem_dependency_installer.rb b/test/rubygems/test_gem_dependency_installer.rb
index 576143904a..914d4aa216 100644
--- a/test/rubygems/test_gem_dependency_installer.rb
+++ b/test/rubygems/test_gem_dependency_installer.rb
@@ -216,6 +216,8 @@ class TestGemDependencyInstaller < RubyGemTestCase
assert File.exist?(File.join(gemhome2, 'specifications',
"#{@a1.full_name}.gemspec"))
+ assert File.exist?(File.join(gemhome2, 'cache',
+ "#{@a1.full_name}.gem"))
end
def test_install_domain_both
diff --git a/test/rubygems/test_gem_remote_fetcher.rb b/test/rubygems/test_gem_remote_fetcher.rb
index 1ac71aabc2..ddadeb9fcf 100644
--- a/test/rubygems/test_gem_remote_fetcher.rb
+++ b/test/rubygems/test_gem_remote_fetcher.rb
@@ -76,8 +76,9 @@ gems:
# don't let 1.8 and 1.9 autotest collide
RUBY_VERSION =~ /(\d+)\.(\d+)\.(\d+)/
- PROXY_PORT = 12345 + $1.to_i * 100 + $2.to_i * 10 + $3.to_i
- SERVER_PORT = 23456 + $1.to_i * 100 + $2.to_i * 10 + $3.to_i
+ # don't let parallel runners collide
+ PROXY_PORT = process_based_port + 100 + $1.to_i * 100 + $2.to_i * 10 + $3.to_i
+ SERVER_PORT = process_based_port + 200 + $1.to_i * 100 + $2.to_i * 10 + $3.to_i
def setup
super
diff --git a/test/rubygems/test_gem_server.rb b/test/rubygems/test_gem_server.rb
index 463ce35180..24f88bf59e 100644
--- a/test/rubygems/test_gem_server.rb
+++ b/test/rubygems/test_gem_server.rb
@@ -15,7 +15,7 @@ class TestGemServer < RubyGemTestCase
@a1 = quick_gem 'a', '1'
- @server = Gem::Server.new Gem.dir, 8809, false
+ @server = Gem::Server.new Gem.dir, process_based_port, false
@req = WEBrick::HTTPRequest.new :Logger => nil
@res = WEBrick::HTTPResponse.new :HTTPVersion => '1.0'
end
diff --git a/test/rubygems/test_gem_source_index.rb b/test/rubygems/test_gem_source_index.rb
index 74aa91d63e..140f3ad067 100644
--- a/test/rubygems/test_gem_source_index.rb
+++ b/test/rubygems/test_gem_source_index.rb
@@ -395,13 +395,31 @@ class TestGemSourceIndex < RubyGemTestCase
assert_equal [updated_platform.name], @source_index.outdated
end
+ def test_refresh_bang
+ a1_spec = File.join @gemhome, "specifications", "#{@a1.full_name}.gemspec"
+
+ FileUtils.mv a1_spec, @tempdir
+
+ source_index = Gem::SourceIndex.from_installed_gems
+
+ assert !source_index.gems.include?(@a1.full_name)
+
+ FileUtils.mv File.join(@tempdir, "#{@a1.full_name}.gemspec"), a1_spec
+
+ source_index.refresh!
+
+ assert source_index.gems.include?(@a1.full_name)
+ end
+
def test_remove_extra
@source_index.add_spec @a1
@source_index.add_spec @a2
+ @source_index.add_spec @pl1
- @source_index.remove_extra [@a1.full_name]
+ @source_index.remove_extra [@a1.full_name, @pl1.full_name]
- assert_equal [@a1.full_name], @source_index.gems.map { |n,s| n }
+ assert_equal [@a1.full_name],
+ @source_index.gems.map { |n,s| n }.sort
end
def test_remove_extra_no_changes
diff --git a/test/rubygems/test_gem_source_info_cache.rb b/test/rubygems/test_gem_source_info_cache.rb
index 3bdaef5aa9..523b404280 100644
--- a/test/rubygems/test_gem_source_info_cache.rb
+++ b/test/rubygems/test_gem_source_info_cache.rb
@@ -287,6 +287,7 @@ class TestGemSourceInfoCache < RubyGemTestCase
@sic.set_cache_data @gem_repo => sice
@sic.update
+ @sic.instance_variable_set :@only_latest, false
@sic.write_cache
@sic.reset_cache_data
@@ -358,6 +359,7 @@ class TestGemSourceInfoCache < RubyGemTestCase
@sic.set_cache_data({@gem_repo => @sice_new})
@sic.update
@sic.write_cache
+ @sic.instance_variable_set :@only_latest, false
assert File.exist?(@sic.user_cache_file), 'user_cache_file'
assert File.exist?(@sic.latest_user_cache_file),
@@ -383,6 +385,7 @@ class TestGemSourceInfoCache < RubyGemTestCase
@sic.set_cache_data({ @gem_repo => @sice })
@sic.update
+
@sic.write_cache
assert File.exist?(@sic.user_cache_file), 'system_cache_file'
@@ -390,7 +393,7 @@ class TestGemSourceInfoCache < RubyGemTestCase
'latest_system_cache_file'
user_cache_data = read_cache(@sic.user_cache_file).to_a.sort
- assert_equal 1, user_cache_data.length
+ assert_equal 1, user_cache_data.length, 'user_cache_data length'
user_cache_data = user_cache_data.first
assert_equal @gem_repo, user_cache_data.first
@@ -417,6 +420,24 @@ class TestGemSourceInfoCache < RubyGemTestCase
assert_equal [[@gem_repo, @sys_sice]],
read_cache(@sic.system_cache_file).to_a.sort
+ assert_equal [[@gem_repo, @sys_sice]],
+ read_cache(@sic.user_cache_file).to_a.sort
+ assert_equal [[@gem_repo, @sice_new]],
+ read_cache(@sic.latest_user_cache_file).to_a.sort
+ end
+
+ def test_write_cache_user_only_latest
+ FileUtils.chmod 0444, @sic.system_cache_file
+ @sic.set_cache_data({@gem_repo => @sice_new})
+ @sic.update
+ @sic.write_cache
+
+ assert File.exist?(@sic.user_cache_file), 'user_cache_file'
+ assert File.exist?(@sic.latest_user_cache_file),
+ 'latest_user_cache_file exists'
+
+ assert_equal [[@gem_repo, @sys_sice]],
+ read_cache(@sic.system_cache_file).to_a.sort
assert_equal [[@gem_repo, @sice_new]],
read_cache(@sic.user_cache_file).to_a.sort
end
diff --git a/test/rubygems/test_open_uri.rb b/test/rubygems/test_open_uri.rb
deleted file mode 100644
index 6f18b7bb6b..0000000000
--- a/test/rubygems/test_open_uri.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-require 'test/unit'
-require 'rubygems/gem_open_uri'
-
-class TestOpenURI < Test::Unit::TestCase
-
- def test_open_uri_not_broken
- assert_nothing_raised do
- open __FILE__ do end
- end
- end
-
-end
-