PageRenderTime 198ms CodeModel.GetById 184ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/tools/Ruby/lib/ruby/site_ruby/1.8/rubygems/installer_test_case.rb

http://github.com/agross/netopenspace
Ruby | 144 lines | 82 code | 42 blank | 20 comment | 0 complexity | 559644188dd7313ba9eb25d533a3f198 MD5 | raw file
  1require 'rubygems/test_case'
  2require 'rubygems/installer'
  3
  4class Gem::Installer
  5
  6  ##
  7  # Available through requiring rubygems/installer_test_case
  8
  9  attr_accessor :gem_dir
 10
 11  ##
 12  # Available through requiring rubygems/installer_test_case
 13
 14  attr_writer :format
 15
 16  ##
 17  # Available through requiring rubygems/installer_test_case
 18
 19  attr_writer :gem_home
 20
 21  ##
 22  # Available through requiring rubygems/installer_test_case
 23
 24  attr_writer :env_shebang
 25
 26  ##
 27  # Available through requiring rubygems/installer_test_case
 28
 29  attr_writer :ignore_dependencies
 30
 31  ##
 32  # Available through requiring rubygems/installer_test_case
 33
 34  attr_writer :format_executable
 35
 36  ##
 37  # Available through requiring rubygems/installer_test_case
 38
 39  attr_writer :security_policy
 40
 41  ##
 42  # Available through requiring rubygems/installer_test_case
 43
 44  attr_writer :spec
 45
 46  ##
 47  # Available through requiring rubygems/installer_test_case
 48
 49  attr_writer :wrappers
 50end
 51
 52##
 53# A test case for Gem::Installer.
 54
 55class Gem::InstallerTestCase < Gem::TestCase
 56
 57  def setup
 58    super
 59
 60    @spec = quick_gem 'a'
 61    util_make_exec @spec
 62
 63    @gem = File.join @tempdir, @spec.file_name
 64
 65    @installer = util_installer @spec, @gem, @gemhome
 66
 67    @user_spec = quick_gem 'b'
 68    util_make_exec @user_spec
 69
 70    @user_gem = File.join @tempdir, @user_spec.file_name
 71
 72    @user_installer = util_installer @user_spec, @user_gem, Gem.user_dir
 73    @user_installer.gem_dir = File.join(Gem.user_dir, 'gems',
 74                                        @user_spec.full_name)
 75  end
 76
 77  def util_gem_bindir spec = @spec
 78    File.join util_gem_dir(spec), "bin"
 79  end
 80
 81  def util_gem_dir spec = @spec
 82    File.join @gemhome, "gems", spec.full_name
 83  end
 84
 85  def util_inst_bindir
 86    File.join @gemhome, "bin"
 87  end
 88
 89  def util_make_exec(spec = @spec, shebang = "#!/usr/bin/ruby")
 90    spec.executables = %w[executable]
 91    spec.files << 'bin/executable'
 92
 93    bindir = util_gem_bindir spec
 94    FileUtils.mkdir_p bindir
 95    exec_path = File.join bindir, 'executable'
 96    open exec_path, 'w' do |io|
 97      io.puts shebang
 98    end
 99
100    temp_bin = File.join(@tempdir, 'bin')
101    FileUtils.mkdir_p temp_bin
102    open File.join(temp_bin, 'executable'), 'w' do |io|
103      io.puts shebang
104    end
105  end
106
107  def util_setup_gem(ui = @ui) # HACK fix use_ui to make this automatic
108    @spec.files << File.join('lib', 'code.rb')
109    @spec.extensions << File.join('ext', 'a', 'mkrf_conf.rb')
110
111    Dir.chdir @tempdir do
112      FileUtils.mkdir_p 'bin'
113      FileUtils.mkdir_p 'lib'
114      FileUtils.mkdir_p File.join('ext', 'a')
115      File.open File.join('bin', 'executable'), 'w' do |f| f.puts '1' end
116      File.open File.join('lib', 'code.rb'), 'w' do |f| f.puts '1' end
117      File.open File.join('ext', 'a', 'mkrf_conf.rb'), 'w' do |f|
118        f << <<-EOF
119          File.open 'Rakefile', 'w' do |rf| rf.puts "task :default" end
120        EOF
121      end
122
123      use_ui ui do
124        FileUtils.rm @gem
125        Gem::Builder.new(@spec).build
126      end
127    end
128
129    @installer = Gem::Installer.new @gem
130  end
131
132  def util_installer(spec, gem_path, gem_home)
133    util_build_gem spec
134    FileUtils.mv Gem.cache_gem(spec.file_name), @tempdir
135    installer = Gem::Installer.new gem_path
136    installer.gem_dir = util_gem_dir
137    installer.gem_home = gem_home
138    installer.spec = spec
139
140    installer
141  end
142
143end
144