Skip to content

Commit 33925f8

Browse files
authored
Add --no-skipping-tests option
1 parent fb28c2f commit 33925f8

File tree

4 files changed

+80
-1
lines changed

4 files changed

+80
-1
lines changed

lib/rdoc/options.rb

+12
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,10 @@ class RDoc::Options
339339

340340
attr_reader :visibility
341341

342+
##
343+
# Indicates if files of test suites should be skipped
344+
attr_accessor :skip_tests
345+
342346
def initialize loaded_options = nil # :nodoc:
343347
init_ivars
344348
override loaded_options if loaded_options
@@ -386,6 +390,7 @@ def init_ivars # :nodoc:
386390
@write_options = false
387391
@encoding = Encoding::UTF_8
388392
@charset = @encoding.name
393+
@skip_tests = true
389394
end
390395

391396
def init_with map # :nodoc:
@@ -778,6 +783,13 @@ def parse argv
778783

779784
opt.separator nil
780785

786+
opt.on("--no-skipping-tests", nil,
787+
"Don't skip generating documentation for test and spec files") do |value|
788+
@skip_tests = false
789+
end
790+
791+
opt.separator nil
792+
781793
opt.on("--extension=NEW=OLD", "-E",
782794
"Treat files ending with .new as if they",
783795
"ended with .old. Using '-E cgi=rb' will",

lib/rdoc/rdoc.rb

+15-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ class RDoc::RDoc
3535

3636
GENERATORS = {}
3737

38+
##
39+
# List of directory names always skipped
40+
41+
UNCONDITIONALLY_SKIPPED_DIRECTORIES = %w[CVS .svn .git].freeze
42+
43+
##
44+
# List of directory names skipped if test suites should be skipped
45+
46+
TEST_SUITE_DIRECTORY_NAMES = %w[spec test].freeze
47+
48+
3849
##
3950
# Generator instance used for creating output
4051

@@ -280,7 +291,10 @@ def normalized_file_list(relative_files, force_doc = false,
280291
file_list[rel_file_name] = mtime
281292
end
282293
when "directory" then
283-
next if rel_file_name == "CVS" || rel_file_name == ".svn"
294+
next if UNCONDITIONALLY_SKIPPED_DIRECTORIES.include?(rel_file_name)
295+
296+
basename = File.basename(rel_file_name)
297+
next if options.skip_tests && TEST_SUITE_DIRECTORY_NAMES.include?(basename)
284298

285299
created_rid = File.join rel_file_name, "created.rid"
286300
next if File.file? created_rid

test/rdoc/test_rdoc_options.rb

+11
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ def test_to_yaml
8383
'title' => nil,
8484
'visibility' => :protected,
8585
'webcvs' => nil,
86+
'skip_tests' => true,
8687
}
8788

8889
assert_equal expected, coder
@@ -871,6 +872,16 @@ def test_load_options_no_file
871872
end
872873
end
873874

875+
def test_skip_test_default_value
876+
@options.parse %w[]
877+
assert_equal true, @options.skip_tests
878+
end
879+
880+
def test_no_skip_test_value
881+
@options.parse %w[--no-skipping-tests]
882+
assert_equal false, @options.skip_tests
883+
end
884+
874885
class DummyCoder < Hash
875886
alias add :[]=
876887
def tag=(tag)

test/rdoc/test_rdoc_rdoc.rb

+42
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,48 @@ def test_normalized_file_list_with_dot_doc_overridden_by_exclude_option
213213
assert_equal expected_files, files
214214
end
215215

216+
def test_normalized_file_list_with_skipping_tests_enabled
217+
files = temp_dir do |dir|
218+
@a = File.expand_path('a.rb')
219+
spec_dir = File.expand_path('spec')
220+
spec_file = File.expand_path(File.join('spec', 'my_spec.rb'))
221+
test_dir = File.expand_path('test')
222+
test_file = File.expand_path(File.join('test', 'my_test.rb'))
223+
FileUtils.touch @a
224+
FileUtils.mkdir_p spec_dir
225+
FileUtils.touch spec_file
226+
FileUtils.mkdir_p test_dir
227+
FileUtils.touch test_file
228+
229+
@rdoc.options.skip_tests = true
230+
@rdoc.normalized_file_list [File.realpath(dir)]
231+
end
232+
233+
files = files.map { |file, *| File.expand_path file }
234+
assert_equal [@a], files
235+
end
236+
237+
def test_normalized_file_list_with_skipping_tests_disabled
238+
files = temp_dir do |dir|
239+
@a = File.expand_path('a.rb')
240+
spec_dir = File.expand_path('spec')
241+
@spec_file = File.expand_path(File.join('spec', 'my_spec.rb'))
242+
test_dir = File.expand_path('test')
243+
@test_file = File.expand_path(File.join('test', 'my_test.rb'))
244+
FileUtils.touch @a
245+
FileUtils.mkdir_p spec_dir
246+
FileUtils.touch @spec_file
247+
FileUtils.mkdir_p test_dir
248+
FileUtils.touch @test_file
249+
250+
@rdoc.options.skip_tests = false
251+
@rdoc.normalized_file_list [File.realpath(dir)]
252+
end
253+
254+
files = files.map { |file, *| File.expand_path file }
255+
assert_equal [@a, @spec_file, @test_file], files.sort
256+
end
257+
216258
def test_parse_file
217259
@rdoc.store = RDoc::Store.new
218260

0 commit comments

Comments
 (0)