Skip to content

Commit c7c9743

Browse files
committed
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 rails#51956
1 parent ea0f0a2 commit c7c9743

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

railties/lib/rails/test_unit/test_parser.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ def self.definition_for(method)
2222
while (node = queue.shift)
2323
case node.type
2424
when :def_node
25-
if node.name.start_with?("test") && node.location.start_line == start_line
25+
if node.location.start_line == start_line
2626
return [filepath, start_line..node.location.end_line]
2727
end
2828
when :call_node
29-
if node.name == :test && node.location.start_line == start_line
29+
if node.location.start_line == start_line
3030
return [filepath, start_line..node.location.end_line]
3131
end
3232
end

railties/test/test_unit/test_parser_test.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ def test_oneline; assert true; end
3838
assert true
3939
assert_not false
4040
}
41+
42+
# Check that extensions can provide aliases for testing methods
43+
def self.my_testing_alias(test_name, &)
44+
define_method(:"test_#{test_name}", &)
45+
end
46+
47+
my_testing_alias("method_alias") { assert true }
4148
end
4249

4350
class TestParserTest < ActiveSupport::TestCase
@@ -57,7 +64,8 @@ def test_parser
5764
[:test_declarative_explicit_receiver, __FILE__, 27..31],
5865
[:test_declarative_oneline, __FILE__, 33..33],
5966
[:test_declarative_oneline_do, __FILE__, 35..35],
60-
[:"test_declarative_multiline_w/_braces", __FILE__, 37..40]
67+
[:"test_declarative_multiline_w/_braces", __FILE__, 37..40],
68+
[:"test_method_alias", __FILE__, 47..47],
6169
]
6270

6371
assert_equal expected, actual

0 commit comments

Comments
 (0)