foneandrew / ruby-spec-runner

Run specific rspec & minitest tests from within vscode
MIT License
9 stars 3 forks source link

Unable to run contexts for Minitest #8

Closed thuyihan1206 closed 1 year ago

thuyihan1206 commented 1 year ago

First of all, thank you for the amazing extension!

The ruby-spec-runner.minitestCodeLensPrompts seems to suggest that we can run an example or several examples grouped by a context. However, I haven't been able to get the "Run" button displayed above a context.

Looking at the code, it seems that the matcher doesn't match the keyword "context":

// in src/minitest/MinitestParser.ts
private matcher = /(?:(?:^\s*(?:it|should)\(?\s*(?<title>(['"]).*\2)\)?\s*(?:do|{))|(?:^\s*def\s*(?<unit_def>test_\w+)(?:\(\))?\s*))\s*(?:#.*)?$/;

Perhaps we should clarify it in the ruby-spec-runner.minitestCodeLensPrompts configuration option.

foneandrew commented 1 year ago

Yeah good call on making it more obvious in the config and readme. Sorry that you had to dig into the code to find that out.

The context feature isn't supported in minitest as it didn't work for me in my testing. So I could supply it with a line number for a context but it just seemed to run the nearest test instead of all the tests in that context. So I got rid of the prompt to reduce confusion.

Although if you know that minitest can run properly for a whole context (like if it's a missing config or old version that I am using) let me know and I will add the context prompt back in.

thuyihan1206 commented 1 year ago

Hi @foneandrew, thank you for the clarification. I'm not aware of any way to execute a context by line number, either.

The closest thing I can think of is to use m to run all tests that match some string. It works for context too. For example, if you have a context defined like:

context "my examples" do
  should "example 1" do
      # ...
  end

  should "example 2" do
      # ...
  end
end

Then you can run all tests within the context with this:

bundle exec m test.rb -- -n "/my examples/"
# don't forget the regex style slashes as the actual test name is typically
# longer than the `context`/`should` string
thuyihan1206 commented 1 year ago

Actually, the -n option doesn't require the m runner. So one possible solution is to match the context string instead of relying on the line number. However, this approach may result in multiple contexts being run together if they share the matched string.

foneandrew commented 1 year ago

Added this to 3.8.0 which I just published. Should work for the code lens buttons and the keyboard shortcut. Adding it was harder than expected as the standard minitest output is a bit of a nightmare to parse so we need to do a bunch of manual line matching shenanigans to get it to work (minitest doesn't give line numbers for tests that pass ಠ╭╮ಠ ). The keyboard shortcut it also limited compared to rspec cause of the things we have to do to make it work.

Anyway it should work for most cases. Lemme know if you run into problems. Or if the lens prompt isn't appearing in places that it should.

thuyihan1206 commented 1 year ago

Wow, thanks for the quick work! My only ask is that if we can add -- in front of -n. It indicates the beginning of arguments being passed in. It would be helpful when a user wants to specify their own MiniTest command.

Cursor_and_Settings_—_backend

Thank you again!

thuyihan1206 commented 1 year ago

I suspect we could change this line and this line to

testNameFilter = `-- -n ${this.testNameFilterRegex(testName)}`;
foneandrew commented 1 year ago

The -- should be there in 3.8.1 Thanks for your help!