Fix discovery of test methods in specs
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
- Add a spec with a
test_method - See that it is discovered by the LSP
| Before | After |
|---|---|
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?
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.