Skip to content

Conversation

@vitallium
Copy link
Collaborator

Reordered and added @RUBY_TEST_NAME capture to test method arguments and blocks to provide explicit test name references for:

  • test method with string argument
  • describe/context/it/its/specify methods with arguments
  • it/its/specify methods with blocks without arguments

This capture can be references in Zed tasks via ZED_CUSTOM_RUBY_TEST_NAME variable. For example, to run a single Minitest properly we need to define the following Zed task:

  {
    "label": "test $ZED_RELATIVE_FILE -n /$ZED_CUSTOM_RUBY_TEST_NAME/",
    "command": "bin/rails",
    "args": [
      "test",
      "$ZED_RELATIVE_FILE",
      "-n",
      "/$ZED_CUSTOM_RUBY_TEST_NAME/"
    ],
    "tags": ["ruby-test"]
  }

Reordered and added @RUBY_TEST_NAME capture to test method arguments
and blocks to provide explicit test name references for:
- test method with string argument
- describe/context/it/its/specify methods with arguments
- it/its/specify methods with blocks without arguments
@cla-bot cla-bot bot added the cla-signed label May 21, 2025
@vitallium vitallium merged commit 7c84df6 into main May 22, 2025
3 checks passed
@vitallium vitallium deleted the vs/expose-ruby-test-name-runnable branch May 22, 2025 17:30
@andyw8
Copy link
Contributor

andyw8 commented Jun 1, 2025

👋 @vitallium is this still working for you with example in the PR description?

I'm trying to update my config to use the new $ZED_CUSTOM_RUBY_TEST_NAME but it doesn't seem to be recognized. I don't see any errors in the logs, but the task isn't listed in the task: spawn list. If I remove the $ZED_CUSTOM_RUBY_TEST_NAME part then I see it listed, so it seems it's erroring on that name.

I'm on the latest Zed (v0.188.5) and I'm using a local check out of this repo.

@vitallium
Copy link
Collaborator Author

👋 @vitallium is this still working for you with example in the PR description?

I'm trying to update my config to use the new $ZED_CUSTOM_RUBY_TEST_NAME but it doesn't seem to be recognized. I don't see any errors in the logs, but the task isn't listed in the task: spawn list. If I remove the $ZED_CUSTOM_RUBY_TEST_NAME part then I see it listed, so it seems it's erroring on that name.

I'm on the latest Zed (v0.188.5) and I'm using a local check out of this repo.

Hi! We haven't released a new version with that fix yet. I think we can do that now. Let me create a new release. Thanks!

@andyw8
Copy link
Contributor

andyw8 commented Jun 2, 2025

We haven't released a new version with that fix yet

Yeah, I realised that but I was using 'Install Dev Extension' to run it locally.

Just tried with the v0.8.0 release and I'm seeing the same problem.

@vitallium
Copy link
Collaborator Author

We haven't released a new version with that fix yet

Yeah, I realised that but I was using 'Install Dev Extension' to run it locally.

Just tried with the v0.8.0 release and I'm see the same problem.

Ah, found the problem. It is a result of bad merge:

    diff --git i/languages/ruby/runnables.scm w/languages/ruby/runnables.scm
