1require 'rdoc/test_case' 2 3class TestRDocRIPaths < RDoc::TestCase 4 5 def setup 6 super 7 8 @orig_gem_path = Gem.path 9 10 @tempdir = File.join Dir.tmpdir, "test_rdoc_ri_paths_#{$$}" 11 Gem.use_paths @tempdir 12 Gem.ensure_gem_subdirectories @tempdir 13 14 specs = [ 15 @rake_10 = Gem::Specification.new('rake', '10.0.1'), 16 @rdoc_4_0 = Gem::Specification.new('rdoc', '4.0'), 17 @rdoc_3_12 = Gem::Specification.new('rdoc', '3.12'), 18 @nodoc = Gem::Specification.new('nodoc', '1.0'), 19 ] 20 21 specs.each do |spec| 22 spec.loaded_from = spec.spec_file 23 24 open spec.spec_file, 'w' do |file| 25 file.write spec.to_ruby_for_cache 26 end 27 28 FileUtils.mkdir_p File.join(spec.doc_dir, 'ri') unless 29 spec.name == 'nodoc' 30 end 31 32 Gem::Specification.reset 33 Gem::Specification.all = specs 34 end 35 36 def teardown 37 super 38 39 Gem.use_paths(*@orig_gem_path) 40 Gem::Specification.reset 41 FileUtils.rm_rf @tempdir 42 end 43 44 def test_class_each 45 enum = RDoc::RI::Paths.each true, true, true, :all 46 47 path = enum.map { |dir,| dir } 48 49 assert_equal RDoc::RI::Paths.system_dir, path.shift 50 assert_equal RDoc::RI::Paths.site_dir, path.shift 51 assert_equal RDoc::RI::Paths.home_dir, path.shift 52 assert_equal File.join(@nodoc.doc_dir, 'ri'), path.shift 53 assert_equal File.join(@rake_10.doc_dir, 'ri'), path.shift 54 assert_equal File.join(@rdoc_4_0.doc_dir, 'ri'), path.shift 55 assert_equal File.join(@rdoc_3_12.doc_dir, 'ri'), path.shift 56 assert_empty path 57 end 58 59 def test_class_gemdirs_latest 60 Dir.chdir @tempdir do 61 gemdirs = RDoc::RI::Paths.gemdirs :latest 62 63 expected = [ 64 File.join(@rake_10.doc_dir, 'ri'), 65 File.join(@rdoc_4_0.doc_dir, 'ri'), 66 ] 67 68 assert_equal expected, gemdirs 69 end 70 end 71 72 def test_class_gemdirs_legacy 73 Dir.chdir @tempdir do 74 gemdirs = RDoc::RI::Paths.gemdirs true 75 76 expected = [ 77 File.join(@rake_10.doc_dir, 'ri'), 78 File.join(@rdoc_4_0.doc_dir, 'ri'), 79 ] 80 81 assert_equal expected, gemdirs 82 end 83 end 84 85 def test_class_gemdirs_all 86 Dir.chdir @tempdir do 87 gemdirs = RDoc::RI::Paths.gemdirs :all 88 89 expected = [ 90 File.join(@nodoc.doc_dir, 'ri'), 91 File.join(@rake_10.doc_dir, 'ri'), 92 File.join(@rdoc_4_0.doc_dir, 'ri'), 93 File.join(@rdoc_3_12.doc_dir, 'ri'), 94 ] 95 96 assert_equal expected, gemdirs 97 end 98 end 99 100 def test_class_gem_dir 101 dir = RDoc::RI::Paths.gem_dir 'rake', '10.0.1' 102 103 expected = File.join @rake_10.doc_dir, 'ri' 104 105 assert_equal expected, dir 106 end 107 108 def test_class_home_dir 109 dir = RDoc::RI::Paths.home_dir 110 111 assert_equal RDoc::RI::Paths::HOMEDIR, dir 112 end 113 114 def test_class_path_nonexistent 115 temp_dir do |dir| 116 nonexistent = File.join dir, 'nonexistent' 117 dir = RDoc::RI::Paths.path true, true, true, true, nonexistent 118 119 refute_includes dir, nonexistent 120 end 121 end 122 123 def test_class_raw_path 124 path = RDoc::RI::Paths.raw_path true, true, true, true 125 126 assert_equal RDoc::RI::Paths.system_dir, path.shift 127 assert_equal RDoc::RI::Paths.site_dir, path.shift 128 assert_equal RDoc::RI::Paths.home_dir, path.shift 129 assert_equal File.join(@rake_10.doc_dir, 'ri'), path.shift 130 end 131 132 def test_class_raw_path_extra_dirs 133 path = RDoc::RI::Paths.raw_path true, true, true, true, '/nonexistent' 134 135 assert_equal '/nonexistent', path.shift 136 assert_equal RDoc::RI::Paths.system_dir, path.shift 137 assert_equal RDoc::RI::Paths.site_dir, path.shift 138 assert_equal RDoc::RI::Paths.home_dir, path.shift 139 assert_equal File.join(@rake_10.doc_dir, 'ri'), path.shift 140 end 141 142 def test_class_site_dir 143 dir = RDoc::RI::Paths.site_dir 144 145 assert_equal File.join(RDoc::RI::Paths::BASE, 'site'), dir 146 end 147 148 def test_class_system_dir 149 dir = RDoc::RI::Paths.system_dir 150 151 assert_equal File.join(RDoc::RI::Paths::BASE, 'system'), dir 152 end 153 154end 155 156