123456789_123456789_123456789_123456789_123456789_

Class: Gem::InstallerTestCase

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, TestCase, MiniTest::Unit::TestCase
Instance Chain:
self, TestCase, DefaultUserInteraction, MiniTest::Unit::TestCase
Inherits: Gem::TestCase
  • Object
Defined in: lib/rubygems/installer_test_case.rb

Overview

A test case for Installer.

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.

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?

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 direcotry 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_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.

DefaultUserInteraction - Included

Instance Method Details

#setup

@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 122

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 187

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 132

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 155

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

    use_ui ui do
      FileUtils.rm_f @gem

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

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