docs/modules/ROOT/pages/cops_minitest.adoc in rubocop-minitest-0.19.1 vs docs/modules/ROOT/pages/cops_minitest.adoc in rubocop-minitest-0.20.0
- old
+ new
@@ -10,12 +10,11 @@
| Yes
| 0.2
| -
|===
-This cop enforces the test to use `assert_empty`
-instead of using `assert(object.empty?)`.
+Enforces the test to use `assert_empty` instead of using `assert(object.empty?)`.
=== Examples
[source,ruby]
----
@@ -42,11 +41,11 @@
| Yes
| 0.5
| 0.11
|===
-This cop enforces the test to use `assert_empty`
+Enforces the test to use `assert_empty`
instead of using `assert_equal([], object)` or `assert_equal({}, object)`.
=== Examples
[source,ruby]
@@ -69,11 +68,11 @@
| Yes
| 0.4
| -
|===
-This cop enforces the use of `assert_equal(expected, actual)`
+Enforces the use of `assert_equal(expected, actual)`
over `assert(expected == actual)`.
=== Examples
[source,ruby]
@@ -99,11 +98,11 @@
| Yes
| 0.10
| -
|===
-This cop enforces the test to use `assert_in_delta`
+Enforces the test to use `assert_in_delta`
instead of using `assert_equal` to compare floats.
=== Examples
[source,ruby]
@@ -131,11 +130,11 @@
| Yes
| 0.2
| -
|===
-This cop enforces the test to use `assert_includes`
+Enforces the test to use `assert_includes`
instead of using `assert(collection.include?(object))`.
=== Examples
[source,ruby]
@@ -163,11 +162,11 @@
| Yes
| 0.4
| -
|===
-This cop enforces the test to use `assert_instance_of(Class, object)`
+Enforces the test to use `assert_instance_of(Class, object)`
over `assert(object.instance_of?(Class))`.
=== Examples
[source,ruby]
@@ -195,11 +194,11 @@
| Yes
| 0.10
| -
|===
-This cop enforces the test to use `assert_kind_of(Class, object)`
+Enforces the test to use `assert_kind_of(Class, object)`
over `assert(object.kind_of?(Class))`.
=== Examples
[source,ruby]
@@ -227,11 +226,11 @@
| Yes
| 0.6
| -
|===
-This cop enforces the test to use `assert_match`
+Enforces the test to use `assert_match`
instead of using `assert(matcher.match(string))`.
=== Examples
[source,ruby]
@@ -259,11 +258,11 @@
| Yes
| 0.1
| -
|===
-This cop enforces the test to use `assert_nil` instead of using
+Enforces the test to use `assert_nil` instead of using
`assert_equal(nil, something)`, `assert(something.nil?)`, or `assert_predicate(something, :nil?)`.
=== Examples
[source,ruby]
@@ -295,11 +294,11 @@
| No
| 0.10
| -
|===
-This cop checks for opportunities to use `assert_output`.
+Checks for opportunities to use `assert_output`.
=== Examples
[source,ruby]
----
@@ -327,12 +326,11 @@
| Yes
| 0.10
| -
|===
-This cop enforces the test to use `assert_path_exists`
-instead of using `assert(File.exist?(path))`.
+Enforces the test to use `assert_path_exists` instead of using `assert(File.exist?(path))`.
=== Examples
[source,ruby]
----
@@ -359,11 +357,11 @@
| Yes
| 0.18
| -
|===
-This cop enforces the test to use `assert_predicate`
+Enforces the test to use `assert_predicate`
instead of using `assert(obj.a_predicate_method?)`.
=== Examples
[source,ruby]
@@ -391,11 +389,11 @@
| Yes
| 0.3
| -
|===
-This cop enforces the use of `assert_respond_to(object, :do_something)`
+Enforces the use of `assert_respond_to(object, :do_something)`
over `assert(object.respond_to?(:do_something))`.
=== Examples
[source,ruby]
@@ -425,11 +423,11 @@
| Yes
| 0.10
| -
|===
-This cop enforces the test to use `assert_silent { ... }`
+Enforces the test to use `assert_silent { ... }`
instead of using `assert_output('', '') { ... }`.
=== Examples
[source,ruby]
@@ -455,12 +453,11 @@
| Yes
| 0.2
| -
|===
-This cop enforces the test to use `assert(actual)`
-instead of using `assert_equal(true, actual)`.
+Enforces the test to use `assert(actual)` instead of using `assert_equal(true, actual)`.
=== Examples
[source,ruby]
----
@@ -487,11 +484,11 @@
| No
| 0.11
| -
|===
-This cop tries to detect when a user accidentally used
+Tries to detect when a user accidentally used
`assert` when they meant to use `assert_equal`.
=== Safety
This cop is unsafe because it is not possible to determine
@@ -521,11 +518,11 @@
| No
| 0.10
| -
|===
-This cop checks for usage of assertions in lifecycle hooks.
+Checks for usage of assertions in lifecycle hooks.
=== Examples
[source,ruby]
----
@@ -558,11 +555,11 @@
If a Minitest class inherits from another class,
it will also inherit its methods causing Minitest to run the parent's tests methods twice.
This cop detects when there are two tests classes, one inherits from the other, and both have tests methods.
-This cop will add an offence to the Child class in such a case.
+This cop will add an offense to the Child class in such a case.
=== Examples
[source,ruby]
----
@@ -599,10 +596,14 @@
def test_parent
end
end
----
+=== References
+
+* https://minitest.rubystyle.guide/#subclassing-test-cases
+
== Minitest/GlobalExpectations
|===
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
@@ -611,11 +612,11 @@
| Yes
| 0.7
| 0.16
|===
-This cop checks for deprecated global expectations
+Checks for deprecated global expectations
and autocorrects them to use expect format.
=== Examples
==== EnforcedStyle: _
@@ -738,11 +739,11 @@
| Yes
| 0.10
| -
|===
-This cop enforces correct order of expected and
+Enforces correct order of expected and
actual arguments for `assert_equal`.
=== Examples
[source,ruby]
@@ -772,11 +773,11 @@
| No
| 0.10
| -
|===
-This cop checks if test cases contain too many assertion calls.
+Checks if test cases contain too many assertion calls.
The maximum allowed assertion calls is configurable.
=== Examples
==== Max: 1
@@ -823,11 +824,11 @@
| No
| 0.12
| -
|===
-This cop checks if test cases contain any assertion calls.
+Checks if test cases contain any assertion calls.
=== Examples
[source,ruby]
----
@@ -855,12 +856,11 @@
| Yes
| 0.3
| -
|===
-This cop enforces to use `refute_empty` instead of
-using `refute(object.empty?)`.
+Enforces to use `refute_empty` instead of using `refute(object.empty?)`.
=== Examples
[source,ruby]
----
@@ -887,11 +887,11 @@
| Yes
| 0.3
| -
|===
-This cop enforces the use of `refute_equal(expected, object)`
+Enforces the use of `refute_equal(expected, object)`
over `assert(expected != actual)` or `assert(! expected == actual)`.
=== Examples
[source,ruby]
@@ -918,12 +918,11 @@
| Yes
| 0.3
| -
|===
-This cop enforces the use of `refute(object)`
-over `assert_equal(false, object)`.
+Enforces the use of `refute(object)` over `assert_equal(false, object)`.
=== Examples
[source,ruby]
----
@@ -953,11 +952,11 @@
| Yes
| 0.10
| -
|===
-This cop enforces the test to use `refute_in_delta`
+Enforces the test to use `refute_in_delta`
instead of using `refute_equal` to compare floats.
=== Examples
[source,ruby]
@@ -985,11 +984,11 @@
| Yes
| 0.3
| -
|===
-This cop enforces the test to use `refute_includes`
+Enforces the test to use `refute_includes`
instead of using `refute(collection.include?(object))`.
=== Examples
[source,ruby]
@@ -1017,11 +1016,11 @@
| Yes
| 0.4
| -
|===
-This cop enforces the use of `refute_instance_of(Class, object)`
+Enforces the use of `refute_instance_of(Class, object)`
over `refute(object.instance_of?(Class))`.
=== Examples
[source,ruby]
@@ -1049,11 +1048,11 @@
| Yes
| 0.10
| -
|===
-This cop enforces the use of `refute_kind_of(Class, object)`
+Enforces the use of `refute_kind_of(Class, object)`
over `refute(object.kind_of?(Class))`.
=== Examples
[source,ruby]
@@ -1081,11 +1080,11 @@
| Yes
| 0.6
| -
|===
-This cop enforces the test to use `refute_match`
+Enforces the test to use `refute_match`
instead of using `refute(matcher.match(string))`.
=== Examples
[source,ruby]
@@ -1113,11 +1112,11 @@
| Yes
| 0.2
| -
|===
-This cop enforces the test to use `refute_nil` instead of using
+Enforces the test to use `refute_nil` instead of using
`refute_equal(nil, something)`, `refute(something.nil?)`, or `refute_predicate(something, :nil?)`.
=== Examples
[source,ruby]
@@ -1149,12 +1148,11 @@
| Yes
| 0.10
| -
|===
-This cop enforces the test to use `refute_path_exists`
-instead of using `refute(File.exist?(path))`.
+Enforces the test to use `refute_path_exists` instead of using `refute(File.exist?(path))`.
=== Examples
[source,ruby]
----
@@ -1181,11 +1179,11 @@
| Yes
| 0.18
| -
|===
-This cop enforces the test to use `refute_predicate`
+Enforces the test to use `refute_predicate`
instead of using `refute(obj.a_predicate_method?)`.
=== Examples
[source,ruby]
@@ -1213,11 +1211,11 @@
| Yes
| 0.4
| -
|===
-This cop enforces the test to use `refute_respond_to(object, :do_something)`
+Enforces the test to use `refute_respond_to(object, :do_something)`
over `refute(object.respond_to?(:do_something))`.
=== Examples
[source,ruby]
@@ -1235,10 +1233,83 @@
=== References
* https://minitest.rubystyle.guide#refute-respond-to
+== Minitest/SkipEnsure
+
+|===
+| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
+
+| Pending
+| Yes
+| No
+| 0.20
+| -
+|===
+
+Checks that `ensure` call even if `skip`. It is unexpected that `ensure` will be called when skipping test.
+If conditional `skip` is used, it checks that `ensure` is also called conditionally.
+
+On the other hand, it accepts `skip` used in `rescue` because `ensure` may be teardown process to `begin`
+setup process.
+
+=== Examples
+
+[source,ruby]
+----
+# bad
+def test_skip
+ skip 'This test is skipped.'
+
+ assert 'foo'.present?
+ensure
+ do_something
+end
+
+# bad
+def test_conditional_skip
+ skip 'This test is skipped.' if condition
+
+ assert do_something
+ensure
+ do_teardown
+end
+
+# good
+def test_skip
+ skip 'This test is skipped.'
+
+ begin
+ assert 'foo'.present?
+ ensure
+ do_something
+ end
+end
+
+# good
+def test_conditional_skip
+ skip 'This test is skipped.' if condition
+
+ assert do_something
+ensure
+ if condition
+ do_teardown
+ end
+end
+
+# good
+def test_skip_is_used_in_rescue
+ do_setup
+ assert do_something
+rescue
+ skip 'This test is skipped.'
+ensure
+ do_teardown
+end
+----
+
== Minitest/TestMethodName
|===
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
@@ -1247,11 +1318,11 @@
| Yes
| 0.10
| -
|===
-This cop enforces that test method names start with `test_` prefix.
+Enforces that test method names start with `test_` prefix.
It aims to prevent tests that aren't executed by forgetting to start test method name with `test_`.
=== Examples
[source,ruby]
@@ -1287,11 +1358,11 @@
| No
| 0.14
| -
|===
-This cop checks for `assert_raises` has an assertion method at
+Checks for `assert_raises` has an assertion method at
the bottom of block because the assertion will be never reached.
=== Examples
[source,ruby]
@@ -1319,10 +1390,10 @@
| No
| 0.10
| -
|===
-This cop checks for a specified error in `assert_raises`.
+Checks for a specified error in `assert_raises`.
=== Examples
[source,ruby]
----