setup()
public
#setup prepares a sandboxed location
to install gems. All installs are directed to a temporary directory. All
install plugins are removed.
If the RUBY environment variable is set the given path is used for
Gem::ruby. The local platform is set to i386-mswin32 for Windows
or i686-darwin8.10.1 otherwise.
If the KEEP_FILES environment variable is set the files will not
be removed from /tmp/test_rubygems_#{$$}.#{Time.now.to_i}.
Show source
def setup
super
@orig_gem_home = ENV['GEM_HOME']
@orig_gem_path = ENV['GEM_PATH']
@current_dir = Dir.pwd
@fetcher = nil
@ui = Gem::MockGemUi.new
tmpdir = File.expand_path Dir.tmpdir
tmpdir.untaint
if ENV['KEEP_FILES'] then
@tempdir = File.join(tmpdir, "test_rubygems_#{$$}.#{Time.now.to_i}")
else
@tempdir = File.join(tmpdir, "test_rubygems_#{$$}")
end
@tempdir.untaint
FileUtils.mkdir_p @tempdir
Dir.chdir @tempdir do
@tempdir = File.expand_path '.'
@tempdir.untaint
end
@gemhome = File.join @tempdir, 'gemhome'
@userhome = File.join @tempdir, 'userhome'
ENV["GEM_SPEC_CACHE"] = File.join @tempdir, 'spec_cache'
@orig_ruby = if ENV['RUBY'] then
ruby = Gem.ruby
Gem.ruby = ENV['RUBY']
ruby
end
@git = ENV['GIT'] || 'git'
Gem.ensure_gem_subdirectories @gemhome
@orig_LOAD_PATH = $LOAD_PATH.dup
$LOAD_PATH.map! { |s| File.expand_path(s).untaint }
Dir.chdir @tempdir
@orig_ENV_HOME = ENV['HOME']
ENV['HOME'] = @userhome
Gem.instance_variable_set :@user_home, nil
Gem.send :remove_instance_variable, :@ruby_version if
Gem.instance_variables.include? :@ruby_version
FileUtils.mkdir_p @gemhome
FileUtils.mkdir_p @userhome
@orig_gem_private_key_passphrase = ENV['GEM_PRIVATE_KEY_PASSPHRASE']
ENV['GEM_PRIVATE_KEY_PASSPHRASE'] = PRIVATE_KEY_PASSPHRASE
@default_dir = File.join @tempdir, 'default'
@default_spec_dir = File.join @default_dir, "specifications", "default"
Gem.instance_variable_set :@default_dir, @default_dir
FileUtils.mkdir_p @default_spec_dir
if @@initial_reset
Gem::Specification.unresolved_deps.clear
else
@@initial_reset = true
Gem::Specification.reset
end
Gem.use_paths(@gemhome)
Gem::Security.reset
Gem.loaded_specs.clear
Gem.clear_default_specs
Gem::Specification.unresolved_deps.clear
Gem.configuration.verbose = true
Gem.configuration.update_sources = true
Gem::RemoteFetcher.fetcher = Gem::FakeFetcher.new
@gem_repo = "http://gems.example.com/"
@uri = URI.parse @gem_repo
Gem.sources.replace [@gem_repo]
Gem.searcher = nil
Gem::SpecFetcher.fetcher = nil
@orig_BASERUBY = RbConfig::CONFIG['BASERUBY']
RbConfig::CONFIG['BASERUBY'] = RbConfig::CONFIG['ruby_install_name']
@orig_arch = RbConfig::CONFIG['arch']
if win_platform?
util_set_arch 'i386-mswin32'
else
util_set_arch 'i686-darwin8.10.1'
end
@marshal_version = "#{Marshal::MAJOR_VERSION}.#{Marshal::MINOR_VERSION}"
end