forked from rubocop/rubocop-minitest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
non_public_test_method.rb
55 lines (52 loc) · 1.4 KB
/
non_public_test_method.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# frozen_string_literal: true
module RuboCop
module Cop
module Minitest
# Detects non `public` (marked as `private` or `protected`) test methods.
# Minitest runs only test methods which are `public`.
#
# @example
# # bad
# class FooTest
# private # or protected
# def test_does_something
# assert_equal 42, do_something
# end
# end
#
# # good
# class FooTest
# def test_does_something
# assert_equal 42, do_something
# end
# end
#
# # good (not a test case name)
# class FooTest
# private # or protected
# def does_something
# assert_equal 42, do_something
# end
# end
#
# # good (no assertions)
# class FooTest
# private # or protected
# def test_does_something
# do_something
# end
# end
#
class NonPublicTestMethod < Base
include MinitestExplorationHelpers
include DefNode
MSG = 'Non `public` test method detected. Make it `public` for it to run.'
def on_class(node)
test_cases(node, visibility_check: false).each do |test_case|
add_offense(test_case) if non_public?(test_case) && assertions(test_case).any?
end
end
end
end
end
end