@@ -523,6 +523,44 @@ module Foo; module Bar; module Qux; end; end; end
523
523
end
524
524
end
525
525
526
+ describe "#module_ancestors" do
527
+ it "returns a list with the base class (if applicable) and included modules" do
528
+ # RDoc chokes on ";" when parsing includes, so replace with "\n".
529
+ top_level = rdoc_top_level_for <<~RUBY . gsub ( ";" , "\n " )
530
+ module M1; end
531
+ module M2; end
532
+ class C1; end
533
+
534
+ module Foo; include M1; include M2; end
535
+ class Bar < C1; include M2; include M1; end
536
+ class Qux < Cx; include Foo; include Mx; end
537
+ RUBY
538
+
539
+ m1 , m2 , c1 , foo , bar , qux = %w[ M1 M2 C1 Foo Bar Qux ] . map { |name | top_level . find_module_named ( name ) }
540
+
541
+ _ ( @helpers . module_ancestors ( foo ) ) . must_equal [ [ "module" , m1 ] , [ "module" , m2 ] ]
542
+ _ ( @helpers . module_ancestors ( bar ) ) . must_equal [ [ "class" , c1 ] , [ "module" , m2 ] , [ "module" , m1 ] ]
543
+ _ ( @helpers . module_ancestors ( qux ) ) . must_equal [ [ "class" , "Cx" ] , [ "module" , foo ] , [ "module" , "Mx" ] ]
544
+ end
545
+
546
+ it "excludes the default base class (Object) from the result" do
547
+ # RDoc chokes on ";" when parsing includes, so replace with "\n".
548
+ top_level = rdoc_top_level_for <<~RUBY . gsub ( ";" , "\n " )
549
+ class Object; end
550
+ class Foo; include M1; end
551
+ RUBY
552
+
553
+ _ ( @helpers . module_ancestors ( top_level . find_module_named ( "Object" ) ) ) . must_equal [ [ "class" , "BasicObject" ] ]
554
+ _ ( @helpers . module_ancestors ( top_level . find_module_named ( "Foo" ) ) ) . must_equal [ [ "module" , "M1" ] ]
555
+
556
+ top_level = rdoc_top_level_for <<~RUBY . gsub ( ";" , "\n " )
557
+ class Foo; include M1; end
558
+ RUBY
559
+
560
+ _ ( @helpers . module_ancestors ( top_level . find_module_named ( "Foo" ) ) ) . must_equal [ [ "module" , "M1" ] ]
561
+ end
562
+ end
563
+
526
564
describe "#method_signature" do
527
565
it "returns the method signature wrapped in <code>" do
528
566
method = rdoc_top_level_for ( <<~RUBY ) . find_module_named ( "Foo" ) . find_method ( "bar" , false )
0 commit comments