|  | 
| 1 | 1 | # frozen_string_literal: true | 
| 2 |  | -require 'rubygems/test_case' | 
|  | 2 | +require "rubygems" | 
|  | 3 | +require "fileutils" | 
|  | 4 | +require "tmpdir" | 
| 3 | 5 | require 'rdoc/rubygems_hook' | 
|  | 6 | +require "test/unit" | 
| 4 | 7 | 
 | 
| 5 |  | -class TestRDocRubygemsHook < Gem::TestCase | 
| 6 |  | -  unless method_defined?(:assert_path_exist) | 
| 7 |  | -    alias assert_path_exist assert_path_exists | 
| 8 |  | -  end | 
| 9 |  | -  unless method_defined?(:assert_path_not_exist) | 
| 10 |  | -    alias assert_path_not_exist refute_path_exists | 
| 11 |  | -  end | 
| 12 |  | -  unless method_defined?(:assert_raise) | 
| 13 |  | -    alias assert_raise assert_raises | 
| 14 |  | -  end | 
| 15 |  | - | 
|  | 8 | +class TestRDocRubygemsHook < Test::Unit::TestCase | 
| 16 | 9 |   def setup | 
| 17 |  | -    super | 
|  | 10 | +    FileUtils.mkdir_p File.expand_path("tmp") | 
| 18 | 11 | 
 | 
| 19 |  | -    @a = util_spec 'a', 2 do |s| | 
|  | 12 | +    @a = Gem::Specification.new do |s| | 
|  | 13 | +      s.platform    = Gem::Platform::RUBY | 
|  | 14 | +      s.name        = "a" | 
|  | 15 | +      s.version     = 2 | 
| 20 | 16 |       s.rdoc_options = %w[--main MyTitle] | 
| 21 | 17 |       s.extra_rdoc_files = %w[README] | 
| 22 | 18 |     end | 
|  | 19 | +    @tempdir = Dir.mktmpdir("test_rubygems_", File.expand_path("tmp")) | 
| 23 | 20 | 
 | 
| 24 |  | -    write_file File.join(@tempdir, 'lib', 'a.rb') | 
| 25 |  | -    write_file File.join(@tempdir, 'README') | 
|  | 21 | +    @a.instance_variable_set(:@doc_dir, File.join(@tempdir, "doc")) | 
|  | 22 | +    @a.instance_variable_set(:@gem_dir, File.join(@tempdir, "a-2")) | 
|  | 23 | +    @a.instance_variable_set(:@full_gem_path, File.join(@tempdir, "a-2")) | 
|  | 24 | +    @a.loaded_from = File.join(@tempdir, 'a-2', 'a-2.gemspec') | 
| 26 | 25 | 
 | 
| 27 |  | -    install_gem @a | 
|  | 26 | +    FileUtils.mkdir_p File.join(@tempdir, 'a-2', 'lib') | 
|  | 27 | +    FileUtils.touch   File.join(@tempdir, 'a-2', 'lib', 'a.rb') | 
|  | 28 | +    FileUtils.touch   File.join(@tempdir, 'a-2', 'README') | 
| 28 | 29 | 
 | 
| 29 | 30 |     @hook = RDoc::RubygemsHook.new @a | 
| 30 | 31 | 
 | 
| 31 | 32 |     begin | 
| 32 | 33 |       RDoc::RubygemsHook.load_rdoc | 
| 33 | 34 |     rescue Gem::DocumentError => e | 
| 34 |  | -      skip e.message | 
|  | 35 | +      pend e.message | 
| 35 | 36 |     end | 
|  | 37 | +    @old_ui = Gem::DefaultUserInteraction.ui | 
|  | 38 | +    Gem::DefaultUserInteraction.ui = Gem::SilentUI.new | 
|  | 39 | +  end | 
| 36 | 40 | 
 | 
| 37 |  | -    Gem.configuration[:rdoc] = nil | 
|  | 41 | +  def teardown | 
|  | 42 | +    Gem::DefaultUserInteraction.ui = @old_ui | 
|  | 43 | +    FileUtils.rm_rf File.expand_path("tmp") | 
| 38 | 44 |   end | 
| 39 | 45 | 
 | 
| 40 | 46 |   def test_initialize | 
| @@ -214,8 +220,8 @@ def test_remove | 
| 214 | 220 |   end | 
| 215 | 221 | 
 | 
| 216 | 222 |   def test_remove_unwritable | 
| 217 |  | -    skip 'chmod not supported' if Gem.win_platform? | 
| 218 |  | -    skip "assumes that euid is not root" if Process.euid == 0 | 
|  | 223 | +    pend 'chmod not supported' if Gem.win_platform? | 
|  | 224 | +    pend "assumes that euid is not root" if Process.euid == 0 | 
| 219 | 225 | 
 | 
| 220 | 226 |     FileUtils.mkdir_p @a.base_dir | 
| 221 | 227 |     FileUtils.chmod 0, @a.base_dir | 
| @@ -244,8 +250,8 @@ def test_setup | 
| 244 | 250 |   end | 
| 245 | 251 | 
 | 
| 246 | 252 |   def test_setup_unwritable | 
| 247 |  | -    skip 'chmod not supported' if Gem.win_platform? | 
| 248 |  | -    skip "assumes that euid is not root" if Process.euid == 0 | 
|  | 253 | +    pend 'chmod not supported' if Gem.win_platform? | 
|  | 254 | +    pend "assumes that euid is not root" if Process.euid == 0 | 
| 249 | 255 | 
 | 
| 250 | 256 |     FileUtils.mkdir_p @a.doc_dir | 
| 251 | 257 |     FileUtils.chmod 0, @a.doc_dir | 
|  | 
0 commit comments