From 8b424513fd43c398aaeea5dede8bbc5c51602773 Mon Sep 17 00:00:00 2001 From: drbrain Date: Thu, 26 Jun 2008 02:06:00 +0000 Subject: Upgrade to RubyGems 1.2.0 r1824. Incorporates [ruby-core:17353]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17576 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/rubygems/gemutilities.rb | 6 + test/rubygems/test_gem.rb | 10 +- test/rubygems/test_gem_config_file.rb | 63 ++++++++--- test/rubygems/test_gem_dependency_installer.rb | 25 ++++ test/rubygems/test_gem_ext_configure_builder.rb | 12 +- test/rubygems/test_gem_ext_rake_builder.rb | 4 +- test/rubygems/test_gem_indexer.rb | 36 +++++- test/rubygems/test_gem_install_update_options.rb | 31 ++++- test/rubygems/test_gem_installer.rb | 56 ++++++--- test/rubygems/test_gem_outdated_command.rb | 40 ------- test/rubygems/test_gem_remote_fetcher.rb | 138 ++++++++++++++++++----- test/rubygems/test_gem_spec_fetcher.rb | 6 +- test/rubygems/test_gem_specification.rb | 17 ++- 13 files changed, 320 insertions(+), 124 deletions(-) delete mode 100644 test/rubygems/test_gem_outdated_command.rb (limited to 'test') diff --git a/test/rubygems/gemutilities.rb b/test/rubygems/gemutilities.rb index d8818d0b01..c84b94a5e5 100644 --- a/test/rubygems/gemutilities.rb +++ b/test/rubygems/gemutilities.rb @@ -7,6 +7,8 @@ at_exit { $SAFE = 1 } +$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) + require 'fileutils' require 'test/unit' require 'tmpdir' @@ -24,6 +26,10 @@ module Gem def self.win_platform=(val) @@win_platform = val end + + module DefaultUserInteraction + @ui = MockGemUi.new + end end class RubyGemTestCase < Test::Unit::TestCase diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb index e5dcef0d57..0c2a03160d 100644 --- a/test/rubygems/test_gem.rb +++ b/test/rubygems/test_gem.rb @@ -279,16 +279,16 @@ class TestGem < RubyGemTestCase end def test_self_path_ENV_PATH - Gem.clear_paths + Gem.send :set_paths, nil path_count = Gem.path.size - path_count -= 1 if defined? APPLE_GEM_HOME Gem.clear_paths - util_ensure_gem_dirs ENV['GEM_PATH'] = @additional.join(File::PATH_SEPARATOR) assert_equal @additional, Gem.path[0,2] - assert_equal path_count + @additional.size, Gem.path.size + + assert_equal path_count + @additional.size, Gem.path.size, + "extra path components: #{Gem.path[2..-1].inspect}" assert_match Gem.dir, Gem.path.last end @@ -337,6 +337,7 @@ class TestGem < RubyGemTestCase file_name = File.expand_path __FILE__ prefix = File.dirname File.dirname(file_name) + prefix = File.dirname prefix if File.basename(prefix) == 'test' Gem::ConfigMap[:libdir] = prefix @@ -350,6 +351,7 @@ class TestGem < RubyGemTestCase file_name = File.expand_path __FILE__ prefix = File.dirname File.dirname(file_name) + prefix = File.dirname prefix if File.basename(prefix) == 'test' Gem::ConfigMap[:sitelibdir] = prefix diff --git a/test/rubygems/test_gem_config_file.rb b/test/rubygems/test_gem_config_file.rb index 46f200d88d..06321d4e7c 100644 --- a/test/rubygems/test_gem_config_file.rb +++ b/test/rubygems/test_gem_config_file.rb @@ -22,11 +22,15 @@ class TestGemConfigFile < RubyGemTestCase Gem::ConfigFile.send :remove_const, :SYSTEM_WIDE_CONFIG_FILE Gem::ConfigFile.send :const_set, :SYSTEM_WIDE_CONFIG_FILE, File.join(@tempdir, 'system-gemrc') + Gem::ConfigFile::OPERATING_SYSTEM_DEFAULTS.clear + Gem::ConfigFile::PLATFORM_DEFAULTS.clear util_config_file end def teardown + Gem::ConfigFile::OPERATING_SYSTEM_DEFAULTS.clear + Gem::ConfigFile::PLATFORM_DEFAULTS.clear Gem::ConfigFile.send :remove_const, :SYSTEM_WIDE_CONFIG_FILE Gem::ConfigFile.send :const_set, :SYSTEM_WIDE_CONFIG_FILE, @orig_SYSTEM_WIDE_CONFIG_FILE @@ -84,6 +88,48 @@ class TestGemConfigFile < RubyGemTestCase assert_equal @temp_conf, @cfg.config_file_name end + def test_initialize_operating_system_override + Gem::ConfigFile::OPERATING_SYSTEM_DEFAULTS[:bulk_threshold] = 1 + Gem::ConfigFile::OPERATING_SYSTEM_DEFAULTS['install'] = '--no-env-shebang' + + Gem::ConfigFile::PLATFORM_DEFAULTS[:bulk_threshold] = 2 + + util_config_file + + assert_equal 2, @cfg.bulk_threshold + assert_equal '--no-env-shebang', @cfg[:install] + end + + def test_initialize_platform_override + Gem::ConfigFile::PLATFORM_DEFAULTS[:bulk_threshold] = 2 + Gem::ConfigFile::PLATFORM_DEFAULTS['install'] = '--no-env-shebang' + + File.open Gem::ConfigFile::SYSTEM_WIDE_CONFIG_FILE, 'w' do |fp| + fp.puts ":bulk_threshold: 3" + end + + util_config_file + + assert_equal 3, @cfg.bulk_threshold + assert_equal '--no-env-shebang', @cfg[:install] + end + + def test_initialize_system_wide_override + File.open Gem::ConfigFile::SYSTEM_WIDE_CONFIG_FILE, 'w' do |fp| + fp.puts ":backtrace: false" + fp.puts ":bulk_threshold: 2048" + end + + File.open @temp_conf, 'w' do |fp| + fp.puts ":backtrace: true" + end + + util_config_file + + assert_equal 2048, @cfg.bulk_threshold + assert_equal true, @cfg.backtrace + end + def test_handle_arguments args = %w[--backtrace --bunch --of --args here] @@ -222,23 +268,6 @@ class TestGemConfigFile < RubyGemTestCase assert_equal %w[http://even-more-gems.example.com], Gem.sources end - def test_global_config_file - File.open(@temp_conf, 'w') do |fp| - fp.puts ":backtrace: true" - end - - File.open(File.join(Gem::ConfigFile::SYSTEM_WIDE_CONFIG_FILE), - 'w') do |fp| - fp.puts ":backtrace: false" - fp.puts ":bulk_threshold: 2048" - end - - util_config_file - - assert_equal 2048, @cfg.bulk_threshold - assert @cfg.backtrace - end - def util_config_file(args = @cfg_args) @cfg = Gem::ConfigFile.new args end diff --git a/test/rubygems/test_gem_dependency_installer.rb b/test/rubygems/test_gem_dependency_installer.rb index fbf92632b3..10e7fdfbda 100644 --- a/test/rubygems/test_gem_dependency_installer.rb +++ b/test/rubygems/test_gem_dependency_installer.rb @@ -66,6 +66,31 @@ class TestGemDependencyInstaller < RubyGemTestCase assert_equal [@a1], inst.installed_gems end + def test_install_all_dependencies + e1, e1_gem = util_gem 'e', '1' do |s| + s.add_dependency 'b' + end + + util_clear_gems + + FileUtils.mv @a1_gem, @tempdir + FileUtils.mv @b1_gem, @tempdir + FileUtils.mv e1_gem, @tempdir + inst = nil + + Dir.chdir @tempdir do + inst = Gem::DependencyInstaller.new :ignore_dependencies => true + inst.install 'b' + end + + Dir.chdir @tempdir do + inst = Gem::DependencyInstaller.new + inst.install 'e' + end + + assert_equal %w[e-1 a-1], inst.installed_gems.map { |s| s.full_name } + end + def test_install_cache_dir FileUtils.mv @a1_gem, @tempdir FileUtils.mv @b1_gem, @tempdir diff --git a/test/rubygems/test_gem_ext_configure_builder.rb b/test/rubygems/test_gem_ext_configure_builder.rb index d3d0efb489..2ed273a192 100644 --- a/test/rubygems/test_gem_ext_configure_builder.rb +++ b/test/rubygems/test_gem_ext_configure_builder.rb @@ -29,12 +29,12 @@ class TestGemExtConfigureBuilder < RubyGemTestCase Gem::Ext::ConfigureBuilder.build nil, nil, @dest_path, output end - expected = [ - "sh ./configure --prefix=#{@dest_path}", - "", "make", "ok\n", "make install", "ok\n" - ] - - assert_equal expected, output + assert_equal "sh ./configure --prefix=#{@dest_path}", output.shift + assert_equal "", output.shift + assert_equal "make", output.shift + assert_match(/^ok$/m, output.shift) + assert_equal "make install", output.shift + assert_match(/^ok$/m, output.shift) end def test_self_build_fail diff --git a/test/rubygems/test_gem_ext_rake_builder.rb b/test/rubygems/test_gem_ext_rake_builder.rb index cd63106077..cf8e2a6d6b 100644 --- a/test/rubygems/test_gem_ext_rake_builder.rb +++ b/test/rubygems/test_gem_ext_rake_builder.rb @@ -34,7 +34,7 @@ class TestGemExtRakeBuilder < RubyGemTestCase expected = [ "#{Gem.ruby} mkrf_conf.rb", "", - "rake RUBYARCHDIR=#{@dest_path} RUBYLIBDIR=#{@dest_path}", + "#{ENV['rake'] || 'rake'} RUBYARCHDIR=#{@dest_path} RUBYLIBDIR=#{@dest_path}", "(in #{realdir})\n" ] @@ -63,7 +63,7 @@ rake failed: #{Gem.ruby} mkrf_conf.rb -rake RUBYARCHDIR=#{@dest_path} RUBYLIBDIR=#{@dest_path} +#{ENV['rake'] || 'rake'} RUBYARCHDIR=#{@dest_path} RUBYLIBDIR=#{@dest_path} EOF assert_equal expected, error.message.split("\n")[0..4].join("\n") diff --git a/test/rubygems/test_gem_indexer.rb b/test/rubygems/test_gem_indexer.rb index 5ccaaff01f..9d68a7f34d 100644 --- a/test/rubygems/test_gem_indexer.rb +++ b/test/rubygems/test_gem_indexer.rb @@ -21,7 +21,6 @@ class TestGemIndexer < RubyGemTestCase util_make_gems @d2_0 = quick_gem 'd', '2.0' - write_file File.join(*%W[gems #{@d2_0.original_name} lib code.rb]) do end util_build_gem @d2_0 gems = File.join(@tempdir, 'gems') @@ -38,6 +37,41 @@ class TestGemIndexer < RubyGemTestCase @indexer.directory end + def test_build_indicies + spec = quick_gem 'd', '2.0' + spec.instance_variable_set :@original_platform, '' + + @indexer.make_temp_directories + + index = Gem::SourceIndex.new + index.add_spec spec + + use_ui @ui do + @indexer.build_indicies index + end + + specs_path = File.join @indexer.directory, "specs.#{@marshal_version}" + specs_dump = Gem.read_binary specs_path + specs = Marshal.load specs_dump + + expected = [ + ['d', Gem::Version.new('2.0'), 'ruby'], + ] + + assert_equal expected, specs, 'specs' + + latest_specs_path = File.join @indexer.directory, + "latest_specs.#{@marshal_version}" + latest_specs_dump = Gem.read_binary latest_specs_path + latest_specs = Marshal.load latest_specs_dump + + expected = [ + ['d', Gem::Version.new('2.0'), 'ruby'], + ] + + assert_equal expected, latest_specs, 'latest_specs' + end + def test_generate_index use_ui @ui do @indexer.generate_index diff --git a/test/rubygems/test_gem_install_update_options.rb b/test/rubygems/test_gem_install_update_options.rb index 8c7a5ce3f7..3638a0670a 100644 --- a/test/rubygems/test_gem_install_update_options.rb +++ b/test/rubygems/test_gem_install_update_options.rb @@ -1,20 +1,21 @@ require 'test/unit' require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities') +require File.join(File.expand_path(File.dirname(__FILE__)), + 'gem_installer_test_case') require 'rubygems/install_update_options' require 'rubygems/command' -class TestGemInstallUpdateOptions < RubyGemTestCase +class TestGemInstallUpdateOptions < GemInstallerTestCase def setup super @cmd = Gem::Command.new 'dummy', 'dummy' @cmd.extend Gem::InstallUpdateOptions + @cmd.add_install_update_options end def test_add_install_update_options - @cmd.add_install_update_options - args = %w[-i /install_to --rdoc --ri -E -f -t -w -P HighSecurity --ignore-dependencies --format-exec --include-dependencies] @@ -22,8 +23,6 @@ class TestGemInstallUpdateOptions < RubyGemTestCase end def test_security_policy - @cmd.add_install_update_options - @cmd.handle_options %w[-P HighSecurity] assert_equal Gem::Security::HighSecurity, @cmd.options[:security_policy] @@ -37,4 +36,26 @@ class TestGemInstallUpdateOptions < RubyGemTestCase end end + def test_user_install_enabled + @cmd.handle_options %w[--user-install] + + @installer = Gem::Installer.new @gem, @cmd.options + @installer.install + assert File.exist?(File.join(@userhome, '.gem', 'gems')) + assert File.exist?(File.join(@userhome, '.gem', 'gems', + @spec.full_name)) + end + + def test_user_install_disabled_read_only + @cmd.handle_options %w[--no-user-install] + + File.chmod 0755, @userhome + FileUtils.chmod 0000, @gemhome + + assert_raises(Gem::FilePermissionError) do + @installer = Gem::Installer.new @gem, @cmd.options + end + ensure + FileUtils.chmod 0755, @gemhome + end end diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb index f57d1c820c..a2547abedb 100644 --- a/test/rubygems/test_gem_installer.rb +++ b/test/rubygems/test_gem_installer.rb @@ -515,6 +515,7 @@ load 'my_exec' spec = quick_gem 'a' do |s| s.platform = Gem::Platform.new 'mswin32' end gem = File.join @tempdir, "#{spec.full_name}.gem" + Dir.mkdir util_inst_bindir util_build_gem spec FileUtils.mv File.join(@gemhome, 'cache', "#{spec.full_name}.gem"), @tempdir @@ -525,6 +526,7 @@ load 'my_exec' end def test_install + Dir.mkdir util_inst_bindir util_setup_gem use_ui @ui do @@ -593,6 +595,7 @@ load 'my_exec' end def test_install_ignore_dependencies + Dir.mkdir util_inst_bindir @spec.add_dependency 'b', '> 5' util_setup_gem @installer.ignore_dependencies = true @@ -634,7 +637,44 @@ load 'my_exec' assert File.exist?(File.join(@gemhome, 'specifications', "#{@spec.full_name}.gemspec")) end + unless win_platform? # File.chmod doesn't work + def test_install_user_local_fallback + Dir.mkdir util_inst_bindir + File.chmod 0755, @userhome + File.chmod 0000, util_inst_bindir + File.chmod 0000, Gem.dir + install_dir = File.join @userhome, '.gem', 'gems', @spec.full_name + @spec.executables = ["executable"] + + use_ui @ui do + util_setup_gem + @installer.install + end + + assert File.exist?(File.join(install_dir, 'lib', 'code.rb')) + assert File.exist?(File.join(@userhome, '.gem', 'bin', 'executable')) + ensure + File.chmod 0755, Gem.dir + File.chmod 0755, util_inst_bindir + end + + def test_install_bindir_read_only + Dir.mkdir util_inst_bindir + File.chmod 0755, @userhome + File.chmod 0000, util_inst_bindir + use_ui @ui do + setup + util_setup_gem + @installer.install + end + + assert File.exist?(File.join(@userhome, '.gem', 'bin', 'executable')) + ensure + File.chmod 0755, util_inst_bindir + end + end + def test_install_with_message @spec.post_install_message = 'I am a shiny gem!' @@ -647,22 +687,6 @@ load 'my_exec' assert_match %r|I am a shiny gem!|, @ui.output end - def test_install_writable - util_setup_gem - - orig_mode = File.stat(Gem.dir).mode - File.chmod 0000, Gem.dir - - e = assert_raise Gem::FilePermissionError do - @installer.install - end - - assert_equal "You don't have write permissions into the #{@gemhome} directory.", - e.message - ensure - File.chmod orig_mode, Gem.dir - end - def test_install_wrong_ruby_version use_ui @ui do installer = Gem::Installer.new old_ruby_required diff --git a/test/rubygems/test_gem_outdated_command.rb b/test/rubygems/test_gem_outdated_command.rb deleted file mode 100644 index adcc4d1980..0000000000 --- a/test/rubygems/test_gem_outdated_command.rb +++ /dev/null @@ -1,40 +0,0 @@ -require 'test/unit' -require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities') -require 'rubygems/commands/outdated_command' - -class TestGemOutdatedCommand < RubyGemTestCase - - def setup - super - - @cmd = Gem::Commands::OutdatedCommand.new - end - - def test_initialize - assert @cmd.handles?(%W[--platform #{Gem::Platform.local}]) - end - - def test_execute - local_01 = quick_gem 'foo', '0.1' - local_02 = quick_gem 'foo', '0.2' - remote_10 = quick_gem 'foo', '1.0' - remote_20 = quick_gem 'foo', '2.0' - - remote_spec_file = File.join @gemhome, 'specifications', - remote_10.full_name + ".gemspec" - FileUtils.rm remote_spec_file - - remote_spec_file = File.join @gemhome, 'specifications', - remote_20.full_name + ".gemspec" - FileUtils.rm remote_spec_file - - util_setup_source_info_cache remote_10, remote_20 - - use_ui @ui do @cmd.execute end - - assert_equal "foo (0.2 < 2.0)\n", @ui.output - assert_equal "", @ui.error - end - -end - diff --git a/test/rubygems/test_gem_remote_fetcher.rb b/test/rubygems/test_gem_remote_fetcher.rb index 1d2103bd06..484104dd8f 100644 --- a/test/rubygems/test_gem_remote_fetcher.rb +++ b/test/rubygems/test_gem_remote_fetcher.rb @@ -10,6 +10,7 @@ require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities') require 'webrick' require 'zlib' require 'rubygems/remote_fetcher' +require 'ostruct' # = Testing Proxy Settings # @@ -106,6 +107,8 @@ gems: @a1, @a1_gem = util_gem 'a', '1' do |s| s.executables << 'a_bin' end Gem::RemoteFetcher.fetcher = nil + + @fetcher = Gem::RemoteFetcher.fetcher end def test_self_fetcher @@ -117,7 +120,10 @@ gems: def test_self_fetcher_with_proxy proxy_uri = 'http://proxy.example.com' Gem.configuration[:http_proxy] = proxy_uri + Gem::RemoteFetcher.fetcher = nil + fetcher = Gem::RemoteFetcher.fetcher + assert_not_nil fetcher assert_kind_of Gem::RemoteFetcher, fetcher assert_equal proxy_uri, fetcher.instance_variable_get(:@proxy_uri).to_s @@ -145,7 +151,7 @@ gems: def test_fetch_size_socket_error fetcher = Gem::RemoteFetcher.new nil def fetcher.connection_for(uri) - raise SocketError + raise SocketError, "tarded" end uri = 'http://gems.example.com/yaml' @@ -153,15 +159,13 @@ gems: fetcher.fetch_size uri end - assert_equal "SocketError (SocketError)\n\tfetching size (#{uri})", - e.message + assert_equal "SocketError: tarded (#{uri})", e.message end def test_no_proxy use_ui @ui do - fetcher = Gem::RemoteFetcher.new nil - assert_data_from_server fetcher.fetch_path(@server_uri) - assert_equal SERVER_DATA.size, fetcher.fetch_size(@server_uri) + assert_data_from_server @fetcher.fetch_path(@server_uri) + assert_equal SERVER_DATA.size, @fetcher.fetch_size(@server_uri) end end @@ -238,6 +242,7 @@ gems: install_dir = File.join @tempdir, 'more_gems' a1_cache_gem = File.join install_dir, 'cache', "#{@a1.full_name}.gem" + FileUtils.mkdir_p(File.dirname(a1_cache_gem)) actual = fetcher.download(@a1, 'http://gems.example.com', install_dir) assert_equal a1_cache_gem, actual @@ -247,7 +252,7 @@ gems: assert File.exist?(a1_cache_gem) end - unless win_platform? then # File.chmod doesn't work + unless win_platform? # File.chmod doesn't work def test_download_local_read_only FileUtils.mv @a1_gem, @tempdir local_path = File.join @tempdir, "#{@a1.full_name}.gem" @@ -263,6 +268,19 @@ gems: ensure File.chmod 0755, File.join(@gemhome, 'cache') end + + def test_download_read_only + File.chmod 0555, File.join(@gemhome, 'cache') + File.chmod 0555, File.join(@gemhome) + + fetcher = util_fuck_with_fetcher File.read(@a1_gem) + fetcher.download(@a1, 'http://gems.example.com') + assert File.exist?(File.join(@userhome, '.gem', + 'cache', "#{@a1.full_name}.gem")) + ensure + File.chmod 0755, File.join(@gemhome) + File.chmod 0755, File.join(@gemhome, 'cache') + end end def test_download_platform_legacy @@ -363,10 +381,22 @@ gems: end end + def test_fetch_path_gzip + fetcher = Gem::RemoteFetcher.new nil + + def fetcher.open_uri_or_path(uri, mtime, head = nil) + Gem.gzip 'foo' + end + + assert_equal 'foo', fetcher.fetch_path(@uri + 'foo.gz') + end + def test_fetch_path_io_error fetcher = Gem::RemoteFetcher.new nil - def fetcher.open_uri_or_path(uri) raise EOFError; end + def fetcher.open_uri_or_path(uri, mtime, head = nil) + raise EOFError + end e = assert_raise Gem::RemoteFetcher::FetchError do fetcher.fetch_path 'uri' @@ -379,7 +409,9 @@ gems: def test_fetch_path_socket_error fetcher = Gem::RemoteFetcher.new nil - def fetcher.open_uri_or_path(uri) raise SocketError; end + def fetcher.open_uri_or_path(uri, mtime, head = nil) + raise SocketError + end e = assert_raise Gem::RemoteFetcher::FetchError do fetcher.fetch_path 'uri' @@ -392,7 +424,7 @@ gems: def test_fetch_path_system_call_error fetcher = Gem::RemoteFetcher.new nil - def fetcher.open_uri_or_path(uri); + def fetcher.open_uri_or_path(uri, mtime = nil, head = nil) raise Errno::ECONNREFUSED, 'connect(2)' end @@ -405,6 +437,16 @@ gems: assert_equal 'uri', e.uri end + def test_fetch_path_unmodified + fetcher = Gem::RemoteFetcher.new nil + + def fetcher.open_uri_or_path(uri, mtime, head = nil) + '' + end + + assert_equal '', fetcher.fetch_path(URI.parse(@gem_repo), Time.at(0)) + end + def test_get_proxy_from_env_empty orig_env_HTTP_PROXY = ENV['HTTP_PROXY'] orig_env_http_proxy = ENV['http_proxy'] @@ -475,9 +517,9 @@ gems: conn = { 'gems.example.com:80' => conn } fetcher.instance_variable_set :@connections, conn - fetcher.send :open_uri_or_path, 'http://gems.example.com/redirect' do |io| - assert_equal 'real_path', io.read - end + data = fetcher.open_uri_or_path 'http://gems.example.com/redirect' + + assert_equal 'real_path', data end def test_open_uri_or_path_limited_redirects @@ -495,29 +537,43 @@ gems: fetcher.instance_variable_set :@connections, conn e = assert_raise Gem::RemoteFetcher::FetchError do - fetcher.send :open_uri_or_path, 'http://gems.example.com/redirect' + fetcher.open_uri_or_path 'http://gems.example.com/redirect' end assert_equal 'too many redirects (http://gems.example.com/redirect)', e.message end - def test_zip - use_ui @ui do - self.class.enable_zip = true - fetcher = Gem::RemoteFetcher.new nil - assert_equal SERVER_DATA.size, fetcher.fetch_size(@server_uri), "probably not from proxy" - zip_data = fetcher.fetch_path(@server_z_uri) - assert zip_data.size < SERVER_DATA.size, "Zipped data should be smaller" - end + def test_request + uri = URI.parse "#{@gem_repo}/specs.#{Gem.marshal_version}" + util_stub_connection_for :body => :junk, :code => 200 + + response = @fetcher.request uri, Net::HTTP::Get + + assert_equal 200, response.code + assert_equal :junk, response.body end - def test_no_zip - use_ui @ui do - self.class.enable_zip = false - fetcher = Gem::RemoteFetcher.new nil - assert_error { fetcher.fetch_path(@server_z_uri) } - end + def test_request_head + uri = URI.parse "#{@gem_repo}/specs.#{Gem.marshal_version}" + util_stub_connection_for :body => '', :code => 200 + response = @fetcher.request uri, Net::HTTP::Head + + assert_equal 200, response.code + assert_equal '', response.body + end + + def test_request_unmodifed + uri = URI.parse "#{@gem_repo}/specs.#{Gem.marshal_version}" + conn = util_stub_connection_for :body => '', :code => 304 + + t = Time.now + response = @fetcher.request uri, Net::HTTP::Head, t + + assert_equal 304, response.code + assert_equal '', response.body + + assert_equal t.rfc2822, conn.payload['if-modified-since'] end def test_yaml_error_on_size @@ -528,7 +584,17 @@ gems: end end - private + def util_stub_connection_for hash + def @fetcher.connection= conn + @conn = conn + end + + def @fetcher.connection_for uri + @conn + end + + @fetcher.connection = Conn.new OpenStruct.new(hash) + end def assert_error(exception_class=Exception) got_exception = false @@ -548,6 +614,20 @@ gems: assert_block("Data is not from proxy") { data =~ /0\.4\.2/ } end + class Conn + attr_accessor :payload + + def initialize(response) + @response = response + self.payload = nil + end + + def request(req) + self.payload = req + @response + end + end + class NilLog < WEBrick::Log def log(level, data) #Do nothing end diff --git a/test/rubygems/test_gem_spec_fetcher.rb b/test/rubygems/test_gem_spec_fetcher.rb index 8b97787023..2e9ce1b7eb 100644 --- a/test/rubygems/test_gem_spec_fetcher.rb +++ b/test/rubygems/test_gem_spec_fetcher.rb @@ -280,7 +280,7 @@ RubyGems will revert to legacy indexes degrading performance. end def test_load_specs_cached - @fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] = nil + @fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] = '' @fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}"] = ' ' * Marshal.dump(@latest_specs).length @@ -294,9 +294,9 @@ RubyGems will revert to legacy indexes degrading performance. Marshal.dump @latest_specs, io end - specs = @sf.load_specs @uri, 'specs' + latest_specs = @sf.load_specs @uri, 'latest_specs' - assert_equal @specs, specs + assert_equal @latest_specs, latest_specs end end diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb index 003ded7bc0..57c3fdc158 100644 --- a/test/rubygems/test_gem_specification.rb +++ b/test/rubygems/test_gem_specification.rb @@ -71,6 +71,8 @@ end File.open File.join(@tempdir, 'bin', 'exec'), 'w' do |fp| fp.puts "#!#{Gem.ruby}" end + + @current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION end def test_self_attribute_names @@ -112,6 +114,19 @@ end assert_equal expected_value, actual_value end + def test_self__load_future + spec = Gem::Specification.new + spec.name = 'a' + spec.version = '1' + spec.specification_version = @current_version + 1 + + new_spec = Marshal.load Marshal.dump(spec) + + assert_equal 'a', new_spec.name + assert_equal Gem::Version.new(1), new_spec.version + assert_equal @current_version, new_spec.specification_version + end + def test_self_load spec = File.join @gemhome, 'specifications', "#{@a2.full_name}.gemspec" gs = Gem::Specification.load spec @@ -689,7 +704,7 @@ end if s.respond_to? :specification_version then current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION - s.specification_version = 3 + s.specification_version = 2 if current_version >= 3 then s.add_runtime_dependency(%q, [\"> 0.4\"]) -- cgit v1.2.3