Relax the prism test parser conditions

Checking explicitly against `test` break extensions that provide their
own methods to generate tests, like `minitest-spec-rails` or `minitest-rails`.

Fixes #51956
This commit is contained in:
Earlopain 2024-05-30 22:28:38 +02:00
parent ea0f0a2c96
commit c7c974335d
No known key found for this signature in database
GPG Key ID: 48860312319ADF61
2 changed files with 11 additions and 3 deletions

@ -22,11 +22,11 @@ def self.definition_for(method)
while (node = queue.shift)
case node.type
when :def_node
if node.name.start_with?("test") && node.location.start_line == start_line
if node.location.start_line == start_line
return [filepath, start_line..node.location.end_line]
end
when :call_node
if node.name == :test && node.location.start_line == start_line
if node.location.start_line == start_line
return [filepath, start_line..node.location.end_line]
end
end

@ -38,6 +38,13 @@ def test_oneline; assert true; end
assert true
assert_not false
}
# Check that extensions can provide aliases for testing methods
def self.my_testing_alias(test_name, &)
define_method(:"test_#{test_name}", &)
end
my_testing_alias("method_alias") { assert true }
end
class TestParserTest < ActiveSupport::TestCase
@ -57,7 +64,8 @@ def test_parser
[:test_declarative_explicit_receiver, __FILE__, 27..31],
[:test_declarative_oneline, __FILE__, 33..33],
[:test_declarative_oneline_do, __FILE__, 35..35],
[:"test_declarative_multiline_w/_braces", __FILE__, 37..40]
[:"test_declarative_multiline_w/_braces", __FILE__, 37..40],
[:"test_method_alias", __FILE__, 47..47],
]
assert_equal expected, actual