Skip to content

Commit d96a7a7

Browse files
committed
Ignore constants discovered in passing
When RDoc parses a class body it will create new modules for newly discovered constant namespaces. When the constant isn't assigned-to the namespaces are now marked as ignored which prevents them from appearing in the coverage report. Bug #209
1 parent be84349 commit d96a7a7

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

History.rdoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
Bug #214 by Ryan Davis.
3636
* Fixed documented? check for classes which indicated incorrect 100%
3737
coverage. Bug #211 by Ryan Davis.
38+
* RDoc ignores constants discovered in passing in class and method bodies.
39+
Bug #209 by Ryan Davis.
3840

3941
=== 4.0.1 / 2013-03-27
4042

lib/rdoc/parser/ruby.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,7 @@ def parse_class container, single, tk, comment
674674
# true, no found constants will be added to RDoc.
675675

676676
def parse_constant container, tk, comment, ignore_constants = false
677+
prev_container = container
677678
offset = tk.seek
678679
line_no = tk.line_no
679680

@@ -696,6 +697,11 @@ def parse_constant container, tk, comment, ignore_constants = false
696697
end
697698

698699
unless TkASSIGN === eq_tk then
700+
while container and container != prev_container do
701+
container.ignore
702+
container = container.parent
703+
end
704+
699705
unget_tk eq_tk
700706
return false
701707
end

test/test_rdoc_parser_ruby.rb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ class Foo
684684
assert_equal 2, foo.method_list.length
685685
end
686686

687-
def test_parse_const_fail_w_meta
687+
def test_parse_const_fail_w_meta_method
688688
util_parser <<-CLASS
689689
class ConstFailMeta
690690
##
@@ -706,6 +706,27 @@ class ConstFailMeta
706706
assert_equal 1, const_fail_meta.attributes.length
707707
end
708708

709+
def test_parse_const_third_party
710+
util_parser <<-CLASS
711+
class A
712+
true if B::C
713+
true if D::E::F
714+
end
715+
CLASS
716+
717+
tk = @parser.get_tk
718+
719+
@parser.parse_class @top_level, RDoc::Parser::Ruby::NORMAL, tk, @comment
720+
721+
a = @top_level.classes.first
722+
assert_equal 'A', a.full_name
723+
724+
visible = @store.all_modules.reject { |mod| mod.ignored? }
725+
visible = visible.map { |mod| mod.full_name }
726+
727+
assert_empty visible
728+
end
729+
709730
def test_parse_class_nested_superclass
710731
foo = @top_level.add_module RDoc::NormalModule, 'Foo'
711732

0 commit comments

Comments
 (0)