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

Allow running specific test with path/to/test.rb:loc #47

Open
phillipspc opened this issue Nov 12, 2024 · 3 comments
Open

Allow running specific test with path/to/test.rb:loc #47

phillipspc opened this issue Nov 12, 2024 · 3 comments

Comments

@phillipspc
Copy link

Sometimes you just want to run a single test. Minitest and RSpec both support this, and I think it would be a good addition to Quickdraw! 🤠

@joeldrapper
Copy link
Owner

I’m working on a really big change in the design first but I do plan to support this.

@kaspth
Copy link

kaspth commented Dec 22, 2024

Technically, minitest doesn't support running tests by line number, but it does support filtering tests on name:

   -n, --name PATTERN               Filter run on /regexp/ or string.
   -e, --exclude PATTERN            Exclude /regexp/ or string from run.

I often do bin/rails t -n /some_method/ to run my tests.

Now, Rails supports line filtering out of the box, but it's implemented via the above pattern support in minitest. When minitest loads, it populates the --name filter into a filter: option and calls === on it.

Rails overrides the passed in filter: with a custom CompositeFilter that also responds to ===.
That happens here https://github.com/rails/rails/blob/5813c82bbd3770d15f8b7f22e898727a7587f6df/railties/lib/rails/test_unit/line_filtering.rb#L8

It looks like the code itself has gotten quite a bit more complex since I wrote it, but the essential logic is in CompositeFilter#=== here https://github.com/rails/rails/blob/5813c82bbd3770d15f8b7f22e898727a7587f6df/railties/lib/rails/test_unit/runner.rb#L158
We then defer to each custom filter's === method here, to blend Rails filters by file/line and minitest's regex filters. https://github.com/rails/rails/blob/5813c82bbd3770d15f8b7f22e898727a7587f6df/railties/lib/rails/test_unit/runner.rb#L194-L201

@kaspth
Copy link

kaspth commented Dec 22, 2024

minitest's rationale for test name based filtering is that the name is less likely to change versus the line number. That's not always the case though, and sometimes line number filtering is handy. I do prefer minitest's -n // regexes almost always.

I'm not saying Quickdraw needs to support this, I just like this kind of code archeology 😄 — even if we may want to revisit things from scratch.

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

3 participants