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, SPECIFICATIONS, TEST_PATH

Class Attribute Summary

TestCase - Inherited

.java_platform?

Is this test being run on a Java platform?

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

#java_platform?

Is this test being run on a Java platform?

#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_directory_exists,
#assert_path_exists

TODO: move to minitest.

#bindir

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

#build_rake_in

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

#common_installer_setup, #common_installer_teardown,
#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.

#exeext

Sets the EXEEXT 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.

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

#vendordir

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

#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).

#with_clean_path_to_ruby,
#write_file

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

#in_path?

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

[ GitHub ]

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

def setup
  super

  Gem::Installer.path_warning = false
end

#setup_base_gem

Creates the following instance variables:

@spec

a spec named ‘a’, intended for regular installs

And returns a gem built for the @spec

[ GitHub ]

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

def setup_base_gem
  @spec = setup_base_spec
  util_build_gem @spec
  @spec.cache_file
end

#setup_base_installer

Creates the following instance variables:

@spec

a spec named ‘a’, intended for regular installs

@gem

the path to a built gem from @spec

And returns a Installer for the @spec that installs into @gemhome

[ GitHub ]

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

def setup_base_installer
  @gem = setup_base_gem
  util_installer @spec, @gemhome
end

#setup_base_spec

Sets up a generic specification for testing the rubygems installer

And returns it

[ GitHub ]

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

def setup_base_spec
  quick_gem 'a' do |spec|
    util_make_exec spec
  end
end

#setup_base_user_installer

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_gem

the path to a built gem from @user_spec

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

[ GitHub ]

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

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

  util_build_gem @user_spec

  @user_gem = @user_spec.cache_file

  util_installer @user_spec, Gem.user_dir, :user
end

#util_inst_bindir

The path where installed executables live

[ GitHub ]

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

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 227

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", bindir = "bin")

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 88

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

  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 188

def util_setup_gem(ui = @ui)
  @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

  Gem::Installer.at @gem
end

#util_setup_installer

Sets up the base @gem, builds it and returns an installer for it.

[ GitHub ]

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

def util_setup_installer
  @gem = setup_base_gem

  util_setup_gem
end