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|Minitest::Test)$"))
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; Examples
44(
45 (call
46 method: (identifier) @run (#any-of? @run "describe" "context" "it" "its" "specify")
47 arguments: (argument_list . (_) @_name)
48 ) @_rspec-test
49 (#set! tag rspec-test)
50)
51
52; Examples (one-liner syntax)
53(
54 (call
55 method: (identifier) @run (#any-of? @run "it" "its" "specify")
56 block: (_) @_name
57 !arguments
58 ) @_rspec-test
59 (#set! tag rspec-test)
60)