teardown()
public
#teardown restores the process to
its original state and removes the tempdir unless the KEEP_FILES
environment variable was set.
Show source
def teardown
$LOAD_PATH.replace @orig_LOAD_PATH if @orig_LOAD_PATH
if @orig_LOADED_FEATURES
if @orig_LOAD_PATH
paths = @orig_LOAD_PATH.map {|path| File.join(File.expand_path(path), "/")}
($LOADED_FEATURES - @orig_LOADED_FEATURES).each do |feat|
unless paths.any? {|path| feat.start_with?(path)}
$LOADED_FEATURES.delete(feat)
end
end
else
$LOADED_FEATURES.replace @orig_LOADED_FEATURES
end
end
if @orig_BASERUBY
RbConfig::CONFIG['BASERUBY'] = @orig_BASERUBY
else
RbConfig::CONFIG.delete('BASERUBY')
end
RbConfig::CONFIG['arch'] = @orig_arch
if defined? Gem::RemoteFetcher
Gem::RemoteFetcher.fetcher = nil
end
Dir.chdir @current_dir
FileUtils.rm_rf @tempdir unless ENV['KEEP_FILES']
ENV.clear
@orig_gem_env_requirements.each do |k,v|
ENV[k] = v
end
ENV['GEM_HOME'] = @orig_gem_home
ENV['GEM_PATH'] = @orig_gem_path
ENV['GEM_VENDOR'] = @orig_gem_vendor
ENV['GEM_SPEC_CACHE'] = @orig_gem_spec_cache
ENV['RUBYGEMS_GEMDEPS'] = @orig_rubygems_gemdeps
ENV['BUNDLE_GEMFILE'] = @orig_bundle_gemfile
ENV['RUBYGEMS_HOST'] = @orig_rubygems_host
Gem.ruby = @orig_ruby if @orig_ruby
if @orig_ENV_HOME
ENV['HOME'] = @orig_ENV_HOME
else
ENV.delete 'HOME'
end
Gem.instance_variable_set :@default_dir, nil
ENV['GEM_PRIVATE_KEY_PASSPHRASE'] = @orig_gem_private_key_passphrase
Gem::Specification._clear_load_cache
Gem::Specification.unresolved_deps.clear
Gem::refresh
@orig_hooks.each do |name, hooks|
Gem.send(name).replace hooks
end
@back_ui.close
end