1- $LOAD_PATH. unshift File . dirname ( __FILE__ ) + '/../lib/'
21require 'fileutils'
2+ require 'tempfile'
33require 'test/unit'
4+ require 'tmpdir'
5+
46require 'rdoc/generator/texinfo'
5- require 'yaml'
67
78# give us access to check this stuff before it's rendered
89class RDoc ::Generator ::Texinfo ; attr_reader :files , :classes ; end
910class RDoc ::RDoc ; attr_reader :options ; attr_reader :gen ; end
1011
1112class TestRdocInfoSections < Test ::Unit ::TestCase
12- OUTPUT_DIR = "/tmp/rdoc-#{ $$} "
1313
1414 def setup
15- # supress stdout
16- $stdout = File . new ( '/dev/null' , 'w' )
17- $stderr = File . new ( '/dev/null' , 'w' )
15+ @output_dir = File . join Dir . tmpdir , "test_rdoc_info_sections_#{ $$} "
16+ @output_file = File . join @output_dir , 'rdoc.texinfo'
17+
18+ @input_file = Tempfile . new 'my_file.rb'
19+
20+ open @input_file . path , 'w' do |io |
21+ io . write TEST_DOC
22+ end
23+
24+ RDoc ::Parser . alias_extension '.rb' , File . extname ( @input_file . path )
1825
1926 @rdoc = RDoc ::RDoc . new
20- @rdoc . document ( [ '--fmt=texinfo' ,
21- File . expand_path ( File . dirname ( __FILE__ ) + '/../lib/rdoc/generator/texinfo.rb' ) ,
22- File . expand_path ( File . dirname ( __FILE__ ) + '/../README.txt' ) ,
23- "--op=#{ OUTPUT_DIR } " ] )
24- @text = File . read ( OUTPUT_DIR + '/rdoc.texinfo' )
27+ @rdoc . document ( [ '--fmt=texinfo' , '--quiet' , @input_file . path ,
28+ "--op=#{ @output_dir } " ] )
29+
30+ @text = File . read @output_file
2531 end
2632
2733 def teardown
28- $stdout = STDOUT
29- $stderr = STDERR
30- FileUtils . rm_rf OUTPUT_DIR
34+ @input_file . close
35+ FileUtils . rm_rf @output_dir
3136 end
3237
3338 def test_output_exists
3439 assert ! @text . empty?
3540 end
3641
3742 def test_each_class_has_a_chapter
38- assert_section "Class RDoc::Generator::Texinfo" , '@chapter'
39- assert_section "Class RDoc::Generator::TexinfoTemplate" , '@chapter'
43+ assert_section "Class MyClass" , '@chapter'
4044 end
4145
4246 def test_class_descriptions_are_given
43- assert_match ( /This generates .*Texinfo.* files for viewing with GNU Info or Emacs from .*RDoc.* extracted from Ruby source files / , @text . gsub ( "\n " , ' ' ) )
47+ assert_match ( /Documentation for my class / , @text . gsub ( "\n " , ' ' ) )
4448 end
4549
4650 def test_included_modules_are_given
47- assert_match ( /Includes.* Generator::MarkUp /m , @text )
51+ assert_match ( /Includes.* MyModule /m , @text )
4852 end
4953
5054 def test_class_methods_are_given
51- assert_match ( /new \( options \) / , @text )
55+ assert_match ( /my_class_method \( my_first_argument \) / , @text )
5256 end
5357
5458 def test_classes_instance_methods_are_given
55- assert_section 'Class RDoc::Generator::Texinfo#generate '
56- assert_match ( /generate \( toplevels \) / , @text )
59+ assert_section 'Class MyClass#my_method '
60+ assert_match ( /my_method \( my_first_argument \) / , @text )
5761 end
5862
5963 def test_each_module_has_a_chapter
60- assert_section "RDoc" , '@chapter'
61- assert_section "Generator" , '@chapter'
64+ assert_section 'MyModule' , '@chapter'
6265 end
6366
6467 def test_methods_are_shown_only_once
65- methods = @rdoc . gen . classes . map { |c | c . methods . map { |m | c . name + '#' + m . name } } . flatten
68+ methods = @rdoc . gen . classes . map do |c |
69+ c . methods . map do |m |
70+ c . name + '#' + m . name
71+ end
72+ end . flatten
73+
6674 assert_equal methods , methods . uniq
6775 end
6876
@@ -82,12 +90,47 @@ def test_methods_are_shown_only_once
8290# def test_oh_yeah_dont_forget_files
8391# end
8492
85- private
8693 def assert_section ( name , command = '@section' )
8794 assert_match Regexp . new ( "^#{ command } .*#{ Regexp . escape name } " ) , @text , "Could not find a #{ command } #{ name } "
8895 end
8996
90- # def puts(*args)
91- # @real_stdout.puts(*args)
92- # end
97+ TEST_DOC = <<-DOC
98+ ##
99+ # Documentation for my module
100+
101+ module MyModule
102+
103+ ##
104+ # Documentation for my included method
105+
106+ def my_included_method() end
107+
108+ end
109+
110+ ##
111+ # Documentation for my class
112+
113+ class MyClass
114+
115+ include MyModule
116+
117+ ##
118+ # Documentation for my constant
119+
120+ MY_CONSTANT = 'my value'
121+
122+ ##
123+ # Documentation for my class method
124+
125+ def self.my_class_method(my_first_argument) end
126+
127+ ##
128+ # Documentation for my method
129+
130+ def my_method(my_first_argument) end
131+
132+ end
133+
134+ DOC
135+
93136end
0 commit comments