Skip to content

Commit 59e4cc0

Browse files
authored
Merge pull request #815 from ruby/fix-rubygems-hook-testcase
Rwrite test-case for rubygems_hook without Gem::TestCase
2 parents ebe185c + 8460a36 commit 59e4cc0

File tree

2 files changed

+32
-24
lines changed

2 files changed

+32
-24
lines changed

lib/rdoc/rubygems_hook.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ def document generator, options, destination
120120
options.exclude ||= [] # TODO maybe move to RDoc::Options#finish
121121
options.setup_generator generator
122122
options.op_dir = destination
123-
options.finish
123+
Dir.chdir @spec.full_gem_path do
124+
options.finish
125+
end
124126

125127
generator = options.generator.new @rdoc.store, options
126128

test/rdoc/test_rdoc_rubygems_hook.rb

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,46 @@
11
# frozen_string_literal: true
2-
require 'rubygems/test_case'
2+
require "rubygems"
3+
require "fileutils"
4+
require "tmpdir"
35
require 'rdoc/rubygems_hook'
6+
require "test/unit"
47

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
169
def setup
17-
super
10+
FileUtils.mkdir_p File.expand_path("tmp")
1811

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
2016
s.rdoc_options = %w[--main MyTitle]
2117
s.extra_rdoc_files = %w[README]
2218
end
19+
@tempdir = Dir.mktmpdir("test_rubygems_", File.expand_path("tmp"))
2320

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')
2625

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')
2829

2930
@hook = RDoc::RubygemsHook.new @a
3031

3132
begin
3233
RDoc::RubygemsHook.load_rdoc
3334
rescue Gem::DocumentError => e
34-
skip e.message
35+
pend e.message
3536
end
37+
@old_ui = Gem::DefaultUserInteraction.ui
38+
Gem::DefaultUserInteraction.ui = Gem::SilentUI.new
39+
end
3640

37-
Gem.configuration[:rdoc] = nil
41+
def teardown
42+
Gem::DefaultUserInteraction.ui = @old_ui
43+
FileUtils.rm_rf File.expand_path("tmp")
3844
end
3945

4046
def test_initialize
@@ -214,8 +220,8 @@ def test_remove
214220
end
215221

216222
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
219225

220226
FileUtils.mkdir_p @a.base_dir
221227
FileUtils.chmod 0, @a.base_dir
@@ -244,8 +250,8 @@ def test_setup
244250
end
245251

246252
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
249255

250256
FileUtils.mkdir_p @a.doc_dir
251257
FileUtils.chmod 0, @a.doc_dir

0 commit comments

Comments
 (0)