diff --git a/CHANGELOG.md b/CHANGELOG.md index 7333a35b..9449d9a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## master (unreleased) +## 0.18.0 (2022-03-13) + ### New features * [#161](https://github.com/rubocop/rubocop-minitest/pull/161): Add new `Minitest/AssertPredicate` and `Minitest/RefutePredicate` cops. ([@koic][]) diff --git a/config/default.yml b/config/default.yml index 467cdc6d..dd836ca6 100644 --- a/config/default.yml +++ b/config/default.yml @@ -85,7 +85,7 @@ Minitest/AssertPredicate: Description: 'This cop enforces the test to use `assert_predicate` instead of using `assert(obj.a_predicate_method?)`.' StyleGuide: 'https://minitest.rubystyle.guide/#assert-predicate' Enabled: pending - VersionAdded: '<>' + VersionAdded: '0.18' Minitest/AssertSilent: Description: "This cop enforces the test to use `assert_silent { ... }` instead of using `assert_output('', '') { ... }`." @@ -204,7 +204,7 @@ Minitest/RefutePredicate: Description: 'This cop enforces the test to use `refute_predicate` instead of using `refute(obj.a_predicate_method?)`.' StyleGuide: 'https://minitest.rubystyle.guide/#refute-predicate' Enabled: pending - VersionAdded: '<>' + VersionAdded: '0.18' Minitest/RefuteRespondTo: Description: 'This cop enforces the test to use `refute_respond_to(object, :do_something)` over `refute(object.respond_to?(:do_something))`.' diff --git a/docs/antora.yml b/docs/antora.yml index 5fb5d9b0..f26ad279 100644 --- a/docs/antora.yml +++ b/docs/antora.yml @@ -2,6 +2,6 @@ name: rubocop-minitest title: RuboCop Minitest # We always provide version without patch here (e.g. 1.1), # as patch versions should not appear in the docs. -version: 'master' +version: '0.18' nav: - modules/ROOT/nav.adoc diff --git a/docs/modules/ROOT/pages/cops.adoc b/docs/modules/ROOT/pages/cops.adoc index 76129963..979f17dc 100644 --- a/docs/modules/ROOT/pages/cops.adoc +++ b/docs/modules/ROOT/pages/cops.adoc @@ -24,6 +24,7 @@ based on the https://minitest.rubystyle.guide/[Minitest Style Guide]. * xref:cops_minitest.adoc#minitestassertnil[Minitest/AssertNil] * xref:cops_minitest.adoc#minitestassertoutput[Minitest/AssertOutput] * xref:cops_minitest.adoc#minitestassertpathexists[Minitest/AssertPathExists] +* xref:cops_minitest.adoc#minitestassertpredicate[Minitest/AssertPredicate] * xref:cops_minitest.adoc#minitestassertrespondto[Minitest/AssertRespondTo] * xref:cops_minitest.adoc#minitestassertsilent[Minitest/AssertSilent] * xref:cops_minitest.adoc#minitestasserttruthy[Minitest/AssertTruthy] @@ -43,6 +44,7 @@ based on the https://minitest.rubystyle.guide/[Minitest Style Guide]. * xref:cops_minitest.adoc#minitestrefutematch[Minitest/RefuteMatch] * xref:cops_minitest.adoc#minitestrefutenil[Minitest/RefuteNil] * xref:cops_minitest.adoc#minitestrefutepathexists[Minitest/RefutePathExists] +* xref:cops_minitest.adoc#minitestrefutepredicate[Minitest/RefutePredicate] * xref:cops_minitest.adoc#minitestrefuterespondto[Minitest/RefuteRespondTo] * xref:cops_minitest.adoc#minitesttestmethodname[Minitest/TestMethodName] * xref:cops_minitest.adoc#minitestunreachableassertion[Minitest/UnreachableAssertion] diff --git a/docs/modules/ROOT/pages/cops_minitest.adoc b/docs/modules/ROOT/pages/cops_minitest.adoc index f1fd6f33..b323fff5 100644 --- a/docs/modules/ROOT/pages/cops_minitest.adoc +++ b/docs/modules/ROOT/pages/cops_minitest.adoc @@ -262,7 +262,7 @@ assert_match(matcher, string, 'message') |=== This cop enforces the test to use `assert_nil` instead of using -`assert_equal(nil, something)` or `assert(something.nil?)`. +`assert_equal(nil, something)`, `assert(something.nil?)`, or `assert_predicate(something, :nil?)`. === Examples @@ -273,6 +273,8 @@ assert_equal(nil, actual) assert_equal(nil, actual, 'message') assert(object.nil?) assert(object.nil?, 'message') +assert_predicate(object, :nil?) +assert_predicate(object, :nil?, 'message') # good assert_nil(actual) @@ -347,6 +349,38 @@ assert_path_exists(path, 'message') * https://minitest.rubystyle.guide/#assert-path-exists +== Minitest/AssertPredicate + +|=== +| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed + +| Pending +| Yes +| Yes +| 0.18 +| - +|=== + +This cop enforces the test to use `assert_predicate` +instead of using `assert(obj.a_predicate_method?)`. + +=== Examples + +[source,ruby] +---- +# bad +assert(obj.one?) +assert(obj.one?, 'message') + +# good +assert_predicate(obj, :one?) +assert_predicate(obj, :one?, 'message') +---- + +=== References + +* https://minitest.rubystyle.guide/#assert-predicate + == Minitest/AssertRespondTo |=== @@ -1025,7 +1059,7 @@ refute_match(matcher, string, 'message') |=== This cop enforces the test to use `refute_nil` instead of using -`refute_equal(nil, something)` or `refute(something.nil?)`. +`refute_equal(nil, something)`, `refute(something.nil?)`, or `refute_predicate(something, :nil?)`. === Examples @@ -1036,6 +1070,8 @@ refute_equal(nil, actual) refute_equal(nil, actual, 'message') refute(actual.nil?) refute(actual.nil?, 'message') +refute_predicate(object, :nil?) +refute_predicate(object, :nil?, 'message') # good refute_nil(actual) @@ -1078,6 +1114,38 @@ refute_path_exists(path, 'message') * https://minitest.rubystyle.guide/#refute-path-exists +== Minitest/RefutePredicate + +|=== +| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed + +| Pending +| Yes +| Yes +| 0.18 +| - +|=== + +This cop enforces the test to use `refute_predicate` +instead of using `refute(obj.a_predicate_method?)`. + +=== Examples + +[source,ruby] +---- +# bad +refute(obj.one?) +refute(obj.one?, 'message') + +# good +refute_predicate(obj, :one?) +refute_predicate(obj, :one?, 'message') +---- + +=== References + +* https://minitest.rubystyle.guide/#refute-predicate + == Minitest/RefuteRespondTo |=== diff --git a/lib/rubocop/minitest/version.rb b/lib/rubocop/minitest/version.rb index 861fc1e5..428b99e3 100644 --- a/lib/rubocop/minitest/version.rb +++ b/lib/rubocop/minitest/version.rb @@ -4,7 +4,7 @@ module RuboCop module Minitest # This module holds the RuboCop Minitest version information. module Version - STRING = '0.17.2' + STRING = '0.18.0' def self.document_version STRING.match('\d+\.\d+').to_s diff --git a/relnotes/v0.18.0.md b/relnotes/v0.18.0.md new file mode 100644 index 00000000..99427e64 --- /dev/null +++ b/relnotes/v0.18.0.md @@ -0,0 +1,9 @@ +### New features + +* [#161](https://github.com/rubocop/rubocop-minitest/pull/161): Add new `Minitest/AssertPredicate` and `Minitest/RefutePredicate` cops. ([@koic][]) + +### Changes + +* [#162](https://github.com/rubocop/rubocop-minitest/pull/162): Make `Minitest/AssertNil` (`Minitest/RefuteNil`) aware of `assert_predicate(obj, :nil?)` (`refute_predicate(obj, :nil?)`). ([@koic][]) + +[@koic]: https://github.com/koic