index c58344a..2bda1fb 100644
--- i/languages/ruby/runnables.scm
+++ w/languages/ruby/runnables.scm
@@ -17,8 +17,8 @@
 (
   (call
     method: (identifier) @run (#eq? @run "test")
-  ) @_ruby-test
     arguments: (argument_list (string (string_content) @name @RUBY_TEST_NAME))
+  ) @_ruby-test
   (#set! tag ruby-test)
 )
 
@@ -42,8 +42,8 @@
 (
   (call
     method: (identifier) @run (#any-of? @run "describe" "context" "it" "its" "specify")
-  ) @_ruby-test
     arguments: (argument_list . (_) @name @RUBY_TEST_NAME)
+  ) @_ruby-test
   (#set! tag ruby-test)
 )

I think I should prioritize #95 to avoid such annoying issues. I will push a fix and release v0.8.1. Sorry for that!

@vitallium
Copy link
Collaborator Author

Pushed the fix.

@andyw8
Copy link
Contributor

andyw8 commented Jun 2, 2025

Thanks for looking into. Still doesn't seem to work for me though 🤔

Are you on the same Zed version? (v0.188.5)

@vitallium
Copy link
Collaborator Author

Thanks for looking into. Still doesn't seem to work for me though 🤔

Are you on the same Zed version? (v0.188.5)

Can you share please the code snippet? I tried it on 0.189.3 (Zed Preview) and 0.188.5 (Zed Stable), and it works:

CleanShot 2025-06-02 at 15 52 27@2x

@andyw8
Copy link
Contributor

andyw8 commented Jun 7, 2025

This is now working for me, but I think there may be some issue with how tasks are cached in Zed. I'll report if I notice it again.

@vitallium
Copy link
Collaborator Author

This is now working for me, but I think there may be some issue with how tasks are cached in Zed. I'll report if I notice it again.

Awesome. Thanks!

@lcmen
Copy link

lcmen commented Jul 26, 2025

Hey @vitallium ! Thank you for this lovely extension.

I've just started using Zed with ruby, and I have encountered a problem with $ZED_CUSTOM_RUBY_TEST_NAME variable. Specifically, it picks the class name instead of the method name from my test file.

Here is an example file:

class TestApp < Minitest::Test
  def test_root_endpoint
    get "/"

    assert last_response.ok?
    assert_equal "application/json", last_response.content_type
  end
end

If I try to spawn a test within test_root_endpoint method, ZED_CUSTOM_RUBY_TEST_NAME will be set to TestApp instead of test_rood_endpoint. Am I doing something wrong?

Here are my tasks definitions:

[
  {
    "label": "Test /$ZED_CUSTOM_RUBY_TEST_NAME/",
    "command": "bundle",
    "args": [
      "exec",
      "ruby",
      "-Itest",
      "-rhelper",
      "$ZED_RELATIVE_FILE",
      "-n",
      "\"$ZED_CUSTOM_RUBY_TEST_NAME\""
    ],
    "tags": ["ruby-test"]
  }
]

I would appreciate any pointers. Thanks again!

@vitallium
Copy link
Collaborator Author

Hey @vitallium ! Thank you for this lovely extension.

I've just started using Zed with ruby, and I have encountered a problem with $ZED_CUSTOM_RUBY_TEST_NAME variable. Specifically, it picks the class name instead of the method name from my test file.

Here is an example file:

class TestApp < Minitest::Test
  def test_root_endpoint
    get "/"

    assert last_response.ok?
    assert_equal "application/json", last_response.content_type
  end
end

If I try to spawn a test within test_root_endpoint method, ZED_CUSTOM_RUBY_TEST_NAME will be set to TestApp instead of test_rood_endpoint. Am I doing something wrong?

Here are my tasks definitions:

[
  {
    "label": "Test /$ZED_CUSTOM_RUBY_TEST_NAME/",
    "command": "bundle",
    "args": [
      "exec",
      "ruby",
      "-Itest",
      "-rhelper",
      "$ZED_RELATIVE_FILE",
      "-n",
      "\"$ZED_CUSTOM_RUBY_TEST_NAME\""
    ],
    "tags": ["ruby-test"]
  }
]

I would appreciate any pointers. Thanks again!

Hi, it seems we don't expose RUBY_TEST_NAME for test methods that starts with test_. This is a bug indeed. I will land a fix for it ASAP. Thanks for reporting!

@vitallium
Copy link
Collaborator Author

@lcmen will be fixed in #153

@lcmen
Copy link

lcmen commented Jul 26, 2025

@lcmen will be fixed in #153

Awesome, thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants