summaryrefslogtreecommitdiff
path: root/test/rdoc/test_rdoc_ri_paths.rb
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-27 04:28:14 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-27 04:28:14 +0000
commit1c279a7d2753949c725754e1302f791b76358114 (patch)
tree36aa3bdde250e564445eba5f2e25fcb96bcb6cef /test/rdoc/test_rdoc_ri_paths.rb
parentc72f0daa877808e4fa5018b3191ca09d4b97c03d (diff)
* lib/rdoc*: Updated to RDoc 4.0 (pre-release)
* bin/rdoc: ditto * test/rdoc: ditto * NEWS: Updated with RDoc 4.0 information git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37889 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/rdoc/test_rdoc_ri_paths.rb')
-rw-r--r--test/rdoc/test_rdoc_ri_paths.rb150
1 files changed, 131 insertions, 19 deletions
diff --git a/test/rdoc/test_rdoc_ri_paths.rb b/test/rdoc/test_rdoc_ri_paths.rb
index e6f33d7d5e..0ef80345bb 100644
--- a/test/rdoc/test_rdoc_ri_paths.rb
+++ b/test/rdoc/test_rdoc_ri_paths.rb
@@ -1,42 +1,154 @@
-require 'rubygems'
-require 'minitest/autorun'
-require 'tmpdir'
-require 'fileutils'
-require 'rdoc/ri/paths'
+require 'rdoc/test_case'
-class TestRDocRIPaths < MiniTest::Unit::TestCase
+class TestRDocRIPaths < RDoc::TestCase
def setup
- RDoc::RI::Paths.instance_variable_set :@gemdirs, %w[/nonexistent/gemdir]
+ super
+
+ @orig_gem_path = Gem.path
+
+ @tempdir = File.join Dir.tmpdir, "test_rdoc_ri_paths_#{$$}"
+ Gem.use_paths @tempdir
+ Gem.ensure_gem_subdirectories @tempdir
+
+ specs = [
+ @rake_10 = Gem::Specification.new('rake', '10.0.1'),
+ @rdoc_4_0 = Gem::Specification.new('rdoc', '4.0'),
+ @rdoc_3_12 = Gem::Specification.new('rdoc', '3.12'),
+ @nodoc = Gem::Specification.new('nodoc', '1.0'),
+ ]
+
+ specs.each do |spec|
+ spec.loaded_from = File.join @tempdir, spec.spec_file
+
+ open spec.spec_file, 'w' do |file|
+ file.write spec.to_ruby_for_cache
+ end
+
+ FileUtils.mkdir_p File.join(spec.doc_dir, 'ri') unless
+ spec.name == 'nodoc'
+ end
+
+ Gem::Specification.reset
+ Gem::Specification.all = specs
end
def teardown
- RDoc::RI::Paths.instance_variable_set :@gemdirs, nil
+ super
+
+ Gem.use_paths(*@orig_gem_path)
+ Gem::Specification.reset
+ FileUtils.rm_rf @tempdir
+ end
+
+ def test_class_each
+ enum = RDoc::RI::Paths.each true, true, true, :all
+
+ path = enum.map { |dir,| dir }
+
+ assert_equal RDoc::RI::Paths.system_dir, path.shift
+ assert_equal RDoc::RI::Paths.site_dir, path.shift
+ assert_equal RDoc::RI::Paths.home_dir, path.shift
+ assert_equal File.join(@nodoc.doc_dir, 'ri'), path.shift
+ assert_equal File.join(@rake_10.doc_dir, 'ri'), path.shift
+ assert_equal File.join(@rdoc_4_0.doc_dir, 'ri'), path.shift
+ assert_equal File.join(@rdoc_3_12.doc_dir, 'ri'), path.shift
+ assert_empty path
+ end
+
+ def test_class_gemdirs_latest
+ Dir.chdir @tempdir do
+ gemdirs = RDoc::RI::Paths.gemdirs :latest
+
+ expected = [
+ File.join(@rake_10.doc_dir, 'ri'),
+ File.join(@rdoc_4_0.doc_dir, 'ri'),
+ ]
+
+ assert_equal expected, gemdirs
+ end
+ end
+
+ def test_class_gemdirs_legacy
+ Dir.chdir @tempdir do
+ gemdirs = RDoc::RI::Paths.gemdirs true
+
+ expected = [
+ File.join(@rake_10.doc_dir, 'ri'),
+ File.join(@rdoc_4_0.doc_dir, 'ri'),
+ ]
+
+ assert_equal expected, gemdirs
+ end
+ end
+
+ def test_class_gemdirs_all
+ Dir.chdir @tempdir do
+ gemdirs = RDoc::RI::Paths.gemdirs :all
+
+ expected = [
+ File.join(@nodoc.doc_dir, 'ri'),
+ File.join(@rake_10.doc_dir, 'ri'),
+ File.join(@rdoc_4_0.doc_dir, 'ri'),
+ File.join(@rdoc_3_12.doc_dir, 'ri'),
+ ]
+
+ assert_equal expected, gemdirs
+ end
+ end
+
+ def test_class_gem_dir
+ dir = RDoc::RI::Paths.gem_dir 'rake', '10.0.1'
+
+ expected = File.join @rake_10.doc_dir, 'ri'
+
+ assert_equal expected, dir
+ end
+
+ def test_class_home_dir
+ dir = RDoc::RI::Paths.home_dir
+
+ assert_equal RDoc::RI::Paths::HOMEDIR, dir
end
def test_class_path_nonexistent
- path = RDoc::RI::Paths.path true, true, true, true, '/nonexistent'
+ temp_dir do |dir|
+ nonexistent = File.join dir, 'nonexistent'
+ dir = RDoc::RI::Paths.path true, true, true, true, nonexistent
- refute_includes path, '/nonexistent'
+ refute_includes dir, nonexistent
+ end
end
def test_class_raw_path
path = RDoc::RI::Paths.raw_path true, true, true, true
- assert_equal RDoc::RI::Paths::SYSDIR, path.shift
- assert_equal RDoc::RI::Paths::SITEDIR, path.shift
- assert_equal RDoc::RI::Paths::HOMEDIR, path.shift
- assert_equal '/nonexistent/gemdir', path.shift
+ assert_equal RDoc::RI::Paths.system_dir, path.shift
+ assert_equal RDoc::RI::Paths.site_dir, path.shift
+ assert_equal RDoc::RI::Paths.home_dir, path.shift
+ assert_equal File.join(@rake_10.doc_dir, 'ri'), path.shift
end
def test_class_raw_path_extra_dirs
path = RDoc::RI::Paths.raw_path true, true, true, true, '/nonexistent'
- assert_equal '/nonexistent', path.shift
- assert_equal RDoc::RI::Paths::SYSDIR, path.shift
- assert_equal RDoc::RI::Paths::SITEDIR, path.shift
- assert_equal RDoc::RI::Paths::HOMEDIR, path.shift
- assert_equal '/nonexistent/gemdir', path.shift
+ assert_equal '/nonexistent', path.shift
+ assert_equal RDoc::RI::Paths.system_dir, path.shift
+ assert_equal RDoc::RI::Paths.site_dir, path.shift
+ assert_equal RDoc::RI::Paths.home_dir, path.shift
+ assert_equal File.join(@rake_10.doc_dir, 'ri'), path.shift
+ end
+
+ def test_class_site_dir
+ dir = RDoc::RI::Paths.site_dir
+
+ assert_equal File.join(RDoc::RI::Paths::BASE, 'site'), dir
+ end
+
+ def test_class_system_dir
+ dir = RDoc::RI::Paths.system_dir
+
+ assert_equal File.join(RDoc::RI::Paths::BASE, 'system'), dir
end
end