lib/rubocop/cop/mixin/minitest_exploration_helpers.rb in rubocop-minitest-0.12.1 vs lib/rubocop/cop/mixin/minitest_exploration_helpers.rb in rubocop-minitest-0.13.0
- old
+ new
@@ -42,10 +42,16 @@
class_ancestor = node.each_ancestor(:class).first
test_class?(class_ancestor)
end
def test_cases(class_node)
- class_def_nodes(class_node).select { |def_node| test_case_name?(def_node.method_name) }
+ test_cases = class_def_nodes(class_node).select { |def_node| test_case_name?(def_node.method_name) }
+
+ # Support Active Support's `test 'example' { ... }` method.
+ # https://api.rubyonrails.org/classes/ActiveSupport/Testing/Declarative.html
+ test_blocks = class_node.each_descendant(:block).select { |block_node| block_node.method?(:test) }
+
+ test_cases + test_blocks
end
def lifecycle_hooks(class_node)
class_def_nodes(class_node)
.select { |def_node| lifecycle_hook_method?(def_node) }