forked from rubocop/rubocop-minitest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
no_assertions.rb
41 lines (35 loc) · 928 Bytes
/
no_assertions.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# frozen_string_literal: true
module RuboCop
module Cop
module Minitest
# Checks if test cases contain any assertion calls.
#
# @example
# # bad
# class FooTest < Minitest::Test
# def test_the_truth
# end
# end
#
# # good
# class FooTest < Minitest::Test
# def test_the_truth
# assert true
# end
# end
#
class NoAssertions < Base
include MinitestExplorationHelpers
MSG = 'Test case has no assertions.'
def on_class(class_node)
return unless test_class?(class_node)
test_cases(class_node).each do |node|
assertions_count = assertions_count(node)
next if assertions_count.positive?
add_offense(node.block_type? ? node.source_range : node.loc.name)
end
end
end
end
end
end