2011-06-16 00:59:24 -04:00
|
|
|
require 'rubygems'
|
2012-11-26 23:28:14 -05:00
|
|
|
require 'rubygems/test_case'
|
2011-06-16 00:59:24 -04:00
|
|
|
require 'rdoc/rubygems_hook'
|
|
|
|
|
|
|
|
class TestRDocRubygemsHook < Gem::TestCase
|
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
skip 'requires RubyGems 1.9+' unless
|
|
|
|
Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.9')
|
|
|
|
|
2012-12-14 00:16:56 -05:00
|
|
|
@a = quick_spec 'a' do |s|
|
|
|
|
s.rdoc_options = %w[--main MyTitle]
|
|
|
|
s.extra_rdoc_files = %w[README]
|
|
|
|
end
|
|
|
|
|
|
|
|
write_file File.join(@tempdir, 'lib', 'a.rb')
|
|
|
|
write_file File.join(@tempdir, 'README')
|
|
|
|
|
|
|
|
install_gem @a
|
2011-06-16 00:59:24 -04:00
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
@hook = RDoc::RubygemsHook.new @a
|
2011-06-16 00:59:24 -04:00
|
|
|
|
|
|
|
begin
|
|
|
|
RDoc::RubygemsHook.load_rdoc
|
|
|
|
rescue Gem::DocumentError => e
|
|
|
|
skip e.message
|
|
|
|
end
|
|
|
|
|
|
|
|
Gem.configuration[:rdoc] = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_initialize
|
2012-12-14 00:16:56 -05:00
|
|
|
refute @hook.generate_rdoc
|
2012-11-27 01:01:41 -05:00
|
|
|
assert @hook.generate_ri
|
2011-06-16 00:59:24 -04:00
|
|
|
|
|
|
|
rdoc = RDoc::RubygemsHook.new @a, false, false
|
|
|
|
|
|
|
|
refute rdoc.generate_rdoc
|
|
|
|
refute rdoc.generate_ri
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_delete_legacy_args
|
|
|
|
args = %w[
|
|
|
|
--inline-source
|
|
|
|
--one-file
|
|
|
|
--promiscuous
|
|
|
|
-p
|
|
|
|
]
|
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
@hook.delete_legacy_args args
|
2011-06-16 00:59:24 -04:00
|
|
|
|
|
|
|
assert_empty args
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_document
|
|
|
|
options = RDoc::Options.new
|
|
|
|
options.files = []
|
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
rdoc = @hook.new_rdoc
|
|
|
|
rdoc.store = RDoc::Store.new
|
|
|
|
@hook.instance_variable_set :@rdoc, rdoc
|
|
|
|
@hook.instance_variable_set :@file_info, []
|
2011-06-16 00:59:24 -04:00
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
@hook.document 'darkfish', options, @a.doc_dir('rdoc')
|
2011-06-16 00:59:24 -04:00
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
assert @hook.rdoc_installed?
|
2011-06-16 00:59:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_generate
|
|
|
|
FileUtils.mkdir_p @a.doc_dir
|
|
|
|
FileUtils.mkdir_p File.join(@a.gem_dir, 'lib')
|
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
@hook.generate
|
2011-06-16 00:59:24 -04:00
|
|
|
|
2012-12-14 00:16:56 -05:00
|
|
|
refute @hook.rdoc_installed?
|
|
|
|
assert @hook.ri_installed?
|
|
|
|
|
|
|
|
rdoc = @hook.instance_variable_get :@rdoc
|
|
|
|
|
|
|
|
refute rdoc.options.hyperlink_all
|
|
|
|
assert_equal Pathname(@a.full_gem_path), rdoc.options.root
|
|
|
|
assert_equal %w[README lib], rdoc.options.files.sort
|
|
|
|
|
|
|
|
assert_equal 'MyTitle', rdoc.store.main
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_generate_all
|
|
|
|
@hook.generate_rdoc = true
|
|
|
|
@hook.generate_ri = true
|
|
|
|
|
|
|
|
FileUtils.mkdir_p @a.doc_dir
|
|
|
|
FileUtils.mkdir_p File.join(@a.gem_dir, 'lib')
|
|
|
|
|
|
|
|
@hook.generate
|
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
assert @hook.rdoc_installed?
|
|
|
|
assert @hook.ri_installed?
|
2011-06-16 00:59:24 -04:00
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
rdoc = @hook.instance_variable_get :@rdoc
|
2011-06-16 00:59:24 -04:00
|
|
|
|
|
|
|
refute rdoc.options.hyperlink_all
|
2012-12-14 00:16:56 -05:00
|
|
|
assert_equal Pathname(@a.full_gem_path), rdoc.options.root
|
|
|
|
assert_equal %w[README lib], rdoc.options.files.sort
|
|
|
|
|
|
|
|
assert_equal 'MyTitle', rdoc.store.main
|
2011-06-16 00:59:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_generate_configuration_rdoc_array
|
|
|
|
Gem.configuration[:rdoc] = %w[-A]
|
|
|
|
|
|
|
|
FileUtils.mkdir_p @a.doc_dir
|
|
|
|
FileUtils.mkdir_p File.join(@a.gem_dir, 'lib')
|
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
@hook.generate
|
2011-06-16 00:59:24 -04:00
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
rdoc = @hook.instance_variable_get :@rdoc
|
2011-06-16 00:59:24 -04:00
|
|
|
|
|
|
|
assert rdoc.options.hyperlink_all
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_generate_configuration_rdoc_string
|
|
|
|
Gem.configuration[:rdoc] = '-A'
|
|
|
|
|
|
|
|
FileUtils.mkdir_p @a.doc_dir
|
|
|
|
FileUtils.mkdir_p File.join(@a.gem_dir, 'lib')
|
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
@hook.generate
|
2011-06-16 00:59:24 -04:00
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
rdoc = @hook.instance_variable_get :@rdoc
|
2011-06-16 00:59:24 -04:00
|
|
|
|
|
|
|
assert rdoc.options.hyperlink_all
|
|
|
|
end
|
|
|
|
|
2012-11-29 18:34:29 -05:00
|
|
|
def test_generate_default_gem
|
|
|
|
skip 'RubyGems 2 required' unless @a.respond_to? :default_gem?
|
|
|
|
@a.loaded_from =
|
|
|
|
File.join Gem::Specification.default_specifications_dir, 'a.gemspec'
|
|
|
|
|
|
|
|
FileUtils.mkdir_p @a.doc_dir
|
|
|
|
FileUtils.mkdir_p File.join(@a.gem_dir, 'lib')
|
|
|
|
|
|
|
|
@hook.generate
|
|
|
|
|
|
|
|
refute @hook.rdoc_installed?
|
|
|
|
refute @hook.ri_installed?
|
|
|
|
end
|
|
|
|
|
2011-06-16 00:59:24 -04:00
|
|
|
def test_generate_disabled
|
2012-11-27 01:01:41 -05:00
|
|
|
@hook.generate_rdoc = false
|
|
|
|
@hook.generate_ri = false
|
2011-06-16 00:59:24 -04:00
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
@hook.generate
|
2011-06-16 00:59:24 -04:00
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
refute @hook.rdoc_installed?
|
|
|
|
refute @hook.ri_installed?
|
2011-06-16 00:59:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_generate_force
|
|
|
|
FileUtils.mkdir_p @a.doc_dir 'ri'
|
|
|
|
FileUtils.mkdir_p @a.doc_dir 'rdoc'
|
|
|
|
FileUtils.mkdir_p File.join(@a.gem_dir, 'lib')
|
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
@hook.force = true
|
2011-06-16 00:59:24 -04:00
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
@hook.generate
|
2011-06-16 00:59:24 -04:00
|
|
|
|
2012-12-14 00:16:56 -05:00
|
|
|
refute_path_exists File.join(@a.doc_dir('rdoc'), 'index.html')
|
2011-06-16 00:59:24 -04:00
|
|
|
assert_path_exists File.join(@a.doc_dir('ri'), 'cache.ri')
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_generate_no_overwrite
|
|
|
|
FileUtils.mkdir_p @a.doc_dir 'ri'
|
|
|
|
FileUtils.mkdir_p @a.doc_dir 'rdoc'
|
|
|
|
FileUtils.mkdir_p File.join(@a.gem_dir, 'lib')
|
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
@hook.generate
|
2011-06-16 00:59:24 -04:00
|
|
|
|
|
|
|
refute_path_exists File.join(@a.doc_dir('rdoc'), 'index.html')
|
|
|
|
refute_path_exists File.join(@a.doc_dir('ri'), 'cache.ri')
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_new_rdoc
|
2012-11-27 01:01:41 -05:00
|
|
|
assert_kind_of RDoc::RDoc, @hook.new_rdoc
|
2011-06-16 00:59:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_rdoc_installed?
|
2012-11-27 01:01:41 -05:00
|
|
|
refute @hook.rdoc_installed?
|
2011-06-16 00:59:24 -04:00
|
|
|
|
|
|
|
FileUtils.mkdir_p @a.doc_dir 'rdoc'
|
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
assert @hook.rdoc_installed?
|
2011-06-16 00:59:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_remove
|
|
|
|
FileUtils.mkdir_p @a.doc_dir 'rdoc'
|
|
|
|
FileUtils.mkdir_p @a.doc_dir 'ri'
|
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
@hook.remove
|
2011-06-16 00:59:24 -04:00
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
refute @hook.rdoc_installed?
|
|
|
|
refute @hook.ri_installed?
|
2011-06-16 00:59:24 -04:00
|
|
|
|
|
|
|
assert_path_exists @a.doc_dir
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_remove_unwritable
|
|
|
|
skip 'chmod not supported' if Gem.win_platform?
|
|
|
|
FileUtils.mkdir_p @a.base_dir
|
|
|
|
FileUtils.chmod 0, @a.base_dir
|
|
|
|
|
|
|
|
e = assert_raises Gem::FilePermissionError do
|
2012-11-27 01:01:41 -05:00
|
|
|
@hook.remove
|
2011-06-16 00:59:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal @a.base_dir, e.directory
|
|
|
|
ensure
|
2012-12-14 00:16:56 -05:00
|
|
|
FileUtils.chmod(0755, @a.base_dir) if File.directory?(@a.base_dir)
|
2011-06-16 00:59:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_ri_installed?
|
2012-11-27 01:01:41 -05:00
|
|
|
refute @hook.ri_installed?
|
2011-06-16 00:59:24 -04:00
|
|
|
|
|
|
|
FileUtils.mkdir_p @a.doc_dir 'ri'
|
|
|
|
|
2012-11-27 01:01:41 -05:00
|
|
|
assert @hook.ri_installed?
|
2011-06-16 00:59:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_setup
|
2012-11-27 01:01:41 -05:00
|
|
|
@hook.setup
|
2011-06-16 00:59:24 -04:00
|
|
|
|
|
|
|
assert_path_exists @a.doc_dir
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_setup_unwritable
|
|
|
|
skip 'chmod not supported' if Gem.win_platform?
|
2012-12-14 00:16:56 -05:00
|
|
|
FileUtils.mkdir_p @a.doc_dir
|
|
|
|
FileUtils.chmod 0, @a.doc_dir
|
|
|
|
|
|
|
|
e = assert_raises Gem::FilePermissionError do
|
|
|
|
@hook.setup
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal @a.doc_dir, e.directory
|
|
|
|
ensure
|
|
|
|
if File.exist? @a.doc_dir
|
|
|
|
FileUtils.chmod 0755, @a.doc_dir
|
|
|
|
FileUtils.rm_r @a.doc_dir
|
2011-06-16 00:59:24 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
end
|
2011-06-16 00:59:24 -04:00
|
|
|
|