method
setup
v2_6_3 -
Show latest stable
- Class:
Gem::TestCase
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}.
# File lib/rubygems/test_case.rb, line 241
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_bundle_gemfile = ENV['BUNDLE_GEMFILE']
@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
ENV['SOURCE_DATE_EPOCH'] = nil
@current_dir = Dir.pwd
@fetcher = nil
if Gem::USE_BUNDLER_FOR_GEMDEPS
Bundler.ui = Bundler::UI::Silent.new
end
@back_ui = Gem::DefaultUserInteraction.ui
@ui = Gem::MockGemUi.new
# This needs to be a new instance since we call use_ui(@ui) when we want to
# capture output
Gem::DefaultUserInteraction.ui = Gem::MockGemUi.new
tmpdir = File.expand_path Dir.tmpdir
tmpdir.untaint
if ENV['KEEP_FILES']
@tempdir = File.join(tmpdir, "test_rubygems_#{$$}.#{Time.now.to_i}")
else
@tempdir = File.join(tmpdir, "test_rubygems_#{$$}")
end
@tempdir.untaint
FileUtils.mkdir_p @tempdir
# This makes the tempdir consistent on OS X.
# File.expand_path Dir.tmpdir #=> "/var/..."
# Dir.chdir Dir.tmpdir do File.expand_path '.' end #=> "/private/var/..."
# TODO use File#realpath above instead of #expand_path once 1.8 support is
# dropped.
Dir.chdir @tempdir do
@tempdir = File.expand_path '.'
@tempdir.untaint
end
# This makes the tempdir consistent on Windows.
# Dir.tmpdir may return short path name, but Dir[Dir.tmpdir] returns long
# path name. https://bugs.ruby-lang.org/issues/10819
# File.expand_path or File.realpath doesn't convert path name to long path
# name. Only Dir[] (= Dir.glob) works.
# Short and long path name is specific to Windows filesystem.
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']
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)
if expand_path != s
expand_path.untaint
if s.instance_variable_defined?(:@gem_prelude_index)
expand_path.instance_variable_set(:@gem_prelude_index, expand_path)
end
expand_path.freeze if s.frozen?
s = expand_path
end
s
}
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
# We use Gem::Specification.reset the first time only so that if there
# are unresolved deps that leak into the whole test suite, they're at least
# reported once.
if @@initial_reset
Gem::Specification.unresolved_deps.clear # done to avoid cross-test warnings
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
if Gem::USE_BUNDLER_FOR_GEMDEPS
Bundler.reset!
end
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
@orig_hooks = {}
]post_install_hooks done_installing_hooks post_uninstall_hooks pre_uninstall_hooks pre_install_hooks pre_reset_hooks post_reset_hooks post_build_hooks].each do |name|
@orig_hooks[name] = Gem.send(name).dup
end
@marshal_version = "#{Marshal::MAJOR_VERSION}.#{Marshal::MINOR_VERSION}"
@orig_LOADED_FEATURES = $LOADED_FEATURES.dup
end Related methods
- Instance methods
- add_to_fetcher
- all_spec_names
- ask_if_ok
- assert_activate
- assert_contains_make_command
- assert_path_exists
- build_rake_in
- common_installer_setup
- common_installer_teardown
- create_tmpdir
- dep
- dependency_request
- enable_shared
- git_gem
- have_git?
- in_path?
- install_default_gems
- install_default_specs
- install_gem
- install_gem_user
- install_specs
- loaded_spec_names
- make_command
- mu_pp
- new_default_spec
- new_spec
- nmake_found?
- parse_make_command_line
- process_based_port
- quick_gem
- quick_spec
- read_binary
- read_cache
- refute_path_exists
- req
- save_gemspec
- save_loaded_features
- scan_make_command_lines
- setup
- spec
- spec_fetcher
- teardown
- uninstall_gem
- unresolved_names
- util_build_gem
- util_clear_RUBY_VERSION
- util_clear_gems
- util_gem
- util_gzip
- util_make_gems
- util_remove_gem
- util_restore_RUBY_VERSION
- util_set_RUBY_VERSION
- util_set_arch
- util_setup_fake_fetcher
- util_setup_spec_fetcher
- util_spec
- util_zip
- v
- vc_windows?
- vendor_gem
- wait_for_child_process_to_exit
- win_platform?
- write_file
- Class methods
- cert_path
- key_path
- load_cert
- load_key
- make_command
- process_based_port
- rubybin
- vc_windows?
- win_platform?
- Private methods
-
escape_path