lib/rubocop/cop/mixin/minitest_exploration_helpers.rb in rubocop-minitest-0.11.1 vs lib/rubocop/cop/mixin/minitest_exploration_helpers.rb in rubocop-minitest-0.12.0
- old
+ new
@@ -17,10 +17,12 @@
refute refute_empty refute_equal refute_in_delta refute_in_epsilon refute_includes refute_instance_of
refute_kind_of refute_match refute_nil refute_operator refute_path_exists refute_predicate
refute_respond_to refute_same
].freeze
+ FLUNK = 'flunk'
+
LIFECYCLE_HOOK_METHODS = %i[
before_setup
setup
after_setup
before_teardown
@@ -40,12 +42,12 @@
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) }
+ (class_def_nodes(class_node).select { |def_node| test_case_name?(def_node.method_name) }) +
+ test_method_calls(class_node)
end
def lifecycle_hooks(class_node)
class_def_nodes(class_node)
.select { |def_node| lifecycle_hook_method?(def_node) }
@@ -60,10 +62,16 @@
else
class_def.each_child_node(:def).to_a
end
end
+ # support https://api.rubyonrails.org/classes/ActiveSupport/Testing/Declarative.html
+ def test_method_calls(class_node)
+ block_nodes = class_node.each_descendant(:block)
+ block_nodes.select { |block_node| block_node.method?(:test) }
+ end
+
def test_case_name?(name)
name.to_s.start_with?('test_')
end
def assertions(def_node)
@@ -80,14 +88,17 @@
send_nodes.select { |send_node| assertion?(send_node) }
end
def assertion?(node)
node.send_type? &&
- ASSERTION_PREFIXES.any? { |prefix| node.method_name.to_s.start_with?(prefix) }
+ ASSERTION_PREFIXES.any? do |prefix|
+ method_name = node.method_name.to_s
+ method_name == FLUNK || method_name.start_with?(prefix)
+ end
end
def assertion_method?(method_name)
- ASSERTION_METHODS.include?(method_name)
+ method_name == FLUNK || ASSERTION_METHODS.include?(method_name)
end
def lifecycle_hook_method?(node)
node.def_type? && LIFECYCLE_HOOK_METHODS.include?(node.method_name)
end