Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add support for Spec syntax #30

Open
rmcastil opened this issue Nov 26, 2024 · 2 comments
Open

How to add support for Spec syntax #30

rmcastil opened this issue Nov 26, 2024 · 2 comments

Comments

@rmcastil
Copy link

Thanks for all the effort with this plugin!

Has there been any effort towards getting Minitest's spec syntax working? I'd love to help if possible or even pay for someone's time to get it working.

It looks like this is where the magic happens?

ChatGPT tells me it's tree sitter syntax and looking at the neotest-rspec library it seems like spec syntax can be defined with this

    ((call
      method: (identifier) @namespace.name (#match? @namespace.name "^(describe|context|feature)$")
      .
      block: (_)
    )) @namespace.definition

    ((call
      method: (identifier) @func_name (#match? @func_name "^(it|its|specify)$")
      block: (block (_) @test.name)
    )) @test.definition

    ((call
      method: (identifier) @func_name (#match? @func_name "^(it|its|specify)$")
      block: (do_block (_) @test.name)
      !arguments
    )) @test.definition

    ((call
      method: (identifier) @func_name (#match? @func_name "^(it|its|scenario|it_behaves_like)$")
      arguments: (argument_list (_) @test.name)
    )) @test.definition
@maxenglander
Copy link

maxenglander commented Dec 23, 2024

I've started working on this in my fork. There are a few things I'm working on at the moment:

  • Getting the new Treesitter grammar in place to capture describe, context, etc. as shown by @rmcastil.
  • Generating and detecting test names. Whereas Minitest::Test generates test names like MyTest#test_my_thing, Minitest::Spec generates test names like MyTest::my_scope#test_0001_my thing.
  • Detecting when a test file is using Minitest::Test or Minitest::Spec.

The first two things are pretty straightforward, and I have those partially working. The last bullet point is giving me some trouble. For some cases, it is pretty easy to detect when a test file is using Minitest::Spec, for example:

class MyTest < Minitest::Spec

However, in some cases (this is my situation), Minitest::Spec may be injected into the test code with something like https://github.com/metaskills/minitest-spec-rails, which dynamically extends ActiveSupport::Concern with Minitest::Spec::DSL. I am not sure how, if it is even possible, to capture such a situation with Treesitter grammar.

Maybe for those kinds of special cases we would just offer a static configuration option, e.g.:

return {
  {
    "nvim-neotest/neotest",
    opts = {
      adapters = {
        ["neotest-minitest"] = {
          spec = true
        },
      },
    },
  },
}

@maxenglander
Copy link

maxenglander commented Dec 24, 2024

Nevermind! That third bullet ended up being a non-issue. I put up a draft PR here in case you want to play with it or give feedback: #33. Right now I have test running working, but haven't started on output parsing so although tests can be run, they always show up as failed. Will tackle that next.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants