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']
    @orig_gem_vendor = ENV['GEM_VENDOR']
    @orig_gem_spec_cache = ENV['GEM_SPEC_CACHE']
    @orig_rubygems_gemdeps = ENV['RUBYGEMS_GEMDEPS']
    @orig_rubygems_host = ENV['RUBYGEMS_HOST']
    ENV.keys.find_all { |k| k.start_with?('GEM_REQUIREMENT_') }.each do |k|
      ENV.delete k
    end
    @orig_gem_env_requirements = ENV.to_hash
    ENV['GEM_VENDOR'] = nil
    @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
    
    
    
    
    
    
    if win_platform?
      @tempdir = Dir[@tempdir][0]
      @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|
      (expand_path = File.expand_path(s)) == s ? s : expand_path.untaint
    }
    Dir.chdir @tempdir
    @orig_ENV_HOME = ENV['HOME']
    ENV['HOME'] = @userhome
    Gem.instance_variable_set :@user_home, nil
    Gem.instance_variable_set :@gemdeps, nil
    Gem.instance_variable_set :@env_requirements_by_name, 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}"
    @orig_LOADED_FEATURES = $LOADED_FEATURES.dup
  end