Skip to content

Commit

Permalink
Relax the prism test parser conditions
Browse files Browse the repository at this point in the history
Checking explicitly against `test` break extensions that provide their
own methods to generate tests, like `minitest-spec-rails` or `minitest-rails`.

Fixes rails#51956
  • Loading branch information
Earlopain committed May 30, 2024
1 parent ea0f0a2 commit c7c9743
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions railties/lib/rails/test_unit/test_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion railties/test/test_unit/test_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit c7c9743

Please sign in to comment.