runnables.scm

 1; Adapted from the following sources:
 2; Minitest: https://github.com/zidhuss/neotest-minitest/blob/main/lua/neotest-minitest/init.lua
 3; RSpec: https://github.com/olimorris/neotest-rspec/blob/main/lua/neotest-rspec/init.lua
 4
 5; Tests that inherit from a specific class
 6(
 7    (class
 8        name: [
 9          (constant) @run
10          (scope_resolution scope: (constant) name: (constant) @run)
11        ]
12        (superclass (scope_resolution) @superclass (#match? @superclass "(::IntegrationTest|::TestCase|::SystemTestCase|Minitest::Test|TLDR)$"))
13    ) @_ruby-test
14    (#set! tag ruby-test)
15)
16
17(
18    (call
19        method: (identifier) @run (#eq? @run "test")
20        arguments: (argument_list (string (string_content) @_name))
21    ) @_ruby-test
22    (#set! tag ruby-test)
23)
24
25; Methods that begin with test_
26(
27    (method
28        name: (identifier) @run (#match? @run "^test_")
29    ) @_ruby-test
30    (#set! tag ruby-test)
31)
32
33; System tests that inherit from ApplicationSystemTestCase
34(
35    (class
36        name: (constant) @run (superclass) @superclass (#match? @superclass "(ApplicationSystemTestCase)$")
37    ) @_ruby-test
38    (#set! tag ruby-test)
39)
40
41; Examples
42(
43    (call
44       method: (identifier) @run (#any-of? @run "describe" "context" "it" "its" "specify")
45       arguments: (argument_list . (_) @_name)
46    ) @_ruby-test
47    (#set! tag ruby-test)
48)
49
50; Examples (one-liner syntax)
51(
52    (call
53        method: (identifier) @run (#any-of? @run "it" "its" "specify")
54        block: (_) @_name
55        !arguments
56    ) @_ruby-test
57    (#set! tag ruby-test)
58)