123456789_123456789_123456789_123456789_123456789_

Class: Gem::InstallerTestCase

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: Gem::TestCase
Defined in: lib/rubygems/installer_test_case.rb

Overview

A test case for Installer.

Constant Summary

TestCase - Inherited

PRIVATE_KEY_PASSPHRASE

Class Attribute Summary

TestCase - Inherited

.vc_windows?

Returns whether or not we’re on a version of Ruby built with VC++ (or Borland) versus Cygwin, Mingw, etc.

.win_platform?

Is this test being run on a Windows platform?

Class Method Summary

TestCase - Inherited

.cert_path

Returns the path to the certificate named cert_name from test/rubygems/.

.key_path

Returns the path to the key named key_name from test/rubygems.

.load_cert

Loads certificate named cert_name from test/rubygems/.

.load_key

Loads an RSA private key named key_name with passphrase in test/rubygems/.

.make_command

Returns the make command for the current platform.

.process_based_port

Allows tests to use a random (but controlled) port number instead of a hardcoded one.

.rubybin

Finds the path to the Ruby executable.

.escape_path

Deprecate - Extended

deprecate

Simple deprecation method that deprecates name by wrapping it up in a dummy method.

skip_during

Temporarily turn off warnings.

Instance Attribute Summary

TestCase - Inherited

#have_git?

Skips this test unless you have a git executable.

#nmake_found?

Returns whether or not the nmake command could be found.

#vc_windows?

Returns whether or not we’re on a version of Ruby built with VC++ (or Borland) versus Cygwin, Mingw, etc.

#win_platform?

Is this test being run on a Windows platform?

#fetcher, #gem_repo, #uri

DefaultUserInteraction - Included

Instance Method Summary

TestCase - Inherited

#add_to_fetcher

Add spec to @fetcher serving the data in the file path.

#all_spec_names, #assert_activate, #assert_contains_make_command,
#assert_path_exists

TODO: move to minitest.

#build_rake_in

Allows the proper version of rake to be used for the test.

#common_installer_setup, #common_installer_teardown,
#create_tmpdir

creates a temporary directory with hax TODO: deprecate and remove.

#dep

Construct a new Dependency.

#dependency_request

Constructs a Resolver::DependencyRequest from a Dependency dep, a from_name and from_version requesting the dependency and a parent DependencyRequest.

#enable_shared

Sets the ENABLE_SHARED entry in RbConfig::CONFIG to value and restores the original value when the block ends.

#git_gem

A git_gem is used with a gem dependencies file.

#install_default_gems

Installs the provided default specs including writing the spec file.

#install_default_specs

Install the provided default specs.

#install_gem

Builds and installs the Specification spec

#install_gem_user

Builds and installs the Specification spec into the user dir.

#install_specs

Install the provided specs.

#loaded_spec_names,
#make_command

Returns the make command for the current platform.

#mu_pp

Enables pretty-print for all tests.

#new_default_spec, #parse_make_command_line,
#process_based_port

See .process_based_port

#quick_gem

Creates a Specification with a minimum of extra work.

#read_binary

Reads a binary file at path

#read_cache

Reads a Marshal file at path

#refute_path_exists

TODO: move to minitest.

#req

Constructs a new Requirement.

#save_gemspec

create_gemspec creates gem specification in given directory or ‘.’ for the given name and version.

#save_loaded_features, #scan_make_command_lines,
#setup

#setup prepares a sandboxed location to install gems.

#spec

Constructs a new Specification.

#spec_fetcher

Creates a SpecFetcher pre-filled with the gems or specs defined in the block.

#teardown

#teardown restores the process to its original state and removes the tempdir unless the KEEP_FILES environment variable was set.

#uninstall_gem

Uninstalls the Specification spec

#unresolved_names,
#util_build_gem

Builds a gem from spec and places it in File.join @gemhome, 'cache'.

#util_clear_gems

Removes all installed gems from @gemhome.

#util_clear_RUBY_VERSION,
#util_gem

Creates a gem with name, version and deps.

#util_gzip

Gzips data.

#util_make_gems

Creates several default gems which all have a lib/code.rb file.

#util_remove_gem, #util_restore_RUBY_VERSION,
#util_set_arch

Set the platform to arch

#util_set_RUBY_VERSION,
#util_setup_fake_fetcher

Sets up a fake fetcher using the gems from #util_make_gems.

#util_setup_spec_fetcher

Sets up SpecFetcher to return information from the gems in specs.

#util_spec

Creates a spec with name, version.

