1require 'rdoc/test_case'
2
3class TestRDocGeneratorRI < RDoc::TestCase
4
5  def setup
6    super
7
8    @options = RDoc::Options.new
9    if Object.const_defined? :Encoding then
10      @options.encoding = Encoding::UTF_8
11      @store.encoding = Encoding::UTF_8
12    end
13
14    @tmpdir = File.join Dir.tmpdir, "test_rdoc_generator_ri_#{$$}"
15    FileUtils.mkdir_p @tmpdir
16
17    @g = RDoc::Generator::RI.new @store, @options
18
19    @top_level = @store.add_file 'file.rb'
20    @klass = @top_level.add_class RDoc::NormalClass, 'Object'
21
22    @meth = RDoc::AnyMethod.new nil, 'method'
23    @meth.record_location @top_level
24
25    @meth_bang = RDoc::AnyMethod.new nil, 'method!'
26    @meth_bang.record_location @top_level
27
28    @attr = RDoc::Attr.new nil, 'attr', 'RW', ''
29    @attr.record_location @top_level
30
31    @klass.add_method @meth
32    @klass.add_method @meth_bang
33    @klass.add_attribute @attr
34
35    Dir.chdir @tmpdir
36  end
37
38  def teardown
39    super
40
41    Dir.chdir @pwd
42    FileUtils.rm_rf @tmpdir
43  end
44
45  def assert_file path
46    assert File.file?(path), "#{path} is not a file"
47  end
48
49  def refute_file path
50    refute File.exist?(path), "#{path} exists"
51  end
52
53  def test_generate
54    @g.generate
55
56    assert_file File.join(@tmpdir, 'cache.ri')
57
58    assert_file File.join(@tmpdir, 'Object', 'cdesc-Object.ri')
59
60    assert_file File.join(@tmpdir, 'Object', 'attr-i.ri')
61    assert_file File.join(@tmpdir, 'Object', 'method-i.ri')
62    assert_file File.join(@tmpdir, 'Object', 'method%21-i.ri')
63
64    store = RDoc::RI::Store.new @tmpdir
65    store.load_cache
66
67    encoding = Object.const_defined?(:Encoding) ? Encoding::UTF_8 : nil
68
69    assert_equal encoding, store.encoding
70  end
71
72  def test_generate_dry_run
73    @store.dry_run = true
74    @g = RDoc::Generator::RI.new @store, @options
75
76    top_level = @store.add_file 'file.rb'
77    top_level.add_class @klass.class, @klass.name
78
79    @g.generate
80
81    refute_file File.join(@tmpdir, 'cache.ri')
82    refute_file File.join(@tmpdir, 'Object')
83  end
84
85end
86
87