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; Minitest
 6;; Rails unit tests
 7(
 8    (class
 9        name: [
10          (constant) @run
11          (scope_resolution scope: (constant) name: (constant) @run)
12        ]
13        (superclass (scope_resolution) @superclass (#match? @superclass "(::IntegrationTest|::TestCase|::SystemTestCase)$"))
14    ) @minitest-test
15    (#set! tag minitest-test)
16)
17
18(
19    (call
20        method: (identifier) @run (#eq? @run "test")
21        arguments: (argument_list (string (string_content) @name))
22    ) @minitest-test
23    (#set! tag minitest-test)
24)
25
26; Methods that begin with test_
27(
28    (method
29        name: (identifier) @run (#match? @run "^test_")
30    ) @minitest-test
31    (#set! tag minitest-test)
32)
33
34; System tests that inherit from ApplicationSystemTestCase
35(
36    (class
37        name: (constant) @run (superclass) @superclass (#match? @superclass "(ApplicationSystemTestCase)$")
38    ) @minitest-test
39    (#set! tag minitest-test)
40)
41
42; RSpec
43
44; Example groups with literals
45(
46    (call
47       method: (identifier) @run (#any-of? @run "describe" "context")
48       arguments: (argument_list . (_) @name)
49    ) @rspec-test
50    (#set! tag rspec-test)
51)
52
53; Examples
54(
55    (call
56        method: (identifier) @run (#any-of? @run "it" "its" "specify")
57        arguments: (argument_list (string (string_content) @name))
58    ) @rspec-test
59    (#set! tag rspec-test)
60)
61
62; Examples (one-liner syntax)
63(
64    (call
65        method: (identifier) @run (#any-of? @run "it" "its" "specify")
66        block: (_) @name
67        !arguments
68    ) @rspec-test
69    (#set! tag rspec-test)
70)