Skip to content

Conversation

@thomasmarshall
Copy link
Contributor

Motivation

Closes #3722.

Methods starting test_ are picked up my Minitest but were not being discovered by the LSP.

describe "MySpec" do
  def test_foo
    assert true
  end
end

Implementation

This commit adds a #on_def_node_enter handler to register test items for methods starting test_ in describe blocks. It should not match non-test methods (e.g. helper methods), nor should it match methods named test_ in non-spec blocks.

Automated Tests

I have added a new testfor this fix.

Manual Tests

  1. Add a spec with a test_ method
  2. See that it is discovered by the LSP
Before After
Screenshot 2025-12-04 at 13 03 13 Screenshot 2025-12-04 at 13 04 10

This commit ensures methods starting with "test_" are discovered as test
methods in specs.
@thomasmarshall thomasmarshall requested a review from a team as a code owner December 4, 2025 13:13
@vinistock
Copy link
Member

I think this may cause duplicate test items in this case below. The reason is because both the TestStyle and SpecStyle listeners run together and so if we always handle test_ methods, it will end up duplicating.

class MySpec < Minitest::Spec
  def test_something; end # is this one duplicated?
end

Can you please check if we're doing the right thing in this case?

Copy link
Contributor Author

Hmm in this case it's not duplicated (because we check current_group.is_a?(DescribeGroup)) but I found a case where it is duplicated, where we have a describe inside a spec class:

class MySpec < Minitest::Spec
  describe 'something' do
    def test_something; end # this one is duplicated
  end
end

I'll work on a fix.

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

Successfully merging this pull request may close these issues.

Tests defined as test_ methods in spec-style describe blocks are not discovered

2 participants