16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/canopus/test_runner/rspec.rb', line 16
def discover(root, path:, limit:, cancelled:)
require "prism"
path = path.dup.freeze
tests, visited = [], 0
stack = [[root, [].freeze, "".freeze, false]]
until stack.empty? || tests.length >= limit
break if cancelled.call
node, groups, full_description, parent_module = stack.pop
break if (visited += 1) > MAX_NODES
if node.is_a?(Prism::DefNode)
next
elsif node.is_a?(Prism::CallNode)
if group_call?(node) && groups.length < MAX_GROUP_DEPTH && (details = group_name(node))
group, last_module = details
separator = !full_description.empty? && !(parent_module && group.match?(/\A(?:#|::|\.)/)) ? " " : ""
nested_description = "#{full_description}#{separator}#{group}".freeze
stack << [node.block.body, [*groups, group].freeze, nested_description, last_module] if node.block.body
next
elsif !groups.empty? && EXAMPLES.include?(node.name) && !node.receiver && (name = literal_name(node.arguments&.arguments&.first))
add(tests, path, name, groups, full_description, node)
next
end
next if node.block
end
node.compact_child_nodes.reverse_each do |child|
stack << [child, groups, full_description, parent_module]
end
end
tests.freeze
end
|