summaryrefslogtreecommitdiff
path: root/test/rubygems/gemutilities.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/rubygems/gemutilities.rb')
-rw-r--r--test/rubygems/gemutilities.rb149
1 files changed, 63 insertions, 86 deletions
diff --git a/test/rubygems/gemutilities.rb b/test/rubygems/gemutilities.rb
index 967e3dc34d..d8818d0b01 100644
--- a/test/rubygems/gemutilities.rb
+++ b/test/rubygems/gemutilities.rb
@@ -10,10 +10,9 @@ at_exit { $SAFE = 1 }
require 'fileutils'
require 'test/unit'
require 'tmpdir'
-require 'tempfile'
require 'uri'
-require 'rubygems/source_info_cache'
require 'rubygems/package'
+require 'rubygems/test_utilities'
require File.join(File.expand_path(File.dirname(__FILE__)), 'mockgemui')
@@ -27,54 +26,6 @@ module Gem
end
end
-class FakeFetcher
-
- attr_reader :data
- attr_accessor :uri
- attr_accessor :paths
-
- def initialize
- @data = {}
- @paths = []
- @uri = nil
- end
-
- def fetch_path(path)
- path = path.to_s
- @paths << path
- raise ArgumentError, 'need full URI' unless path =~ %r'^http://'
- data = @data[path]
- raise Gem::RemoteFetcher::FetchError, "no data for #{path}" if data.nil?
- data.respond_to?(:call) ? data.call : data
- end
-
- def fetch_size(path)
- path = path.to_s
- @paths << path
- raise ArgumentError, 'need full URI' unless path =~ %r'^http://'
- data = @data[path]
- raise Gem::RemoteFetcher::FetchError, "no data for #{path}" if data.nil?
- data.respond_to?(:call) ? data.call : data.length
- end
-
- def download spec, source_uri, install_dir = Gem.dir
- 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))
- end
- else
- FileUtils.cp source_uri, path
- end
-
- path
- end
-end
-
class RubyGemTestCase < Test::Unit::TestCase
include Gem::DefaultUserInteraction
@@ -94,8 +45,13 @@ class RubyGemTestCase < Test::Unit::TestCase
@gemcache = File.join(@gemhome, "source_cache")
@usrcache = File.join(@gemhome, ".gem", "user_cache")
@latest_usrcache = File.join(@gemhome, ".gem", "latest_user_cache")
+ @userhome = File.join @tempdir, 'userhome'
+
+ ENV['HOME'] = @userhome
+ Gem.instance_variable_set :@user_home, nil
FileUtils.mkdir_p @gemhome
+ FileUtils.mkdir_p @userhome
ENV['GEMCACHE'] = @usrcache
Gem.use_paths(@gemhome)
@@ -104,9 +60,12 @@ class RubyGemTestCase < Test::Unit::TestCase
Gem.configuration.verbose = true
Gem.configuration.update_sources = true
- @gem_repo = "http://gems.example.com"
+ @gem_repo = "http://gems.example.com/"
+ @uri = URI.parse @gem_repo
Gem.sources.replace [@gem_repo]
+ Gem::SpecFetcher.fetcher = nil
+
@orig_BASERUBY = Gem::ConfigMap[:BASERUBY]
Gem::ConfigMap[:BASERUBY] = Gem::ConfigMap[:RUBY_INSTALL_NAME]
@@ -131,7 +90,7 @@ class RubyGemTestCase < Test::Unit::TestCase
Gem::ConfigMap[:arch] = @orig_arch
if defined? Gem::RemoteFetcher then
- Gem::RemoteFetcher.instance_variable_set :@fetcher, nil
+ Gem::RemoteFetcher.fetcher = nil
end
FileUtils.rm_rf @tempdir
@@ -141,7 +100,6 @@ class RubyGemTestCase < Test::Unit::TestCase
ENV.delete 'GEM_PATH'
Gem.clear_paths
- Gem::SourceInfoCache.instance_variable_set :@cache, nil
end
def install_gem gem
@@ -154,7 +112,7 @@ class RubyGemTestCase < Test::Unit::TestCase
end
gem = File.join(@tempdir, "#{gem.full_name}.gem").untaint
- Gem::Installer.new(gem).install
+ Gem::Installer.new(gem, :wrappers => true).install
end
def prep_cache_files(lc)
@@ -231,6 +189,8 @@ class RubyGemTestCase < Test::Unit::TestCase
spec.loaded_from = written_path
+ Gem.source_index.add_spec spec
+
return spec
end
@@ -254,6 +214,12 @@ class RubyGemTestCase < Test::Unit::TestCase
end
end
+ def util_clear_gems
+ FileUtils.rm_r File.join(@gemhome, 'gems')
+ FileUtils.rm_r File.join(@gemhome, 'specifications')
+ Gem.source_index.refresh!
+ end
+
def util_gem(name, version, &block)
spec = quick_gem(name, version, &block)
@@ -271,6 +237,16 @@ class RubyGemTestCase < Test::Unit::TestCase
[spec, cache_file]
end
+ def util_gzip(data)
+ out = StringIO.new
+
+ Zlib::GzipWriter.wrap out do |io|
+ io.write data
+ end
+
+ out.string
+ end
+
def util_make_gems
init = proc do |s|
s.files = %w[lib/code.rb]
@@ -303,7 +279,7 @@ class RubyGemTestCase < Test::Unit::TestCase
end
##
- # Set the platform to +cpu+ and +os+
+ # Set the platform to +arch+
def util_set_arch(arch)
Gem::ConfigMap[:arch] = arch
@@ -320,9 +296,7 @@ class RubyGemTestCase < Test::Unit::TestCase
require 'socket'
require 'rubygems/remote_fetcher'
- @uri = URI.parse @gem_repo
- @fetcher = FakeFetcher.new
- @fetcher.uri = @uri
+ @fetcher = Gem::FakeFetcher.new
util_make_gems
@@ -338,10 +312,11 @@ class RubyGemTestCase < Test::Unit::TestCase
@source_index.add_spec @a_evil9
@source_index.add_spec @c1_2
- Gem::RemoteFetcher.instance_variable_set :@fetcher, @fetcher
+ Gem::RemoteFetcher.fetcher = @fetcher
end
def util_setup_source_info_cache(*specs)
+ require 'rubygems/source_info_cache'
require 'rubygems/source_info_cache_entry'
specs = Hash[*specs.map { |spec| [spec.full_name, spec] }.flatten]
@@ -356,6 +331,35 @@ class RubyGemTestCase < Test::Unit::TestCase
sic.reset_cache_data
Gem::SourceInfoCache.instance_variable_set :@cache, sic
+
+ si
+ end
+
+ def util_setup_spec_fetcher(*specs)
+ specs = Hash[*specs.map { |spec| [spec.full_name, spec] }.flatten]
+ si = Gem::SourceIndex.new specs
+
+ spec_fetcher = Gem::SpecFetcher.fetcher
+
+ spec_fetcher.specs[@uri] = []
+ si.gems.sort_by { |_, spec| spec }.each do |_, spec|
+ spec_tuple = [spec.name, spec.version, spec.original_platform]
+ spec_fetcher.specs[@uri] << spec_tuple
+ end
+
+ spec_fetcher.latest_specs[@uri] = []
+ si.latest_specs.sort.each do |spec|
+ spec_tuple = [spec.name, spec.version, spec.original_platform]
+ spec_fetcher.latest_specs[@uri] << spec_tuple
+ end
+
+ si.gems.sort_by { |_,spec| spec }.each do |_, spec|
+ path = "#{@gem_repo}quick/Marshal.#{Gem.marshal_version}/#{spec.original_name}.gemspec.rz"
+ data = Marshal.dump spec
+ data_deflate = Zlib::Deflate.deflate data
+ @fetcher.data[path] = data_deflate
+ end
+
si
end
@@ -384,30 +388,3 @@ class RubyGemTestCase < Test::Unit::TestCase
end
-class TempIO
-
- @@count = 0
-
- def initialize(string = '')
- @tempfile = Tempfile.new "TempIO-#{@@count ++ 1}"
- @tempfile.binmode
- @tempfile.write string
- @tempfile.rewind
- end
-
- def method_missing(meth, *args, &block)
- @tempfile.send(meth, *args, &block)
- end
-
- def respond_to?(meth)
- @tempfile.respond_to? meth
- end
-
- def string
- @tempfile.flush
-
- Gem.read_binary @tempfile.path
- end
-
-end
-