3
3
4
4
require_relative 'helper'
5
5
6
- class TestRDocParser < RDoc ::TestCase
7
-
6
+ class RDocParserTest < RDoc ::TestCase
8
7
def setup
9
8
super
10
9
11
10
@RP = RDoc ::Parser
12
- @binary_dat = File . expand_path '../binary.dat' , __FILE__
13
-
14
- @fn = 'file.rb'
15
- @top_level = RDoc ::TopLevel . new @fn
11
+ @binary_dat_fixture_path = File . expand_path '../binary.dat' , __FILE__
16
12
@options = RDoc ::Options . new
17
13
end
18
14
@@ -71,7 +67,7 @@ def test_class_can_parse
71
67
72
68
assert_equal @RP ::Simple , @RP . can_parse ( readme_file_name )
73
69
74
- assert_equal @RP ::Simple , @RP . can_parse ( @binary_dat )
70
+ assert_equal @RP ::Simple , @RP . can_parse ( @binary_dat_fixture_path )
75
71
76
72
jtest_file_name = File . expand_path '../test.ja.txt' , __FILE__
77
73
assert_equal @RP ::Simple , @RP . can_parse ( jtest_file_name )
@@ -90,16 +86,12 @@ def test_class_can_parse
90
86
end
91
87
92
88
def test_class_for_executable
93
- temp_dir do
94
- content = "#!/usr/bin/env ruby -w\n "
95
- File . open 'app' , 'w' do |io | io . write content end
96
- app = @store . add_file 'app'
97
-
98
- parser = @RP . for app , 'app' , content , @options , :stats
89
+ with_top_level ( "app" , "#!/usr/bin/env ruby -w\n " ) do |top_level , content |
90
+ parser = @RP . for top_level , content , @options , :stats
99
91
100
92
assert_kind_of RDoc ::Parser ::Ruby , parser
101
93
102
- assert_equal 'app' , parser . file_name
94
+ assert_equal top_level . absolute_name , parser . file_name
103
95
end
104
96
end
105
97
@@ -111,7 +103,7 @@ def test_class_for_forbidden
111
103
File . chmod 0000 , io . path
112
104
forbidden = @store . add_file io . path
113
105
114
- parser = @RP . for forbidden , 'forbidden' , ' ', @options , :stats
106
+ parser = @RP . for forbidden , '' , @options , :stats
115
107
116
108
assert_nil parser
117
109
ensure
@@ -123,13 +115,8 @@ def test_class_for_forbidden
123
115
end
124
116
125
117
def test_class_for_modeline
126
- temp_dir do
127
- content = "# -*- rdoc -*-\n = NEWS\n "
128
-
129
- File . open 'NEWS' , 'w' do |io | io . write content end
130
- app = @store . add_file 'NEWS'
131
-
132
- parser = @RP . for app , 'NEWS' , content , @options , :stats
118
+ with_top_level ( "NEWS" , "# -*- rdoc -*-\n = NEWS\n " ) do |top_level , content |
119
+ parser = @RP . for top_level , content , @options , :stats
133
120
134
121
assert_kind_of RDoc ::Parser ::Simple , parser
135
122
@@ -226,25 +213,18 @@ def test_check_modeline_no_modeline
226
213
end
227
214
228
215
def test_class_for_binary
229
- rp = @RP . dup
230
-
231
- class << rp
232
- alias old_can_parse can_parse
216
+ dat_fixture = File . read ( @binary_dat_fixture_path )
217
+ with_top_level ( "binary.dat" , dat_fixture ) do |top_level , content |
218
+ assert_nil @RP . for ( top_level , content , @options , nil )
233
219
end
234
-
235
- def rp . can_parse ( *args ) nil end
236
-
237
- assert_nil @RP . for ( nil , @binary_dat , nil , nil , nil )
238
220
end
239
221
240
222
def test_class_for_markup
241
- content = <<-CONTENT
242
- # coding: utf-8 markup: rd
243
- CONTENT
223
+ with_top_level ( "file.rb" , "# coding: utf-8 markup: rd" ) do |top_level , content |
224
+ parser = @RP . for top_level , content , @options , nil
244
225
245
- parser = @RP . for @top_level , __FILE__ , content , @options , nil
246
-
247
- assert_kind_of @RP ::RD , parser
226
+ assert_kind_of @RP ::RD , parser
227
+ end
248
228
end
249
229
250
230
def test_class_use_markup
@@ -329,9 +309,26 @@ def test_class_use_markup_unknown
329
309
end
330
310
331
311
def test_initialize
332
- @RP . new @top_level , @fn , '' , @options , nil
312
+ with_top_level ( "file.rb" , "" ) do |top_level , content |
313
+ @RP . new top_level , top_level . absolute_name , content , @options , nil
314
+
315
+ assert_equal @RP , top_level . parser
316
+ end
317
+ end
333
318
334
- assert_equal @RP , @top_level . parser
319
+ private
320
+
321
+ def with_top_level ( filename , content , &block )
322
+ absoluate_filename = File . join Dir . tmpdir , filename
323
+ File . open absoluate_filename , 'w' do |io |
324
+ io . write content
325
+ end
326
+
327
+ top_level = RDoc ::TopLevel . new absoluate_filename
328
+
329
+ yield ( top_level , content )
330
+ ensure
331
+ File . unlink absoluate_filename
335
332
end
336
333
337
334
end
0 commit comments