rubocop-minitest 0.13.0 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cb85f2ad7f928abf4e8f8e2c22c8508700960b11bdb8215b4ca8ea792a96dd73
4
- data.tar.gz: 404314baeb561c4be2bd64eb1ec154d014942975ce4c0780b43df4c1a35e9286
3
+ metadata.gz: bcdc752936f6002cc925a5ca82039770b2977685a53f182250b0cc75fffbb412
4
+ data.tar.gz: a634c0d0fa393ef7f00b07ebb8c17063df18c8e4d92643eb361699c1fa327097
5
5
  SHA512:
6
- metadata.gz: b20af6e92af74832f025aad226808d3343da4dd427149137b331a0ad177ab6aabcf5f326dfc83022aa50b73dc21fc48e4bb5149f2aa2506c7cf4ba7a0b7a97ac
7
- data.tar.gz: a535fb3d220ec32ceb6c1fb2cd75f7cdd7061709334609e566900e65c47506ea15751827f8b49d3f73af8cc8b39705534c817b55aead18c3f3206e877f0996b8
6
+ metadata.gz: 1879892d3bb7d99c4e2e1c483f1c9f93b990f55fecc71f5ae37b0193bfde0ae7167588d21fbf3a62abdfa26f4e88efc2655d0ddc4e0f078f23fe5f05843e95ca
7
+ data.tar.gz: c411392994e053920757c682c793defae132d9fd4e556c131f6c4a74fef3d93dca05fab0f3bd91a3081e038a943dd41a00b88626966b0c74928e97afa0cec65f
data/.rubocop.yml CHANGED
@@ -23,6 +23,19 @@ Naming/PredicateName:
23
23
  - def_node_matcher
24
24
  - def_node_search
25
25
 
26
+ Naming/InclusiveLanguage:
27
+ FlaggedTerms:
28
+ whitelist:
29
+ Suggestions:
30
+ - allowlist
31
+ blacklist:
32
+ Suggestions:
33
+ - denylist
34
+ master:
35
+ AllowedRegex:
36
+ - 'blob/master/'
37
+ - 'master \(unreleased\)'
38
+
26
39
  Style/FormatStringToken:
27
40
  # Because we parse a lot of source codes from strings. Percent arrays
28
41
  # look like unannotated format string tokens to this cop.
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## master (unreleased)
4
4
 