#util_zip

Deflates data

#v

Construct a new Version.

#vendor_gem

A vendor_gem is used with a gem dependencies file.

#wait_for_child_process_to_exit

In case we’re building docs in a background process, this method waits for that process to exit (or if it’s already been reaped, or never happened, swallows the Errno::ECHILD error).

#write_file

Writes a binary file to path which is relative to @gemhome.

#in_path?,
#new_spec

new_spec is deprecated as it is never used.

#quick_spec

TODO: remove in RubyGems 4.0.

DefaultUserInteraction - Included

Text - Included

#clean_text

Remove any non-printable characters and make the text suitable for printing.

#format_text

Wraps text to wrap characters and optionally indents by indent characters.

#levenshtein_distance

This code is based directly on the Text gem implementation Returns a value representing the “cost” of transforming str1 into str2.

#truncate_text, #min3

Instance Method Details

#setup

Creates the following instance variables:

@spec

a spec named ‘a’, intended for regular installs

@user_spec

a spec named ‘b’, intended for user installs

@gem

the path to a built gem from @spec

@user_spec

the path to a built gem from @user_spec

@installer

a Gem::Installer for the @spec that installs into @gemhome

@user_installer

a Gem::Installer for the @user_spec that installs into Gem.user_dir

[ GitHub ]

  
# File 'lib/rubygems/installer_test_case.rb', line 86

def setup
  super

  @spec = quick_gem 'a' do |spec|
    util_make_exec spec
  end

  @user_spec = quick_gem 'b' do |spec|
    util_make_exec spec
  end

  util_build_gem @spec
  util_build_gem @user_spec

  @gem = @spec.cache_file
  @user_gem = @user_spec.cache_file

  @installer      = util_installer @spec, @gemhome
  @user_installer = util_installer @user_spec, Gem.user_dir, :user

  Gem::Installer.path_warning = false
end

#util_inst_bindir

The path where installed executables live

[ GitHub ]

  
# File 'lib/rubygems/installer_test_case.rb', line 112

def util_inst_bindir
  File.join @gemhome, "bin"
end

#util_installer(spec, gem_home, user = false)

Creates an installer for spec that will install into gem_home. If user is true a user-install will be performed.

[ GitHub ]

  
# File 'lib/rubygems/installer_test_case.rb', line 179

def util_installer(spec, gem_home, user=false)
  Gem::Installer.at(spec.cache_file,
                     :install_dir => gem_home,
                     :user_install => user)
end

#util_make_exec(spec = @spec, shebang = "#!/usr/bin/ruby")

Adds an executable named “executable” to spec with the given shebang.

The executable is also written to the bin dir in @tmpdir and the installed gem directory for spec.

[ GitHub ]

  
# File 'lib/rubygems/installer_test_case.rb', line 122

def util_make_exec(spec = @spec, shebang = "#!/usr/bin/ruby")
  spec.executables = %w[executable]
  spec.files << 'bin/executable'

  exec_path = spec.bin_file "executable"
  write_file exec_path do |io|
    io.puts shebang
  end

  bin_path = File.join @tempdir, "bin", "executable"
  write_file bin_path do |io|
    io.puts shebang
  end
end

#util_setup_gem(ui = @ui)

Builds the @spec gem and returns an installer for it. The built gem includes:

bin/executable
lib/code.rb
ext/a/mkrf_conf.rb
[ GitHub ]

  
# File 'lib/rubygems/installer_test_case.rb', line 145

def util_setup_gem(ui = @ui) # HACK fix use_ui to make this automatic
  @spec.files << File.join('lib', 'code.rb')
  @spec.extensions << File.join('ext', 'a', 'mkrf_conf.rb')

  Dir.chdir @tempdir do
    FileUtils.mkdir_p 'bin'
    FileUtils.mkdir_p 'lib'
    FileUtils.mkdir_p File.join('ext', 'a')
    File.open File.join('bin', 'executable'), 'w' do |f|
      f.puts "raise 'ran executable'"
    end
    File.open File.join('lib', 'code.rb'), 'w' do |f| f.puts '1' end
    File.open File.join('ext', 'a', 'mkrf_conf.rb'), 'w' do |f|
      f << <<-EOF
        File.open 'Rakefile', 'w' do |rf| rf.puts "task :default" end
      EOF
    end

    yield @spec if block_given?

    use_ui ui do
      FileUtils.rm_f @gem

      @gem = Gem::Package.build @spec
    end
  end

  @installer = Gem::Installer.at @gem
end