rubocop-minitest 0.18.0 → 0.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/linting.yml +1 -1
- data/.github/workflows/spell_checking.yml +2 -2
- data/CHANGELOG.md +7 -0
- data/config/default.yml +28 -23
- data/docs/antora.yml +1 -1
- data/docs/modules/ROOT/pages/cops.adoc +1 -0
- data/docs/modules/ROOT/pages/cops_minitest.adoc +57 -0
- data/lib/rubocop/cop/minitest/duplicate_test_run.rb +81 -0
- data/lib/rubocop/cop/minitest_cops.rb +1 -0
- data/lib/rubocop/minitest/version.rb +1 -1
- data/relnotes/v0.19.0.md +5 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95cf5254c67b24f10e4739b82656ebcd96fba6924832abaaf3045aacbb33708f
|
4
|
+
data.tar.gz: 7aa03cd9becf56e2c2f27c59e0757d2e451a8866c212c713e1370bcc69e04c83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd2b68e25392718c159b1d43dfabe0529f00a11230322d14a3c8b987e16b177a976ffacb37f97015c062a22e3f3c195e82f7ebd897b97c374682f909a0fe8805
|
7
|
+
data.tar.gz: 29a54d7e19f8ad4b06c9bf443adf13c0920e5ab55413618a3268fb81253c6e96d16540a733677ab5b9e6340a172d58164d0f01f3f7c2725bfd90cbcbaf04e515
|
@@ -10,7 +10,7 @@ jobs:
|
|
10
10
|
matrix:
|
11
11
|
python-version: [3.8]
|
12
12
|
steps:
|
13
|
-
- uses: actions/checkout@
|
13
|
+
- uses: actions/checkout@v3
|
14
14
|
- name: Set up Python ${{ matrix.python-version }}
|
15
15
|
uses: actions/setup-python@v2
|
16
16
|
with:
|
@@ -26,7 +26,7 @@ jobs:
|
|
26
26
|
name: Check spelling of all files in commit with misspell
|
27
27
|
runs-on: ubuntu-latest
|
28
28
|
steps:
|
29
|
-
- uses: actions/checkout@
|
29
|
+
- uses: actions/checkout@v3
|
30
30
|
- name: Install
|
31
31
|
run: wget -O - -q https://git.io/misspell | sh -s -- -b .
|
32
32
|
- name: Misspell
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
## master (unreleased)
|
4
4
|
|
5
|
+
## 0.19.0 (2022-04-05)
|
6
|
+
|
7
|
+
### New features
|
8
|
+
|
9
|
+
* [#164](https://github.com/rubocop/rubocop-minitest/pull/164): Add new `Minitest/DuplicateTestRun cop. ([@ignacio-chiazzo][])
|
10
|
+
|
5
11
|
## 0.18.0 (2022-03-13)
|
6
12
|
|
7
13
|
### New features
|
@@ -286,3 +292,4 @@
|
|
286
292
|
[@cstyles]: https://github.com/cstyles
|
287
293
|
[@ghiculescu]: https://github.com/ghiculescu
|
288
294
|
[@gi]: https://github.com/gi
|
295
|
+
[@ignacio-chiazzo]: https://github.com/ignacio-chiazzo
|
data/config/default.yml
CHANGED
@@ -28,17 +28,6 @@ Minitest/AssertInDelta:
|
|
28
28
|
Enabled: 'pending'
|
29
29
|
VersionAdded: '0.10'
|
30
30
|
|
31
|
-
Minitest/AssertionInLifecycleHook:
|
32
|
-
Description: 'This cop checks for usage of assertions in lifecycle hooks.'
|
33
|
-
Enabled: 'pending'
|
34
|
-
VersionAdded: '0.10'
|
35
|
-
|
36
|
-
Minitest/AssertMatch:
|
37
|
-
Description: 'This cop enforces the test to use `assert_match` instead of using `assert(matcher.match(object))`.'
|
38
|
-
StyleGuide: 'https://minitest.rubystyle.guide#assert-match'
|
39
|
-
Enabled: true
|
40
|
-
VersionAdded: '0.6'
|
41
|
-
|
42
31
|
Minitest/AssertIncludes:
|
43
32
|
Description: 'This cop enforces the test to use `assert_includes` instead of using `assert(collection.include?(object))`.'
|
44
33
|
StyleGuide: 'https://minitest.rubystyle.guide#assert-includes'
|
@@ -57,6 +46,12 @@ Minitest/AssertKindOf:
|
|
57
46
|
Enabled: 'pending'
|
58
47
|
VersionAdded: '0.10'
|
59
48
|
|
49
|
+
Minitest/AssertMatch:
|
50
|
+
Description: 'This cop enforces the test to use `assert_match` instead of using `assert(matcher.match(object))`.'
|
51
|
+
StyleGuide: 'https://minitest.rubystyle.guide#assert-match'
|
52
|
+
Enabled: true
|
53
|
+
VersionAdded: '0.6'
|
54
|
+
|
60
55
|
Minitest/AssertNil:
|
61
56
|
Description: 'This cop enforces the test to use `assert_nil` instead of using `assert_equal(nil, something)` or `assert(something.nil?)`.'
|
62
57
|
StyleGuide: 'https://minitest.rubystyle.guide#assert-nil'
|
@@ -75,18 +70,18 @@ Minitest/AssertPathExists:
|
|
75
70
|
Enabled: 'pending'
|
76
71
|
VersionAdded: '0.10'
|
77
72
|
|
78
|
-
Minitest/AssertRespondTo:
|
79
|
-
Description: 'This cop enforces the test to use `assert_respond_to(object, :do_something)` over `assert(object.respond_to?(:do_something))`.'
|
80
|
-
StyleGuide: 'https://minitest.rubystyle.guide#assert-responds-to-method'
|
81
|
-
Enabled: true
|
82
|
-
VersionAdded: '0.3'
|
83
|
-
|
84
73
|
Minitest/AssertPredicate:
|
85
74
|
Description: 'This cop enforces the test to use `assert_predicate` instead of using `assert(obj.a_predicate_method?)`.'
|
86
75
|
StyleGuide: 'https://minitest.rubystyle.guide/#assert-predicate'
|
87
76
|
Enabled: pending
|
88
77
|
VersionAdded: '0.18'
|
89
78
|
|
79
|
+
Minitest/AssertRespondTo:
|
80
|
+
Description: 'This cop enforces the test to use `assert_respond_to(object, :do_something)` over `assert(object.respond_to?(:do_something))`.'
|
81
|
+
StyleGuide: 'https://minitest.rubystyle.guide#assert-responds-to-method'
|
82
|
+
Enabled: true
|
83
|
+
VersionAdded: '0.3'
|
84
|
+
|
90
85
|
Minitest/AssertSilent:
|
91
86
|
Description: "This cop enforces the test to use `assert_silent { ... }` instead of using `assert_output('', '') { ... }`."
|
92
87
|
StyleGuide: 'https://github.com/rubocop/minitest-style-guide#assert-silent'
|
@@ -105,6 +100,16 @@ Minitest/AssertWithExpectedArgument:
|
|
105
100
|
Safe: false
|
106
101
|
VersionAdded: '0.11'
|
107
102
|
|
103
|
+
Minitest/AssertionInLifecycleHook:
|
104
|
+
Description: 'This cop checks for usage of assertions in lifecycle hooks.'
|
105
|
+
Enabled: 'pending'
|
106
|
+
VersionAdded: '0.10'
|
107
|
+
|
108
|
+
Minitest/DuplicateTestRun:
|
109
|
+
Description: 'This cop detects duplicate test runs caused by one test class inheriting from another.'
|
110
|
+
Enabled: pending
|
111
|
+
VersionAdded: '0.19'
|
112
|
+
|
108
113
|
Minitest/GlobalExpectations:
|
109
114
|
Description: 'This cop checks for deprecated global expectations.'
|
110
115
|
StyleGuide: 'https://minitest.rubystyle.guide#global-expectations'
|
@@ -170,12 +175,6 @@ Minitest/RefuteIncludes:
|
|
170
175
|
Enabled: true
|
171
176
|
VersionAdded: '0.3'
|
172
177
|
|
173
|
-
Minitest/RefuteMatch:
|
174
|
-
Description: 'This cop enforces the test to use `refute_match` instead of using `refute(matcher.match(object))`.'
|
175
|
-
StyleGuide: 'https://minitest.rubystyle.guide#refute-match'
|
176
|
-
Enabled: true
|
177
|
-
VersionAdded: '0.6'
|
178
|
-
|
179
178
|
Minitest/RefuteInstanceOf:
|
180
179
|
Description: 'This cop enforces the test to use `refute_instance_of(Class, object)` over `refute(object.instance_of?(Class))`.'
|
181
180
|
StyleGuide: 'https://minitest.rubystyle.guide#refute-instance-of'
|
@@ -188,6 +187,12 @@ Minitest/RefuteKindOf:
|
|
188
187
|
Enabled: 'pending'
|
189
188
|
VersionAdded: '0.10'
|
190
189
|
|
190
|
+
Minitest/RefuteMatch:
|
191
|
+
Description: 'This cop enforces the test to use `refute_match` instead of using `refute(matcher.match(object))`.'
|
192
|
+
StyleGuide: 'https://minitest.rubystyle.guide#refute-match'
|
193
|
+
Enabled: true
|
194
|
+
VersionAdded: '0.6'
|
195
|
+
|
191
196
|
Minitest/RefuteNil:
|
192
197
|
Description: 'This cop enforces the test to use `refute_nil` instead of using `refute_equal(nil, something)` or `refute(something.nil?)`.'
|
193
198
|
StyleGuide: 'https://minitest.rubystyle.guide#refute-nil'
|
data/docs/antora.yml
CHANGED
@@ -30,6 +30,7 @@ based on the https://minitest.rubystyle.guide/[Minitest Style Guide].
|
|
30
30
|
* xref:cops_minitest.adoc#minitestasserttruthy[Minitest/AssertTruthy]
|
31
31
|
* xref:cops_minitest.adoc#minitestassertwithexpectedargument[Minitest/AssertWithExpectedArgument]
|
32
32
|
* xref:cops_minitest.adoc#minitestassertioninlifecyclehook[Minitest/AssertionInLifecycleHook]
|
33
|
+
* xref:cops_minitest.adoc#minitestduplicatetestrun[Minitest/DuplicateTestRun]
|
33
34
|
* xref:cops_minitest.adoc#minitestglobalexpectations[Minitest/GlobalExpectations]
|
34
35
|
* xref:cops_minitest.adoc#minitestliteralasactualargument[Minitest/LiteralAsActualArgument]
|
35
36
|
* xref:cops_minitest.adoc#minitestmultipleassertions[Minitest/MultipleAssertions]
|
@@ -544,6 +544,63 @@ class FooTest < Minitest::Test
|
|
544
544
|
end
|
545
545
|
----
|
546
546
|
|
547
|
+
== Minitest/DuplicateTestRun
|
548
|
+
|
549
|
+
|===
|
550
|
+
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
|
551
|
+
|
552
|
+
| Pending
|
553
|
+
| Yes
|
554
|
+
| No
|
555
|
+
| 0.19
|
556
|
+
| -
|
557
|
+
|===
|
558
|
+
|
559
|
+
If a Minitest class inherits from another class,
|
560
|
+
it will also inherit its methods causing Minitest to run the parent's tests methods twice.
|
561
|
+
|
562
|
+
This cop detects when there are two tests classes, one inherits from the other, and both have tests methods.
|
563
|
+
This cop will add an offence to the Child class in such a case.
|
564
|
+
|
565
|
+
=== Examples
|
566
|
+
|
567
|
+
[source,ruby]
|
568
|
+
----
|
569
|
+
# bad
|
570
|
+
class ParentTest < Minitest::Test
|
571
|
+
def test_parent # it will run this test twice.
|
572
|
+
end
|
573
|
+
end
|
574
|
+
|
575
|
+
class ChildTest < ParentTest
|
576
|
+
def test_child
|
577
|
+
end
|
578
|
+
end
|
579
|
+
|
580
|
+
# good
|
581
|
+
class ParentTest < Minitest::Test
|
582
|
+
def test_parent
|
583
|
+
end
|
584
|
+
end
|
585
|
+
|
586
|
+
class ChildTest < Minitest::Test
|
587
|
+
def test_child
|
588
|
+
end
|
589
|
+
end
|
590
|
+
|
591
|
+
# good
|
592
|
+
class ParentTest < Minitest::Test
|
593
|
+
end
|
594
|
+
|
595
|
+
class ChildTest
|
596
|
+
def test_child
|
597
|
+
end
|
598
|
+
|
599
|
+
def test_parent
|
600
|
+
end
|
601
|
+
end
|
602
|
+
----
|
603
|
+
|
547
604
|
== Minitest/GlobalExpectations
|
548
605
|
|
549
606
|
|===
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Minitest
|
6
|
+
# If a Minitest class inherits from another class,
|
7
|
+
# it will also inherit its methods causing Minitest to run the parent's tests methods twice.
|
8
|
+
#
|
9
|
+
# This cop detects when there are two tests classes, one inherits from the other, and both have tests methods.
|
10
|
+
# This cop will add an offence to the Child class in such a case.
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# # bad
|
14
|
+
# class ParentTest < Minitest::Test
|
15
|
+
# def test_parent # it will run this test twice.
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# class ChildTest < ParentTest
|
20
|
+
# def test_child
|
21
|
+
# end
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
#
|
25
|
+
# # good
|
26
|
+
# class ParentTest < Minitest::Test
|
27
|
+
# def test_parent
|
28
|
+
# end
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# class ChildTest < Minitest::Test
|
32
|
+
# def test_child
|
33
|
+
# end
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# # good
|
37
|
+
# class ParentTest < Minitest::Test
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
# class ChildTest
|
41
|
+
# def test_child
|
42
|
+
# end
|
43
|
+
#
|
44
|
+
# def test_parent
|
45
|
+
# end
|
46
|
+
# end
|
47
|
+
#
|
48
|
+
class DuplicateTestRun < Base
|
49
|
+
include MinitestExplorationHelpers
|
50
|
+
|
51
|
+
MSG = "Subclasses with test methods causes the parent' tests to run them twice."
|
52
|
+
|
53
|
+
def on_class(class_node)
|
54
|
+
return unless test_class?(class_node)
|
55
|
+
return unless test_methods?(class_node)
|
56
|
+
return unless parent_class_has_test_methods?(class_node)
|
57
|
+
|
58
|
+
message = format(MSG)
|
59
|
+
add_offense(class_node, message: message)
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def parent_class_has_test_methods?(class_node)
|
65
|
+
parent_class = class_node.parent_class
|
66
|
+
parent_class_node = class_node.parent.each_child_node(:class).detect do |klass|
|
67
|
+
klass.identifier == parent_class
|
68
|
+
end
|
69
|
+
|
70
|
+
return false unless parent_class_node
|
71
|
+
|
72
|
+
test_methods?(parent_class_node)
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_methods?(class_node)
|
76
|
+
test_cases(class_node).size.positive?
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -23,6 +23,7 @@ require_relative 'minitest/assert_path_exists'
|
|
23
23
|
require_relative 'minitest/assert_respond_to'
|
24
24
|
require_relative 'minitest/assert_silent'
|
25
25
|
require_relative 'minitest/assert_truthy'
|
26
|
+
require_relative 'minitest/duplicate_test_run'
|
26
27
|
require_relative 'minitest/global_expectations'
|
27
28
|
require_relative 'minitest/literal_as_actual_argument'
|
28
29
|
require_relative 'minitest/multiple_assertions'
|
data/relnotes/v0.19.0.md
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-minitest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.19.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bozhidar Batsov
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2022-
|
13
|
+
date: 2022-04-05 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rubocop
|
@@ -108,6 +108,7 @@ files:
|
|
108
108
|
- lib/rubocop/cop/minitest/assert_truthy.rb
|
109
109
|
- lib/rubocop/cop/minitest/assert_with_expected_argument.rb
|
110
110
|
- lib/rubocop/cop/minitest/assertion_in_lifecycle_hook.rb
|
111
|
+
- lib/rubocop/cop/minitest/duplicate_test_run.rb
|
111
112
|
- lib/rubocop/cop/minitest/global_expectations.rb
|
112
113
|
- lib/rubocop/cop/minitest/literal_as_actual_argument.rb
|
113
114
|
- lib/rubocop/cop/minitest/multiple_assertions.rb
|
@@ -160,6 +161,7 @@ files:
|
|
160
161
|
- relnotes/v0.17.1.md
|
161
162
|
- relnotes/v0.17.2.md
|
162
163
|
- relnotes/v0.18.0.md
|
164
|
+
- relnotes/v0.19.0.md
|
163
165
|
- relnotes/v0.2.0.md
|
164
166
|
- relnotes/v0.2.1.md
|
165
167
|
- relnotes/v0.3.0.md
|
@@ -186,7 +188,7 @@ metadata:
|
|
186
188
|
homepage_uri: https://docs.rubocop.org/rubocop-minitest/
|
187
189
|
changelog_uri: https://github.com/rubocop/rubocop-minitest/blob/master/CHANGELOG.md
|
188
190
|
source_code_uri: https://github.com/rubocop/rubocop-minitest
|
189
|
-
documentation_uri: https://docs.rubocop.org/rubocop-minitest/0.
|
191
|
+
documentation_uri: https://docs.rubocop.org/rubocop-minitest/0.19
|
190
192
|
bug_tracker_uri: https://github.com/rubocop/rubocop-minitest/issues
|
191
193
|
rubygems_mfa_required: 'true'
|
192
194
|
post_install_message:
|