Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

ruby: Add support for running tests (#12052)

Vitaly Slobodin99570f9361cc
diff --git a/extensions/ruby/languages/ruby/outline.scm b/extensions/ruby/languages/ruby/outline.scm
index 544257ac0c3..be62712ef30 100644
--- a/extensions/ruby/languages/ruby/outline.scm
+++ b/extensions/ruby/languages/ruby/outline.scm
@@ -18,3 +18,9 @@
(module
"module" @context
name: (_) @name) @item
+
+; Minitest/RSpec
+(call
+ method: (identifier) @run (#any-of? @run "describe" "context" "test")
+ arguments: (argument_list . (_) @name)
+) @item
diff --git a/extensions/ruby/languages/ruby/runnables.scm b/extensions/ruby/languages/ruby/runnables.scm
new file mode 100644
index 00000000000..4170a655ea8
--- /dev/null
+++ b/extensions/ruby/languages/ruby/runnables.scm
@@ -0,0 +1,49 @@
+; Adapted from the following sources:
+; Minitest: https://github.com/zidhuss/neotest-minitest/blob/main/lua/neotest-minitest/init.lua
+; RSpec: https://github.com/olimorris/neotest-rspec/blob/main/lua/neotest-rspec/init.lua
+
+; Minitest
+;; Rails unit tests
+(class
+ name: [
+ (constant) @run
+ (scope_resolution scope: (constant) name: (constant) @run)
+ ]
+ (superclass (scope_resolution) @superclass (#match? @superclass "(::IntegrationTest|::TestCase|::SystemTestCase)$"))
+) @minitest-test
+
+(call
+ method: (identifier) @run (#eq? @run "test")
+ arguments: (argument_list (string (string_content) @name))
+) @minitest-test
+
+; Methods that begin with test_
+(method
+ name: (identifier) @run (#match? @run "^test_")
+) @minitest-test
+
+; System tests that inherit from ApplicationSystemTestCase
+(class
+ name: (constant) @run (superclass) @superclass (#match? @superclass "(ApplicationSystemTestCase)$")
+) @minitest-test
+
+; RSpec
+
+; Example groups with literals
+(call
+ method: (identifier) @run (#any-of? @run "describe" "context")
+ arguments: (argument_list . (_) @name)
+) @rspec-test
+
+; Examples
+(call
+ method: (identifier) @run (#any-of? @run "it" "its" "specify")
+ arguments: (argument_list (string (string_content) @name))
+) @rspec-test
+
+; Examples (one-liner syntax)
+(call
+ method: (identifier) @run (#any-of? @run "it" "its" "specify")
+ block: (_) @name
+ !arguments
+) @rspec-test
diff --git a/extensions/ruby/languages/ruby/tasks.json b/extensions/ruby/languages/ruby/tasks.json
new file mode 100644
index 00000000000..e4d5bca1cbc
--- /dev/null
+++ b/extensions/ruby/languages/ruby/tasks.json
@@ -0,0 +1,14 @@
+[
+ {
+ "label": "test $ZED_SYMBOL",
+ "command": "ruby",
+ "args": ["-Itest", "$ZED_FILE", "--name", "\"/$ZED_SYMBOL/\""],
+ "tags": ["minitest-test"]
+ },
+ {
+ "label": "rspec $ZED_SYMBOL",
+ "command": "./bin/rspec",
+ "args": ["\"$ZED_FILE:$ZED_ROW\""],
+ "tags": ["rspec-test"]
+ }
+]