/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

  1. require 'rubygems/test_case'
  2. require 'rubygems/installer'
  3. class Gem::Installer
  4. ##
  5. # Available through requiring rubygems/installer_test_case
  6. attr_accessor :gem_dir
  7. ##
  8. # Available through requiring rubygems/installer_test_case
  9. attr_writer :format
  10. ##
  11. # Available through requiring rubygems/installer_test_case
  12. attr_writer :gem_home
  13. ##
  14. # Available through requiring rubygems/installer_test_case
  15. attr_writer :env_shebang
  16. ##
  17. # Available through requiring rubygems/installer_test_case
  18. attr_writer :ignore_dependencies
  19. ##
  20. # Available through requiring rubygems/installer_test_case
  21. attr_writer :format_executable
  22. ##
  23. # Available through requiring rubygems/installer_test_case
  24. attr_writer :security_policy
  25. ##
  26. # Available through requiring rubygems/installer_test_case
  27. attr_writer :spec
  28. ##
  29. # Available through requiring rubygems/installer_test_case
  30. attr_writer :wrappers
  31. end
  32. ##
  33. # A test case for Gem::Installer.
  34. class Gem::InstallerTestCase < Gem::TestCase
  35. def setup
  36. super
  37. @spec = quick_gem 'a'
  38. util_make_exec @spec
  39. @gem = File.join @tempdir, @spec.file_name
  40. @installer = util_installer @spec, @gem, @gemhome
  41. @user_spec = quick_gem 'b'
  42. util_make_exec @user_spec
  43. @user_gem = File.join @tempdir, @user_spec.file_name
  44. @user_installer = util_installer @user_spec, @user_gem, Gem.user_dir
  45. @user_installer.gem_dir = File.join(Gem.user_dir, 'gems',
  46. @user_spec.full_name)
  47. end
  48. def util_gem_bindir spec = @spec
  49. File.join util_gem_dir(spec), "bin"
  50. end
  51. def util_gem_dir spec = @spec
  52. File.join @gemhome, "gems", spec.full_name
  53. end
  54. def util_inst_bindir
  55. File.join @gemhome, "bin"
  56. end
  57. def util_make_exec(spec = @spec, shebang = "#!/usr/bin/ruby")
  58. spec.executables = %w[executable]
  59. spec.files << 'bin/executable'
  60. bindir = util_gem_bindir spec
  61. FileUtils.mkdir_p bindir
  62. exec_path = File.join bindir, 'executable'
  63. open exec_path, 'w' do |io|
  64. io.puts shebang
  65. end
  66. temp_bin = File.join(@tempdir, 'bin')
  67. FileUtils.mkdir_p temp_bin
  68. open File.join(temp_bin, 'executable'), 'w' do |io|
  69. io.puts shebang
  70. end
  71. end
  72. def util_setup_gem(ui = @ui) # HACK fix use_ui to make this automatic
  73. @spec.files << File.join('lib', 'code.rb')
  74. @spec.extensions << File.join('ext', 'a', 'mkrf_conf.rb')
  75. Dir.chdir @tempdir do
  76. FileUtils.mkdir_p 'bin'
  77. FileUtils.mkdir_p 'lib'
  78. FileUtils.mkdir_p File.join('ext', 'a')
  79. File.open File.join('bin', 'executable'), 'w' do |f| f.puts '1' end
  80. File.open File.join('lib', 'code.rb'), 'w' do |f| f.puts '1' end
  81. File.open File.join('ext', 'a', 'mkrf_conf.rb'), 'w' do |f|
  82. f << <<-EOF
  83. File.open 'Rakefile', 'w' do |rf| rf.puts "task :default" end
  84. EOF
  85. end
  86. use_ui ui do
  87. FileUtils.rm @gem
  88. Gem::Builder.new(@spec).build
  89. end
  90. end
  91. @installer = Gem::Installer.new @gem
  92. end
  93. def util_installer(spec, gem_path, gem_home)
  94. util_build_gem spec
  95. FileUtils.mv Gem.cache_gem(spec.file_name), @tempdir
  96. installer = Gem::Installer.new gem_path
  97. installer.gem_dir = util_gem_dir
  98. installer.gem_home = gem_home
  99. installer.spec = spec
  100. installer
  101. end
  102. end