rubocop-minitest 0.8.0 → 0.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.circleci/config.yml +15 -3
- data/.rubocop.yml +3 -1
- data/.rubocop_todo.yml +7 -13
- data/CHANGELOG.md +52 -0
- data/Gemfile +1 -1
- data/README.md +18 -2
- data/Rakefile +29 -0
- data/config/default.yml +96 -16
- data/docs/antora.yml +7 -0
- data/docs/modules/ROOT/nav.adoc +6 -0
- data/docs/modules/ROOT/pages/cops.adoc +48 -0
- data/docs/modules/ROOT/pages/cops_minitest.adoc +1014 -0
- data/docs/modules/ROOT/pages/index.adoc +5 -0
- data/docs/modules/ROOT/pages/installation.adoc +15 -0
- data/docs/modules/ROOT/pages/usage.adoc +32 -0
- data/{manual → legacy-docs}/cops.md +0 -0
- data/{manual → legacy-docs}/cops_minitest.md +0 -0
- data/{manual → legacy-docs}/index.md +0 -0
- data/{manual → legacy-docs}/installation.md +0 -0
- data/{manual → legacy-docs}/usage.md +0 -0
- data/lib/rubocop/cop/generator.rb +56 -0
- data/lib/rubocop/cop/minitest/assert_empty_literal.rb +15 -0
- data/lib/rubocop/cop/minitest/assert_in_delta.rb +27 -0
- data/lib/rubocop/cop/minitest/assert_kind_of.rb +25 -0
- data/lib/rubocop/cop/minitest/assert_output.rb +49 -0
- data/lib/rubocop/cop/minitest/assert_path_exists.rb +58 -0
- data/lib/rubocop/cop/minitest/assert_silent.rb +45 -0
- data/lib/rubocop/cop/minitest/assertion_in_lifecycle_hook.rb +43 -0
- data/lib/rubocop/cop/minitest/global_expectations.rb +27 -13
- data/lib/rubocop/cop/minitest/literal_as_actual_argument.rb +52 -0
- data/lib/rubocop/cop/minitest/multiple_assertions.rb +63 -0
- data/lib/rubocop/cop/minitest/refute_equal.rb +1 -1
- data/lib/rubocop/cop/minitest/refute_in_delta.rb +27 -0
- data/lib/rubocop/cop/minitest/refute_kind_of.rb +25 -0
- data/lib/rubocop/cop/minitest/refute_path_exists.rb +58 -0
- data/lib/rubocop/cop/minitest/test_method_name.rb +70 -0
- data/lib/rubocop/cop/minitest/unspecified_exception.rb +36 -0
- data/lib/rubocop/cop/minitest_cops.rb +15 -0
- data/lib/rubocop/cop/mixin/argument_range_helper.rb +10 -0
- data/lib/rubocop/cop/mixin/in_delta_mixin.rb +50 -0
- data/lib/rubocop/cop/mixin/minitest_cop_rule.rb +2 -4
- data/lib/rubocop/cop/mixin/minitest_exploration_helpers.rb +84 -0
- data/lib/rubocop/minitest/version.rb +8 -1
- data/mkdocs.yml +2 -2
- data/relnotes/v0.10.0.md +21 -0
- data/relnotes/v0.10.1.md +5 -0
- data/relnotes/v0.10.2.md +5 -0
- data/relnotes/v0.8.1.md +5 -0
- data/relnotes/v0.9.0.md +10 -0
- data/rubocop-minitest.gemspec +5 -5
- data/tasks/cops_documentation.rake +15 -264
- data/tasks/cut_release.rake +16 -0
- metadata +52 -18
@@ -0,0 +1,48 @@
|
|
1
|
+
= Cops
|
2
|
+
|
3
|
+
In RuboCop lingo the various checks performed on the code are called cops.
|
4
|
+
Each cop is responsible for detecting one particular offense.
|
5
|
+
RuboCop Minitest has only one Minitest department.
|
6
|
+
|
7
|
+
== Minitest
|
8
|
+
|
9
|
+
Minitest cops check for Minitest best practices and coding conventions. Many of the them are
|
10
|
+
based on the https://minitest.rubystyle.guide/[Minitest Style Guide].
|
11
|
+
|
12
|
+
// START_COP_LIST
|
13
|
+
|
14
|
+
=== Department xref:cops_minitest.adoc[Minitest]
|
15
|
+
|
16
|
+
* xref:cops_minitest.adoc#minitestassertempty[Minitest/AssertEmpty]
|
17
|
+
* xref:cops_minitest.adoc#minitestassertemptyliteral[Minitest/AssertEmptyLiteral]
|
18
|
+
* xref:cops_minitest.adoc#minitestassertequal[Minitest/AssertEqual]
|
19
|
+
* xref:cops_minitest.adoc#minitestassertindelta[Minitest/AssertInDelta]
|
20
|
+
* xref:cops_minitest.adoc#minitestassertincludes[Minitest/AssertIncludes]
|
21
|
+
* xref:cops_minitest.adoc#minitestassertinstanceof[Minitest/AssertInstanceOf]
|
22
|
+
* xref:cops_minitest.adoc#minitestassertkindof[Minitest/AssertKindOf]
|
23
|
+
* xref:cops_minitest.adoc#minitestassertmatch[Minitest/AssertMatch]
|
24
|
+
* xref:cops_minitest.adoc#minitestassertnil[Minitest/AssertNil]
|
25
|
+
* xref:cops_minitest.adoc#minitestassertoutput[Minitest/AssertOutput]
|
26
|
+
* xref:cops_minitest.adoc#minitestassertpathexists[Minitest/AssertPathExists]
|
27
|
+
* xref:cops_minitest.adoc#minitestassertrespondto[Minitest/AssertRespondTo]
|
28
|
+
* xref:cops_minitest.adoc#minitestassertsilent[Minitest/AssertSilent]
|
29
|
+
* xref:cops_minitest.adoc#minitestasserttruthy[Minitest/AssertTruthy]
|
30
|
+
* xref:cops_minitest.adoc#minitestassertioninlifecyclehook[Minitest/AssertionInLifecycleHook]
|
31
|
+
* xref:cops_minitest.adoc#minitestglobalexpectations[Minitest/GlobalExpectations]
|
32
|
+
* xref:cops_minitest.adoc#minitestliteralasactualargument[Minitest/LiteralAsActualArgument]
|
33
|
+
* xref:cops_minitest.adoc#minitestmultipleassertions[Minitest/MultipleAssertions]
|
34
|
+
* xref:cops_minitest.adoc#minitestrefuteempty[Minitest/RefuteEmpty]
|
35
|
+
* xref:cops_minitest.adoc#minitestrefuteequal[Minitest/RefuteEqual]
|
36
|
+
* xref:cops_minitest.adoc#minitestrefutefalse[Minitest/RefuteFalse]
|
37
|
+
* xref:cops_minitest.adoc#minitestrefuteindelta[Minitest/RefuteInDelta]
|
38
|
+
* xref:cops_minitest.adoc#minitestrefuteincludes[Minitest/RefuteIncludes]
|
39
|
+
* xref:cops_minitest.adoc#minitestrefuteinstanceof[Minitest/RefuteInstanceOf]
|
40
|
+
* xref:cops_minitest.adoc#minitestrefutekindof[Minitest/RefuteKindOf]
|
41
|
+
* xref:cops_minitest.adoc#minitestrefutematch[Minitest/RefuteMatch]
|
42
|
+
* xref:cops_minitest.adoc#minitestrefutenil[Minitest/RefuteNil]
|
43
|
+
* xref:cops_minitest.adoc#minitestrefutepathexists[Minitest/RefutePathExists]
|
44
|
+
* xref:cops_minitest.adoc#minitestrefuterespondto[Minitest/RefuteRespondTo]
|
45
|
+
* xref:cops_minitest.adoc#minitesttestmethodname[Minitest/TestMethodName]
|
46
|
+
* xref:cops_minitest.adoc#minitestunspecifiedexception[Minitest/UnspecifiedException]
|
47
|
+
|
48
|
+
// END_COP_LIST
|
@@ -0,0 +1,1014 @@
|
|
1
|
+
= Minitest
|
2
|
+
|
3
|
+
== Minitest/AssertEmpty
|
4
|
+
|
5
|
+
|===
|
6
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
7
|
+
|
8
|
+
| Enabled
|
9
|
+
| Yes
|
10
|
+
| Yes
|
11
|
+
| 0.2
|
12
|
+
| -
|
13
|
+
|===
|
14
|
+
|
15
|
+
This cop enforces the test to use `assert_empty`
|
16
|
+
instead of using `assert(object.empty?)`.
|
17
|
+
|
18
|
+
=== Examples
|
19
|
+
|
20
|
+
[source,ruby]
|
21
|
+
----
|
22
|
+
# bad
|
23
|
+
assert(object.empty?)
|
24
|
+
assert(object.empty?, 'message')
|
25
|
+
|
26
|
+
# good
|
27
|
+
assert_empty(object)
|
28
|
+
assert_empty(object, 'message')
|
29
|
+
----
|
30
|
+
|
31
|
+
=== References
|
32
|
+
|
33
|
+
* https://minitest.rubystyle.guide#assert-empty
|
34
|
+
|
35
|
+
== Minitest/AssertEmptyLiteral
|
36
|
+
|
37
|
+
|===
|
38
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
39
|
+
|
40
|
+
| Enabled
|
41
|
+
| Yes
|
42
|
+
| Yes (Unsafe)
|
43
|
+
| 0.5
|
44
|
+
| 0.10
|
45
|
+
|===
|
46
|
+
|
47
|
+
This cop enforces the test to use `assert_empty`
|
48
|
+
instead of using `assert([], object)`.
|
49
|
+
|
50
|
+
=== Examples
|
51
|
+
|
52
|
+
[source,ruby]
|
53
|
+
----
|
54
|
+
# bad
|
55
|
+
assert([], object)
|
56
|
+
assert({}, object)
|
57
|
+
|
58
|
+
# good
|
59
|
+
assert_empty(object)
|
60
|
+
----
|
61
|
+
|
62
|
+
== Minitest/AssertEqual
|
63
|
+
|
64
|
+
|===
|
65
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
66
|
+
|
67
|
+
| Enabled
|
68
|
+
| Yes
|
69
|
+
| Yes
|
70
|
+
| 0.4
|
71
|
+
| -
|
72
|
+
|===
|
73
|
+
|
74
|
+
This cop enforces the use of `assert_equal(expected, actual)`
|
75
|
+
over `assert(expected == actual)`.
|
76
|
+
|
77
|
+
=== Examples
|
78
|
+
|
79
|
+
[source,ruby]
|
80
|
+
----
|
81
|
+
# bad
|
82
|
+
assert("rubocop-minitest" == actual)
|
83
|
+
|
84
|
+
# good
|
85
|
+
assert_equal("rubocop-minitest", actual)
|
86
|
+
----
|
87
|
+
|
88
|
+
=== References
|
89
|
+
|
90
|
+
* https://minitest.rubystyle.guide#assert-equal-arguments-order
|
91
|
+
|
92
|
+
== Minitest/AssertInDelta
|
93
|
+
|
94
|
+
|===
|
95
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
96
|
+
|
97
|
+
| Pending
|
98
|
+
| Yes
|
99
|
+
| Yes
|
100
|
+
| 0.10
|
101
|
+
| -
|
102
|
+
|===
|
103
|
+
|
104
|
+
This cop enforces the test to use `assert_in_delta`
|
105
|
+
instead of using `assert_equal` to compare floats.
|
106
|
+
|
107
|
+
=== Examples
|
108
|
+
|
109
|
+
[source,ruby]
|
110
|
+
----
|
111
|
+
# bad
|
112
|
+
assert_equal(0.2, actual)
|
113
|
+
assert_equal(0.2, actual, 'message')
|
114
|
+
|
115
|
+
# good
|
116
|
+
assert_in_delta(0.2, actual)
|
117
|
+
assert_in_delta(0.2, actual, 0.001, 'message')
|
118
|
+
----
|
119
|
+
|
120
|
+
=== References
|
121
|
+
|
122
|
+
* https://minitest.rubystyle.guide/#assert-in-delta
|
123
|
+
|
124
|
+
== Minitest/AssertIncludes
|
125
|
+
|
126
|
+
|===
|
127
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
128
|
+
|
129
|
+
| Enabled
|
130
|
+
| Yes
|
131
|
+
| Yes
|
132
|
+
| 0.2
|
133
|
+
| -
|
134
|
+
|===
|
135
|
+
|
136
|
+
This cop enforces the test to use `assert_includes`
|
137
|
+
instead of using `assert(collection.include?(object))`.
|
138
|
+
|
139
|
+
=== Examples
|
140
|
+
|
141
|
+
[source,ruby]
|
142
|
+
----
|
143
|
+
# bad
|
144
|
+
assert(collection.include?(object))
|
145
|
+
assert(collection.include?(object), 'message')
|
146
|
+
|
147
|
+
# good
|
148
|
+
assert_includes(collection, object)
|
149
|
+
assert_includes(collection, object, 'message')
|
150
|
+
----
|
151
|
+
|
152
|
+
=== References
|
153
|
+
|
154
|
+
* https://minitest.rubystyle.guide#assert-includes
|
155
|
+
|
156
|
+
== Minitest/AssertInstanceOf
|
157
|
+
|
158
|
+
|===
|
159
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
160
|
+
|
161
|
+
| Enabled
|
162
|
+
| Yes
|
163
|
+
| Yes
|
164
|
+
| 0.4
|
165
|
+
| -
|
166
|
+
|===
|
167
|
+
|
168
|
+
This cop enforces the test to use `assert_instance_of(Class, object)`
|
169
|
+
over `assert(object.instance_of?(Class))`.
|
170
|
+
|
171
|
+
=== Examples
|
172
|
+
|
173
|
+
[source,ruby]
|
174
|
+
----
|
175
|
+
# bad
|
176
|
+
assert(object.instance_of?(Class))
|
177
|
+
assert(object.instance_of?(Class), 'message')
|
178
|
+
|
179
|
+
# good
|
180
|
+
assert_instance_of(Class, object)
|
181
|
+
assert_instance_of(Class, object, 'message')
|
182
|
+
----
|
183
|
+
|
184
|
+
=== References
|
185
|
+
|
186
|
+
* https://minitest.rubystyle.guide#assert-instance-of
|
187
|
+
|
188
|
+
== Minitest/AssertKindOf
|
189
|
+
|
190
|
+
|===
|
191
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
192
|
+
|
193
|
+
| Pending
|
194
|
+
| Yes
|
195
|
+
| Yes
|
196
|
+
| 0.10
|
197
|
+
| -
|
198
|
+
|===
|
199
|
+
|
200
|
+
This cop enforces the test to use `assert_kind_of(Class, object)`
|
201
|
+
over `assert(object.kind_of?(Class))`.
|
202
|
+
|
203
|
+
=== Examples
|
204
|
+
|
205
|
+
[source,ruby]
|
206
|
+
----
|
207
|
+
# bad
|
208
|
+
assert(object.kind_of?(Class))
|
209
|
+
assert(object.kind_of?(Class), 'message')
|
210
|
+
|
211
|
+
# good
|
212
|
+
assert_kind_of(Class, object)
|
213
|
+
assert_kind_of(Class, object, 'message')
|
214
|
+
----
|
215
|
+
|
216
|
+
=== References
|
217
|
+
|
218
|
+
* https://github.com/rubocop-hq/minitest-style-guide#assert-kind-of
|
219
|
+
|
220
|
+
== Minitest/AssertMatch
|
221
|
+
|
222
|
+
|===
|
223
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
224
|
+
|
225
|
+
| Enabled
|
226
|
+
| Yes
|
227
|
+
| Yes
|
228
|
+
| 0.6
|
229
|
+
| -
|
230
|
+
|===
|
231
|
+
|
232
|
+
This cop enforces the test to use `assert_match`
|
233
|
+
instead of using `assert(matcher.match(string))`.
|
234
|
+
|
235
|
+
=== Examples
|
236
|
+
|
237
|
+
[source,ruby]
|
238
|
+
----
|
239
|
+
# bad
|
240
|
+
assert(matcher.match(string))
|
241
|
+
assert(matcher.match(string), 'message')
|
242
|
+
|
243
|
+
# good
|
244
|
+
assert_match(regex, string)
|
245
|
+
assert_match(matcher, string, 'message')
|
246
|
+
----
|
247
|
+
|
248
|
+
=== References
|
249
|
+
|
250
|
+
* https://minitest.rubystyle.guide#assert-match
|
251
|
+
|
252
|
+
== Minitest/AssertNil
|
253
|
+
|
254
|
+
|===
|
255
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
256
|
+
|
257
|
+
| Enabled
|
258
|
+
| Yes
|
259
|
+
| Yes
|
260
|
+
| 0.1
|
261
|
+
| -
|
262
|
+
|===
|
263
|
+
|
264
|
+
This cop enforces the test to use `assert_nil`
|
265
|
+
instead of using `assert_equal(nil, something)`.
|
266
|
+
|
267
|
+
=== Examples
|
268
|
+
|
269
|
+
[source,ruby]
|
270
|
+
----
|
271
|
+
# bad
|
272
|
+
assert_equal(nil, actual)
|
273
|
+
assert_equal(nil, actual, 'message')
|
274
|
+
|
275
|
+
# good
|
276
|
+
assert_nil(actual)
|
277
|
+
assert_nil(actual, 'message')
|
278
|
+
----
|
279
|
+
|
280
|
+
=== References
|
281
|
+
|
282
|
+
* https://minitest.rubystyle.guide#assert-nil
|
283
|
+
|
284
|
+
== Minitest/AssertOutput
|
285
|
+
|
286
|
+
|===
|
287
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
288
|
+
|
289
|
+
| Pending
|
290
|
+
| Yes
|
291
|
+
| No
|
292
|
+
| 0.10
|
293
|
+
| -
|
294
|
+
|===
|
295
|
+
|
296
|
+
This cop checks for opportunities to use `assert_output`.
|
297
|
+
|
298
|
+
=== Examples
|
299
|
+
|
300
|
+
[source,ruby]
|
301
|
+
----
|
302
|
+
# bad
|
303
|
+
$stdout = StringIO.new
|
304
|
+
puts object.method
|
305
|
+
$stdout.rewind
|
306
|
+
assert_match expected, $stdout.read
|
307
|
+
|
308
|
+
# good
|
309
|
+
assert_output(expected) { puts object.method }
|
310
|
+
----
|
311
|
+
|
312
|
+
=== References
|
313
|
+
|
314
|
+
* https://minitest.rubystyle.guide/#assert-output
|
315
|
+
|
316
|
+
== Minitest/AssertPathExists
|
317
|
+
|
318
|
+
|===
|
319
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
320
|
+
|
321
|
+
| Pending
|
322
|
+
| Yes
|
323
|
+
| Yes
|
324
|
+
| 0.10
|
325
|
+
| -
|
326
|
+
|===
|
327
|
+
|
328
|
+
This cop enforces the test to use `assert_path_exists`
|
329
|
+
instead of using `assert(File.exist?(path))`.
|
330
|
+
|
331
|
+
=== Examples
|
332
|
+
|
333
|
+
[source,ruby]
|
334
|
+
----
|
335
|
+
# bad
|
336
|
+
assert(File.exist?(path))
|
337
|
+
assert(File.exist?(path), 'message')
|
338
|
+
|
339
|
+
# good
|
340
|
+
assert_path_exists(path)
|
341
|
+
assert_path_exists(path, 'message')
|
342
|
+
----
|
343
|
+
|
344
|
+
=== References
|
345
|
+
|
346
|
+
* https://minitest.rubystyle.guide/#assert-path-exists
|
347
|
+
|
348
|
+
== Minitest/AssertRespondTo
|
349
|
+
|
350
|
+
|===
|
351
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
352
|
+
|
353
|
+
| Enabled
|
354
|
+
| Yes
|
355
|
+
| Yes
|
356
|
+
| 0.3
|
357
|
+
| -
|
358
|
+
|===
|
359
|
+
|
360
|
+
This cop enforces the use of `assert_respond_to(object, :do_something)`
|
361
|
+
over `assert(object.respond_to?(:do_something))`.
|
362
|
+
|
363
|
+
=== Examples
|
364
|
+
|
365
|
+
[source,ruby]
|
366
|
+
----
|
367
|
+
# bad
|
368
|
+
assert(object.respond_to?(:do_something))
|
369
|
+
assert(object.respond_to?(:do_something), 'message')
|
370
|
+
assert(respond_to?(:do_something))
|
371
|
+
|
372
|
+
# good
|
373
|
+
assert_respond_to(object, :do_something)
|
374
|
+
assert_respond_to(object, :do_something, 'message')
|
375
|
+
assert_respond_to(self, :do_something)
|
376
|
+
----
|
377
|
+
|
378
|
+
=== References
|
379
|
+
|
380
|
+
* https://minitest.rubystyle.guide#assert-responds-to-method
|
381
|
+
|
382
|
+
== Minitest/AssertSilent
|
383
|
+
|
384
|
+
|===
|
385
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
386
|
+
|
387
|
+
| Pending
|
388
|
+
| Yes
|
389
|
+
| Yes
|
390
|
+
| 0.10
|
391
|
+
| -
|
392
|
+
|===
|
393
|
+
|
394
|
+
This cop enforces the test to use `assert_silent { ... }`
|
395
|
+
instead of using `assert_output('', '') { ... }`.
|
396
|
+
|
397
|
+
=== Examples
|
398
|
+
|
399
|
+
[source,ruby]
|
400
|
+
----
|
401
|
+
# bad
|
402
|
+
assert_output('', '') { puts object.do_something }
|
403
|
+
|
404
|
+
# good
|
405
|
+
assert_silent { puts object.do_something }
|
406
|
+
----
|
407
|
+
|
408
|
+
=== References
|
409
|
+
|
410
|
+
* https://github.com/rubocop-hq/minitest-style-guide#assert-silent
|
411
|
+
|
412
|
+
== Minitest/AssertTruthy
|
413
|
+
|
414
|
+
|===
|
415
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
416
|
+
|
417
|
+
| Enabled
|
418
|
+
| Yes
|
419
|
+
| Yes
|
420
|
+
| 0.2
|
421
|
+
| -
|
422
|
+
|===
|
423
|
+
|
424
|
+
This cop enforces the test to use `assert(actual)`
|
425
|
+
instead of using `assert_equal(true, actual)`.
|
426
|
+
|
427
|
+
=== Examples
|
428
|
+
|
429
|
+
[source,ruby]
|
430
|
+
----
|
431
|
+
# bad
|
432
|
+
assert_equal(true, actual)
|
433
|
+
assert_equal(true, actual, 'message')
|
434
|
+
|
435
|
+
# good
|
436
|
+
assert(actual)
|
437
|
+
assert(actual, 'message')
|
438
|
+
----
|
439
|
+
|
440
|
+
=== References
|
441
|
+
|
442
|
+
* https://minitest.rubystyle.guide#assert-truthy
|
443
|
+
|
444
|
+
== Minitest/AssertionInLifecycleHook
|
445
|
+
|
446
|
+
|===
|
447
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
448
|
+
|
449
|
+
| Pending
|
450
|
+
| Yes
|
451
|
+
| No
|
452
|
+
| 0.10
|
453
|
+
| -
|
454
|
+
|===
|
455
|
+
|
456
|
+
This cop checks for usage of assertions in lifecycle hooks.
|
457
|
+
|
458
|
+
=== Examples
|
459
|
+
|
460
|
+
[source,ruby]
|
461
|
+
----
|
462
|
+
# bad
|
463
|
+
class FooTest < Minitest::Test
|
464
|
+
def setup
|
465
|
+
assert_equal(foo, bar)
|
466
|
+
end
|
467
|
+
end
|
468
|
+
|
469
|
+
# good
|
470
|
+
class FooTest < Minitest::Test
|
471
|
+
def test_something
|
472
|
+
assert_equal(foo, bar)
|
473
|
+
end
|
474
|
+
end
|
475
|
+
----
|
476
|
+
|
477
|
+
== Minitest/GlobalExpectations
|
478
|
+
|
479
|
+
|===
|
480
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
481
|
+
|
482
|
+
| Enabled
|
483
|
+
| Yes
|
484
|
+
| Yes
|
485
|
+
| 0.7
|
486
|
+
| -
|
487
|
+
|===
|
488
|
+
|
489
|
+
This cop checks for deprecated global expectations
|
490
|
+
and autocorrects them to use expect format.
|
491
|
+
|
492
|
+
=== Examples
|
493
|
+
|
494
|
+
[source,ruby]
|
495
|
+
----
|
496
|
+
# bad
|
497
|
+
musts.must_equal expected_musts
|
498
|
+
wonts.wont_match expected_wonts
|
499
|
+
musts.must_raise TypeError
|
500
|
+
|
501
|
+
# good
|
502
|
+
_(musts).must_equal expected_musts
|
503
|
+
_(wonts).wont_match expected_wonts
|
504
|
+
_ { musts }.must_raise TypeError
|
505
|
+
----
|
506
|
+
|
507
|
+
=== References
|
508
|
+
|
509
|
+
* https://minitest.rubystyle.guide#global-expectations
|
510
|
+
|
511
|
+
== Minitest/LiteralAsActualArgument
|
512
|
+
|
513
|
+
|===
|
514
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
515
|
+
|
516
|
+
| Pending
|
517
|
+
| Yes
|
518
|
+
| Yes
|
519
|
+
| 0.10
|
520
|
+
| -
|
521
|
+
|===
|
522
|
+
|
523
|
+
This cop enforces correct order of expected and
|
524
|
+
actual arguments for `assert_equal`.
|
525
|
+
|
526
|
+
=== Examples
|
527
|
+
|
528
|
+
[source,ruby]
|
529
|
+
----
|
530
|
+
# bad
|
531
|
+
assert_equal foo, 2
|
532
|
+
assert_equal foo, [1, 2]
|
533
|
+
assert_equal foo, [1, 2], 'message'
|
534
|
+
|
535
|
+
# good
|
536
|
+
assert_equal 2, foo
|
537
|
+
assert_equal [1, 2], foo
|
538
|
+
assert_equal [1, 2], foo, 'message'
|
539
|
+
----
|
540
|
+
|
541
|
+
=== References
|
542
|
+
|
543
|
+
* https://minitest.rubystyle.guide/#assert-equal-arguments-order
|
544
|
+
|
545
|
+
== Minitest/MultipleAssertions
|
546
|
+
|
547
|
+
|===
|
548
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
549
|
+
|
550
|
+
| Pending
|
551
|
+
| Yes
|
552
|
+
| No
|
553
|
+
| 0.10
|
554
|
+
| -
|
555
|
+
|===
|
556
|
+
|
557
|
+
This cop checks if test cases contain too many assertion calls.
|
558
|
+
The maximum allowed assertion calls is configurable.
|
559
|
+
|
560
|
+
=== Examples
|
561
|
+
|
562
|
+
==== Max: 1
|
563
|
+
|
564
|
+
[source,ruby]
|
565
|
+
----
|
566
|
+
# bad
|
567
|
+
class FooTest < Minitest::Test
|
568
|
+
def test_asserts_twice
|
569
|
+
assert_equal(42, do_something)
|
570
|
+
assert_empty(array)
|
571
|
+
end
|
572
|
+
end
|
573
|
+
|
574
|
+
# good
|
575
|
+
class FooTest < Minitest::Test
|
576
|
+
def test_asserts_once
|
577
|
+
assert_equal(42, do_something)
|
578
|
+
end
|
579
|
+
|
580
|
+
def test_another_asserts_once
|
581
|
+
assert_empty(array)
|
582
|
+
end
|
583
|
+
end
|
584
|
+
----
|
585
|
+
|
586
|
+
=== Configurable attributes
|
587
|
+
|
588
|
+
|===
|
589
|
+
| Name | Default value | Configurable values
|
590
|
+
|
591
|
+
| Max
|
592
|
+
| `3`
|
593
|
+
| Integer
|
594
|
+
|===
|
595
|
+
|
596
|
+
== Minitest/RefuteEmpty
|
597
|
+
|
598
|
+
|===
|
599
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
600
|
+
|
601
|
+
| Enabled
|
602
|
+
| Yes
|
603
|
+
| Yes
|
604
|
+
| 0.3
|
605
|
+
| -
|
606
|
+
|===
|
607
|
+
|
608
|
+
This cop enforces to use `refute_empty` instead of
|
609
|
+
using `refute(object.empty?)`.
|
610
|
+
|
611
|
+
=== Examples
|
612
|
+
|
613
|
+
[source,ruby]
|
614
|
+
----
|
615
|
+
# bad
|
616
|
+
refute(object.empty?)
|
617
|
+
refute(object.empty?, 'message')
|
618
|
+
|
619
|
+
# good
|
620
|
+
refute_empty(object)
|
621
|
+
refute_empty(object, 'message')
|
622
|
+
----
|
623
|
+
|
624
|
+
=== References
|
625
|
+
|
626
|
+
* https://minitest.rubystyle.guide#refute-empty
|
627
|
+
|
628
|
+
== Minitest/RefuteEqual
|
629
|
+
|
630
|
+
|===
|
631
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
632
|
+
|
633
|
+
| Enabled
|
634
|
+
| Yes
|
635
|
+
| Yes
|
636
|
+
| 0.3
|
637
|
+
| -
|
638
|
+
|===
|
639
|
+
|
640
|
+
This cop enforces the use of `refute_equal(expected, object)`
|
641
|
+
over `assert(expected != actual)` or `assert(! expected == actual)`.
|
642
|
+
|
643
|
+
=== Examples
|
644
|
+
|
645
|
+
[source,ruby]
|
646
|
+
----
|
647
|
+
# bad
|
648
|
+
assert("rubocop-minitest" != actual)
|
649
|
+
assert(! "rubocop-minitest" == actual)
|
650
|
+
|
651
|
+
# good
|
652
|
+
refute_equal("rubocop-minitest", actual)
|
653
|
+
----
|
654
|
+
|
655
|
+
=== References
|
656
|
+
|
657
|
+
* https://minitest.rubystyle.guide#refute-equal
|
658
|
+
|
659
|
+
== Minitest/RefuteFalse
|
660
|
+
|
661
|
+
|===
|
662
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
663
|
+
|
664
|
+
| Enabled
|
665
|
+
| Yes
|
666
|
+
| Yes
|
667
|
+
| 0.3
|
668
|
+
| -
|
669
|
+
|===
|
670
|
+
|
671
|
+
This cop enforces the use of `refute(object)`
|
672
|
+
over `assert_equal(false, object)`.
|
673
|
+
|
674
|
+
=== Examples
|
675
|
+
|
676
|
+
[source,ruby]
|
677
|
+
----
|
678
|
+
# bad
|
679
|
+
assert_equal(false, actual)
|
680
|
+
assert_equal(false, actual, 'message')
|
681
|
+
|
682
|
+
assert(!test)
|
683
|
+
assert(!test, 'message')
|
684
|
+
|
685
|
+
# good
|
686
|
+
refute(actual)
|
687
|
+
refute(actual, 'message')
|
688
|
+
----
|
689
|
+
|
690
|
+
=== References
|
691
|
+
|
692
|
+
* https://minitest.rubystyle.guide#refute-false
|
693
|
+
|
694
|
+
== Minitest/RefuteInDelta
|
695
|
+
|
696
|
+
|===
|
697
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
698
|
+
|
699
|
+
| Pending
|
700
|
+
| Yes
|
701
|
+
| Yes
|
702
|
+
| 0.10
|
703
|
+
| -
|
704
|
+
|===
|
705
|
+
|
706
|
+
This cop enforces the test to use `refute_in_delta`
|
707
|
+
instead of using `refute_equal` to compare floats.
|
708
|
+
|
709
|
+
=== Examples
|
710
|
+
|
711
|
+
[source,ruby]
|
712
|
+
----
|
713
|
+
# bad
|
714
|
+
refute_equal(0.2, actual)
|
715
|
+
refute_equal(0.2, actual, 'message')
|
716
|
+
|
717
|
+
# good
|
718
|
+
refute_in_delta(0.2, actual)
|
719
|
+
refute_in_delta(0.2, actual, 0.001, 'message')
|
720
|
+
----
|
721
|
+
|
722
|
+
=== References
|
723
|
+
|
724
|
+
* https://minitest.rubystyle.guide/#refute-in-delta
|
725
|
+
|
726
|
+
== Minitest/RefuteIncludes
|
727
|
+
|
728
|
+
|===
|
729
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
730
|
+
|
731
|
+
| Enabled
|
732
|
+
| Yes
|
733
|
+
| Yes
|
734
|
+
| 0.3
|
735
|
+
| -
|
736
|
+
|===
|
737
|
+
|
738
|
+
This cop enforces the test to use `refute_includes`
|
739
|
+
instead of using `refute(collection.include?(object))`.
|
740
|
+
|
741
|
+
=== Examples
|
742
|
+
|
743
|
+
[source,ruby]
|
744
|
+
----
|
745
|
+
# bad
|
746
|
+
refute(collection.include?(object))
|
747
|
+
refute(collection.include?(object), 'message')
|
748
|
+
|
749
|
+
# good
|
750
|
+
refute_includes(collection, object)
|
751
|
+
refute_includes(collection, object, 'message')
|
752
|
+
----
|
753
|
+
|
754
|
+
=== References
|
755
|
+
|
756
|
+
* https://minitest.rubystyle.guide#refute-includes
|
757
|
+
|
758
|
+
== Minitest/RefuteInstanceOf
|
759
|
+
|
760
|
+
|===
|
761
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
762
|
+
|
763
|
+
| Enabled
|
764
|
+
| Yes
|
765
|
+
| Yes
|
766
|
+
| 0.4
|
767
|
+
| -
|
768
|
+
|===
|
769
|
+
|
770
|
+
This cop enforces the use of `refute_instance_of(Class, object)`
|
771
|
+
over `refute(object.instance_of?(Class))`.
|
772
|
+
|
773
|
+
=== Examples
|
774
|
+
|
775
|
+
[source,ruby]
|
776
|
+
----
|
777
|
+
# bad
|
778
|
+
refute(object.instance_of?(Class))
|
779
|
+
refute(object.instance_of?(Class), 'message')
|
780
|
+
|
781
|
+
# good
|
782
|
+
refute_instance_of(Class, object)
|
783
|
+
refute_instance_of(Class, object, 'message')
|
784
|
+
----
|
785
|
+
|
786
|
+
=== References
|
787
|
+
|
788
|
+
* https://minitest.rubystyle.guide#refute-instance-of
|
789
|
+
|
790
|
+
== Minitest/RefuteKindOf
|
791
|
+
|
792
|
+
|===
|
793
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
794
|
+
|
795
|
+
| Pending
|
796
|
+
| Yes
|
797
|
+
| Yes
|
798
|
+
| 0.10
|
799
|
+
| -
|
800
|
+
|===
|
801
|
+
|
802
|
+
This cop enforces the use of `refute_kind_of(Class, object)`
|
803
|
+
over `refute(object.kind_of?(Class))`.
|
804
|
+
|
805
|
+
=== Examples
|
806
|
+
|
807
|
+
[source,ruby]
|
808
|
+
----
|
809
|
+
# bad
|
810
|
+
refute(object.kind_of?(Class))
|
811
|
+
refute(object.kind_of?(Class), 'message')
|
812
|
+
|
813
|
+
# good
|
814
|
+
refute_kind_of(Class, object)
|
815
|
+
refute_kind_of(Class, object, 'message')
|
816
|
+
----
|
817
|
+
|
818
|
+
=== References
|
819
|
+
|
820
|
+
* https://github.com/rubocop-hq/minitest-style-guide#refute-kind-of
|
821
|
+
|
822
|
+
== Minitest/RefuteMatch
|
823
|
+
|
824
|
+
|===
|
825
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
826
|
+
|
827
|
+
| Enabled
|
828
|
+
| Yes
|
829
|
+
| Yes
|
830
|
+
| 0.6
|
831
|
+
| -
|
832
|
+
|===
|
833
|
+
|
834
|
+
This cop enforces the test to use `refute_match`
|
835
|
+
instead of using `refute(matcher.match(string))`.
|
836
|
+
|
837
|
+
=== Examples
|
838
|
+
|
839
|
+
[source,ruby]
|
840
|
+
----
|
841
|
+
# bad
|
842
|
+
refute(matcher.match(string))
|
843
|
+
refute(matcher.match(string), 'message')
|
844
|
+
|
845
|
+
# good
|
846
|
+
refute_match(matcher, string)
|
847
|
+
refute_match(matcher, string, 'message')
|
848
|
+
----
|
849
|
+
|
850
|
+
=== References
|
851
|
+
|
852
|
+
* https://minitest.rubystyle.guide#refute-match
|
853
|
+
|
854
|
+
== Minitest/RefuteNil
|
855
|
+
|
856
|
+
|===
|
857
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
858
|
+
|
859
|
+
| Enabled
|
860
|
+
| Yes
|
861
|
+
| Yes
|
862
|
+
| 0.2
|
863
|
+
| -
|
864
|
+
|===
|
865
|
+
|
866
|
+
This cop enforces the test to use `refute_nil`
|
867
|
+
instead of using `refute_equal(nil, something)`.
|
868
|
+
|
869
|
+
=== Examples
|
870
|
+
|
871
|
+
[source,ruby]
|
872
|
+
----
|
873
|
+
# bad
|
874
|
+
refute_equal(nil, actual)
|
875
|
+
refute_equal(nil, actual, 'message')
|
876
|
+
|
877
|
+
# good
|
878
|
+
refute_nil(actual)
|
879
|
+
refute_nil(actual, 'message')
|
880
|
+
----
|
881
|
+
|
882
|
+
=== References
|
883
|
+
|
884
|
+
* https://minitest.rubystyle.guide#refute-nil
|
885
|
+
|
886
|
+
== Minitest/RefutePathExists
|
887
|
+
|
888
|
+
|===
|
889
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
890
|
+
|
891
|
+
| Pending
|
892
|
+
| Yes
|
893
|
+
| Yes
|
894
|
+
| 0.10
|
895
|
+
| -
|
896
|
+
|===
|
897
|
+
|
898
|
+
This cop enforces the test to use `refute_path_exists`
|
899
|
+
instead of using `refute(File.exist?(path))`.
|
900
|
+
|
901
|
+
=== Examples
|
902
|
+
|
903
|
+
[source,ruby]
|
904
|
+
----
|
905
|
+
# bad
|
906
|
+
refute(File.exist?(path))
|
907
|
+
refute(File.exist?(path), 'message')
|
908
|
+
|
909
|
+
# good
|
910
|
+
refute_path_exists(path)
|
911
|
+
refute_path_exists(path, 'message')
|
912
|
+
----
|
913
|
+
|
914
|
+
=== References
|
915
|
+
|
916
|
+
* https://minitest.rubystyle.guide/#refute-path-exists
|
917
|
+
|
918
|
+
== Minitest/RefuteRespondTo
|
919
|
+
|
920
|
+
|===
|
921
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
922
|
+
|
923
|
+
| Enabled
|
924
|
+
| Yes
|
925
|
+
| Yes
|
926
|
+
| 0.4
|
927
|
+
| -
|
928
|
+
|===
|
929
|
+
|
930
|
+
This cop enforces the test to use `refute_respond_to(object, :do_something)`
|
931
|
+
over `refute(object.respond_to?(:do_something))`.
|
932
|
+
|
933
|
+
=== Examples
|
934
|
+
|
935
|
+
[source,ruby]
|
936
|
+
----
|
937
|
+
# bad
|
938
|
+
refute(object.respond_to?(:do_something))
|
939
|
+
refute(object.respond_to?(:do_something), 'message')
|
940
|
+
refute(respond_to?(:do_something))
|
941
|
+
|
942
|
+
# good
|
943
|
+
refute_respond_to(object, :do_something)
|
944
|
+
refute_respond_to(object, :do_something, 'message')
|
945
|
+
refute_respond_to(self, :do_something)
|
946
|
+
----
|
947
|
+
|
948
|
+
=== References
|
949
|
+
|
950
|
+
* https://minitest.rubystyle.guide#refute-respond-to
|
951
|
+
|
952
|
+
== Minitest/TestMethodName
|
953
|
+
|
954
|
+
|===
|
955
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
956
|
+
|
957
|
+
| Pending
|
958
|
+
| Yes
|
959
|
+
| Yes
|
960
|
+
| 0.10
|
961
|
+
| -
|
962
|
+
|===
|
963
|
+
|
964
|
+
This cop enforces that test method names start with `test_` prefix.
|
965
|
+
|
966
|
+
=== Examples
|
967
|
+
|
968
|
+
[source,ruby]
|
969
|
+
----
|
970
|
+
# bad
|
971
|
+
class FooTest < Minitest::Test
|
972
|
+
def does_something
|
973
|
+
assert_equal 42, do_something
|
974
|
+
end
|
975
|
+
end
|
976
|
+
|
977
|
+
# good
|
978
|
+
class FooTest < Minitest::Test
|
979
|
+
def test_does_something
|
980
|
+
assert_equal 42, do_something
|
981
|
+
end
|
982
|
+
end
|
983
|
+
----
|
984
|
+
|
985
|
+
== Minitest/UnspecifiedException
|
986
|
+
|
987
|
+
|===
|
988
|
+
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
989
|
+
|
990
|
+
| Pending
|
991
|
+
| Yes
|
992
|
+
| No
|
993
|
+
| 0.10
|
994
|
+
| -
|
995
|
+
|===
|
996
|
+
|
997
|
+
This cop checks for a specified error in `assert_raises`.
|
998
|
+
|
999
|
+
=== Examples
|
1000
|
+
|
1001
|
+
[source,ruby]
|
1002
|
+
----
|
1003
|
+
# bad
|
1004
|
+
assert_raises { raise FooException }
|
1005
|
+
assert_raises('This should have raised') { raise FooException }
|
1006
|
+
|
1007
|
+
# good
|
1008
|
+
assert_raises(FooException) { raise FooException }
|
1009
|
+
assert_raises(FooException, 'This should have raised') { raise FooException }
|
1010
|
+
----
|
1011
|
+
|
1012
|
+
=== References
|
1013
|
+
|
1014
|
+
* https://minitest.rubystyle.guide#unspecified-exception
|