summaryrefslogtreecommitdiff
path: root/jni/ruby/test/rdoc/test_rdoc_ri_paths.rb
blob: e377b0b1d00fb7993791761b56460407ca26edbd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
require 'rdoc/test_case'

class TestRDocRIPaths < RDoc::TestCase

  def setup
    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 = 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
    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
    temp_dir do |dir|
      nonexistent = File.join dir, 'nonexistent'
      dir = RDoc::RI::Paths.path true, true, true, true, 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.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.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