5
+ ## 0.14.0 (2021-07-03)
6
+
7
+ ### New features
8
+
9
+ * [#133](https://github.com/rubocop/rubocop-minitest/issues/133): Add new `Minitest/UnreachableAssertion` cop. ([@koic][])
10
+
5
11
  ## 0.13.0 (2021-06-20)
6
12
 
7
13
  ### New features
data/config/default.yml CHANGED
@@ -194,6 +194,11 @@ Minitest/TestMethodName:
194
194
  Enabled: 'pending'
195
195
  VersionAdded: '0.10'
196
196
 
197
+ Minitest/UnreachableAssertion:
198
+ Description: 'This cop checks for an `assert_raises` block containing any unreachable assertions.'
199
+ Enabled: pending
200
+ VersionAdded: '0.14'
201
+
197
202
  Minitest/UnspecifiedException:
198
203
  Description: 'This cop checks for a specified error in `assert_raises`.'
199
204
  StyleGuide: 'https://minitest.rubystyle.guide#unspecified-exception'
data/docs/antora.yml CHANGED
@@ -2,6 +2,6 @@ name: rubocop-minitest
2
2
  title: RuboCop Minitest
3
3
  # We always provide version without patch here (e.g. 1.1),
4
4
  # as patch versions should not appear in the docs.
5
- version: '0.13'
5
+ version: '0.14'
6
6
  nav:
7
7
  - modules/ROOT/nav.adoc
@@ -45,6 +45,7 @@ based on the https://minitest.rubystyle.guide/[Minitest Style Guide].
45
45
  * xref:cops_minitest.adoc#minitestrefutepathexists[Minitest/RefutePathExists]
46
46
  * xref:cops_minitest.adoc#minitestrefuterespondto[Minitest/RefuteRespondTo]
47
47
  * xref:cops_minitest.adoc#minitesttestmethodname[Minitest/TestMethodName]
48
+ * xref:cops_minitest.adoc#minitestunreachableassertion[Minitest/UnreachableAssertion]
48
49
  * xref:cops_minitest.adoc#minitestunspecifiedexception[Minitest/UnspecifiedException]
49
50
 
50
51
  // END_COP_LIST
@@ -1053,6 +1053,38 @@ class FooTest < Minitest::Test
1053
1053
  end
1054
1054
  ----
1055
1055
 
1056
+ == Minitest/UnreachableAssertion
1057
+
1058
+ |===
1059
+ | Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
1060
+
1061
+ | Pending
1062
+ | Yes
1063
+ | No
1064
+ | 0.14
1065
+ | -
1066
+ |===
1067
+
1068
+ This cop checks for `assert_raises` has an assertion method at
1069
+ the bottom of block because the assertion will be never reached.
1070
+
1071
+ === Examples
1072
+
1073
+ [source,ruby]
1074
+ ----
1075
+ # bad
1076
+ assert_raises FooError do
1077
+ obj.occur_error
1078
+ assert_equal('foo', obj.bar) # Never asserted.
1079
+ end
1080
+
1081
+ # good
1082
+ assert_raises FooError do
1083
+ obj.occur_error
1084
+ end
1085
+ assert_equal('foo', obj.bar)
1086
+ ----
1087
+
1056
1088
  == Minitest/UnspecifiedException
1057
1089
 
1058
1090
  |===
@@ -22,10 +22,8 @@ module RuboCop
22
22
  include ArgumentRangeHelper
23
23
  extend AutoCorrector
24
24
 
25
- MSG_FOR_ASSERT_EQUAL = 'Prefer using `refute(%<arguments>s)` over ' \
26
- '`assert_equal(false, %<arguments>s)`.'
27
- MSG_FOR_ASSERT = 'Prefer using `refute(%<arguments>s)` over ' \
28
- '`assert(!%<arguments>s)`.'
25
+ MSG_FOR_ASSERT_EQUAL = 'Prefer using `refute(%<arguments>s)` over `assert_equal(false, %<arguments>s)`.'
26
+ MSG_FOR_ASSERT = 'Prefer using `refute(%<arguments>s)` over `assert(!%<arguments>s)`.'
29
27
  RESTRICT_ON_SEND = %i[assert_equal assert].freeze
30
28
 
31
29
  def_node_matcher :assert_equal_with_false, <<~PATTERN
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Minitest
6
+ # This cop checks for `assert_raises` has an assertion method at
7
+ # the bottom of block because the assertion will be never reached.
8
+ #
9
+ # @example
10
+ #
11
+ # # bad
12
+ # assert_raises FooError do
13
+ # obj.occur_error
14
+ # assert_equal('foo', obj.bar) # Never asserted.
15
+ # end
16
+ #
17
+ # # good
18
+ # assert_raises FooError do
19
+ # obj.occur_error
20
+ # end
21
+ # assert_equal('foo', obj.bar)
22
+ #
23
+ class UnreachableAssertion < Base
24
+ include MinitestExplorationHelpers
25
+
26
+ MSG = 'Unreachable `%<assertion_method>s` detected.'
27
+
28
+ def on_block(node)
29
+ return unless node.method?(:assert_raises) && (body = node.body)
30
+
31
+ last_node = body.begin_type? ? body.children.last : body
32
+ return unless last_node.send_type?
33
+
34
+ method_name = last_node.method_name
35
+ return unless assertion_method?(method_name)
36
+
37
+ add_offense(last_node, message: format(MSG, assertion_method: method_name))
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -36,4 +36,5 @@ require_relative 'minitest/refute_instance_of'
36
36
  require_relative 'minitest/refute_path_exists'
37
37
  require_relative 'minitest/refute_respond_to'
38
38
  require_relative 'minitest/test_method_name'
39
+ require_relative 'minitest/unreachable_assertion'
39
40
  require_relative 'minitest/unspecified_exception'
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Minitest
5
5
  # This module holds the RuboCop Minitest version information.
6
6
  module Version
7
- STRING = '0.13.0'
7
+ STRING = '0.14.0'
8
8
 
9
9
  def self.document_version
10
10
  STRING.match('\d+\.\d+').to_s
@@ -0,0 +1,5 @@
1
+ ### New features
2
+
3
+ * [#133](https://github.com/rubocop/rubocop-minitest/issues/133): Add new `Minitest/UnreachableAssertion` cop. ([@koic][])
4
+
5
+ [@koic]: https://github.com/koic
@@ -25,8 +25,7 @@ task verify_cops_documentation: :generate_cops_documentation do
25
25
  # Output diff before raising error
26
26
  sh('GIT_PAGER=cat git diff docs')
27
27
 
28
- warn 'The docs directory is out of sync. ' \
29
- 'Run `rake generate_cops_documentation` and commit the results.'
28
+ warn 'The docs directory is out of sync. Run `rake generate_cops_documentation` and commit the results.'
30
29
  exit!
31
30
  end
32
31
  end
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.13.0
4
+ version: 0.14.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: 2021-06-20 00:00:00.000000000 Z
13
+ date: 2021-07-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rubocop
@@ -118,6 +118,7 @@ files:
118
118
  - lib/rubocop/cop/minitest/refute_path_exists.rb
119
119
  - lib/rubocop/cop/minitest/refute_respond_to.rb
120
120
  - lib/rubocop/cop/minitest/test_method_name.rb
121
+ - lib/rubocop/cop/minitest/unreachable_assertion.rb
121
122
  - lib/rubocop/cop/minitest/unspecified_exception.rb
122
123
  - lib/rubocop/cop/minitest_cops.rb
123
124
  - lib/rubocop/cop/mixin/argument_range_helper.rb
@@ -139,6 +140,7 @@ files:
139
140
  - relnotes/v0.12.0.md
140
141
  - relnotes/v0.12.1.md
141
142
  - relnotes/v0.13.0.md
143
+ - relnotes/v0.14.0.md
142
144
  - relnotes/v0.2.0.md
143
145
  - relnotes/v0.2.1.md
144
146
  - relnotes/v0.3.0.md
@@ -163,7 +165,7 @@ metadata:
163
165
  homepage_uri: https://docs.rubocop.org/rubocop-minitest/
164
166
  changelog_uri: https://github.com/rubocop/rubocop-minitest/blob/master/CHANGELOG.md
165
167
  source_code_uri: https://github.com/rubocop/rubocop-minitest
166
- documentation_uri: https://docs.rubocop.org/rubocop-minitest/0.13
168
+ documentation_uri: https://docs.rubocop.org/rubocop-minitest/0.14
167
169
  bug_tracker_uri: https://github.com/rubocop/rubocop-minitest/issues
168
170
  post_install_message:
169
171
  rdoc_options: []