@@ -61,11 +61,26 @@ def calc_fully_qualified_name(name)
6161
6262 #: (Prism::ClassNode node, String fully_qualified_name) -> Array[String]
6363 def calc_attached_ancestors ( node , fully_qualified_name )
64- @index . linearized_ancestors_of ( fully_qualified_name )
65- rescue RubyIndexer ::Index ::NonExistingNamespaceError
66- # When there are dynamic parts in the constant path, we will not have indexed the namespace. We can still
67- # provide test functionality if the class inherits directly from Test::Unit::TestCase or Minitest::Test
68- [ node . superclass &.slice ] . compact
64+ superclass = node . superclass
65+
66+ begin
67+ ancestors = @index . linearized_ancestors_of ( fully_qualified_name )
68+ # If the project has no bundle and a test class inherits from `Minitest::Test`, the linearized ancestors will
69+ # not include the parent class because we never indexed it in the first place. Here we add the superclass
70+ # directly, so that we can support running tests in projects without a bundle
71+ return ancestors if ancestors . length > 1
72+
73+ # If all we found is the class itself, then manually include the parent class
74+ if ancestors . first == fully_qualified_name && superclass
75+ return [ *ancestors , superclass . slice ]
76+ end
77+
78+ ancestors
79+ rescue RubyIndexer ::Index ::NonExistingNamespaceError
80+ # When there are dynamic parts in the constant path, we will not have indexed the namespace. We can still
81+ # provide test functionality if the class inherits directly from Test::Unit::TestCase or Minitest::Test
82+ [ superclass &.slice ] . compact
83+ end
6984 end
7085
7186 #: (Prism::ConstantPathNode | Prism::ConstantReadNode | Prism::ConstantPathTargetNode | Prism::CallNode | Prism::MissingNode node) -> String
0 commit comments