rubocop-minitest 0.20.1 → 0.21.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: d780d9c08b215f247a19ffc039d8385b58f63037585c882e3b760cdbe511ae14
4
- data.tar.gz: 1ea02089d0b9a3511cbc19a3222f3c55e86a3c17d05bdc05291281df8115500a
3
+ metadata.gz: 1026c124f46d1dc887ec84cc1a0bf3b246afee76f0201c3d96bbd0895f3045e9
4
+ data.tar.gz: 2a66060a132b7235c2bbe77747df17fdb47bcf0011b0f03467612f514c7454de
5
5
  SHA512:
6
- metadata.gz: 241d069163e52ba35fc4edb2c96d3f7fca6a32fa84ced1feee2abf777d42561503b309371444b81da318c3f07bce469a89e12fc2f6d0295372c3249c41db1ff1
7
- data.tar.gz: 76ec782b3a226848f6676266dfbd1f06dc0cf2bbd999f01f9c46096def25cfe188c7dddb95ca93ab737812ef6eae81fd8401872b8a243344e1903c50143a699c
6
+ metadata.gz: dd56df2ffbf84f91e18af928f18d66decae8879a030db57f1833f1c4811aaf670c367067e42304b6ba94a38cbb7a13aeb55706d02f8495d25e4b5a1a66930c38
7
+ data.tar.gz: bf2460fca6fe8af2921a84e8b9f6c2fd6e34528a01f9c3c4b781dac4946fe7b042943977baf2c6d9dee7e83f4cf1a8573db492b06b6f63dff559320ccf5e733e
data/.rubocop.yml CHANGED
@@ -31,6 +31,12 @@ Naming/InclusiveLanguage:
31
31
  Enabled: true
32
32
  CheckStrings: true
33
33
  FlaggedTerms:
34
+ auto-correct:
35
+ Suggestions:
36
+ - autocorrect
37
+ auto_correct:
38
+ Suggestions:
39
+ - autocorrect
34
40
  behaviour:
35
41
  Suggestions:
36
42
  - behavior
@@ -68,6 +74,9 @@ Layout/ClassStructure:
68
74
  - protected_methods
69
75
  - private_methods
70
76
 
77
+ Layout/RedundantLineBreak:
78
+ Enabled: true
79
+
71
80
  # Trailing white space is meaningful in code examples
72
81
  Layout/TrailingWhitespace:
73
82
  AllowInHeredoc: true
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## master (unreleased)
4
4
 
5
+ ## 0.21.0 (2022-07-31)
6
+
7
+ ### New features
8
+
9
+ * [#109](https://github.com/rubocop/rubocop-minitest/issues/109): Add new `Minitest/AssertRaisesCompoundBody` cop. ([@fatkodima][])
10
+
5
11
  ## 0.20.1 (2022-06-13)
6
12
 
7
13
  ### Bug fixes
data/Rakefile CHANGED
@@ -28,18 +28,14 @@ end
28
28
  desc 'Run RuboCop over itself'
29
29
  RuboCop::RakeTask.new(:internal_investigation)
30
30
 
31
- task default: %i[
32
- documentation_syntax_check
33
- test
34
- internal_investigation
35
- ]
31
+ task default: %i[documentation_syntax_check test internal_investigation]
36
32
 
37
33
  desc 'Generate a new cop template'
38
34
  task :new_cop, [:cop] do |_task, args|
39
35
  require 'rubocop'
40
36
 
41
37
  cop_name = args.fetch(:cop) do
42
- warn 'usage: bundle exec rake new_cop[Department/Name]'
38
+ warn "usage: bundle exec rake 'new_cop[Department/Name]'"
43
39
  exit!
44
40
  end
45
41
 
data/config/default.yml CHANGED
@@ -76,6 +76,11 @@ Minitest/AssertPredicate:
76
76
  Enabled: pending
77
77
  VersionAdded: '0.18'
78
78
 
79
+ Minitest/AssertRaisesCompoundBody:
80
+ Description: 'This cop enforces the block body of `assert_raises { ... }` to be reduced to only the raising code.'
81
+ Enabled: pending
82
+ VersionAdded: '0.21'
83
+
79
84
  Minitest/AssertRespondTo:
80
85
  Description: 'This cop enforces the test to use `assert_respond_to(object, :do_something)` over `assert(object.respond_to?(:do_something))`.'
81
86
  StyleGuide: 'https://minitest.rubystyle.guide#assert-responds-to-method'
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.20'
5
+ version: '0.21'
6
6
  nav:
7
7
  - modules/ROOT/nav.adoc
@@ -25,6 +25,7 @@ based on the https://minitest.rubystyle.guide/[Minitest Style Guide].
25
25
  * xref:cops_minitest.adoc#minitestassertoutput[Minitest/AssertOutput]
26
26
  * xref:cops_minitest.adoc#minitestassertpathexists[Minitest/AssertPathExists]
27
27
  * xref:cops_minitest.adoc#minitestassertpredicate[Minitest/AssertPredicate]
28
+ * xref:cops_minitest.adoc#minitestassertraisescompoundbody[Minitest/AssertRaisesCompoundBody]
28
29
  * xref:cops_minitest.adoc#minitestassertrespondto[Minitest/AssertRespondTo]
29
30
  * xref:cops_minitest.adoc#minitestassertsilent[Minitest/AssertSilent]
30
31
  * xref:cops_minitest.adoc#minitestasserttruthy[Minitest/AssertTruthy]
@@ -379,6 +379,44 @@ assert_predicate(obj, :one?, 'message')
379
379
 
380
380
  * https://minitest.rubystyle.guide/#assert-predicate
381
381
 
382
+ == Minitest/AssertRaisesCompoundBody
383
+
384
+ |===
385
+ | Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
386
+
387
+ | Pending
388
+ | Yes
389
+ | No
390
+ | 0.21
391
+ | -
392
+ |===
393
+
394
+ Enforces the block body of `assert_raises { ... }` to be reduced to only the raising code.
395
+
396
+ === Examples
397
+
398
+ [source,ruby]
399
+ ----
400
+ # bad
401
+ assert_raises(MyError) do
402
+ foo
403
+ bar
404
+ end
405
+
406
+ # good
407
+ assert_raises(MyError) do
408
+ foo
409
+ end
410
+
411
+ # good
412
+ assert_raises(MyError) do
413
+ foo do
414
+ bar
415
+ baz
416
+ end
417
+ end
418
+ ----
419
+
382
420
  == Minitest/AssertRespondTo
383
421
 
384
422
  |===
@@ -39,13 +39,7 @@ module RuboCop
39
39
  private
40
40
 
41
41
  def test_path
42
- File.join(
43
- 'test',
44
- 'rubocop',
45
- 'cop',
46
- 'minitest',
47
- "#{snake_case(badge.cop_name.to_s)}_test.rb"
48
- )
42
+ File.join('test', 'rubocop', 'cop', 'minitest', "#{snake_case(badge.cop_name.to_s)}_test.rb")
49
43
  end
50
44
 
51
45
  def generated_test
@@ -19,7 +19,7 @@ module RuboCop
19
19
  include InDeltaMixin
20
20
  extend AutoCorrector
21
21
 
22
- RESTRICT_ON_SEND = %i[assert_equal].freeze
22
+ RESTRICT_ON_SEND = %i[assert_equal].freeze # rubocop:disable InternalAffairs/UselessRestrictOnSend
23
23
 
24
24
  def_node_matcher :equal_floats_call, <<~PATTERN
25
25
  (send nil? :assert_equal $_ $_ $...)
@@ -21,7 +21,7 @@ module RuboCop
21
21
  extend AutoCorrector
22
22
 
23
23
  MSG = 'Prefer using `assert_predicate(%<new_arguments>s)`.'
24
- RESTRICT_ON_SEND = %i[assert].freeze
24
+ RESTRICT_ON_SEND = %i[assert].freeze # rubocop:disable InternalAffairs/UselessRestrictOnSend
25
25
 
26
26
  private
27
27
 
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Minitest
6
+ # Enforces the block body of `assert_raises { ... }` to be reduced to only the raising code.
7
+ #
8
+ # @example
9
+ # # bad
10
+ # assert_raises(MyError) do
11
+ # foo
12
+ # bar
13
+ # end
14
+ #
15
+ # # good
16
+ # assert_raises(MyError) do
17
+ # foo
18
+ # end
19
+ #
20
+ # # good
21
+ # assert_raises(MyError) do
22
+ # foo do
23
+ # bar
24
+ # baz
25
+ # end
26
+ # end
27
+ #
28
+ class AssertRaisesCompoundBody < Base
29
+ MSG = 'Reduce `assert_raises` block body to contain only the raising code.'
30
+
31
+ def on_block(node)
32
+ return unless node.method?(:assert_raises) && multi_statement_begin?(node.body)
33
+
34
+ add_offense(node)
35
+ end
36
+
37
+ private
38
+
39
+ def multi_statement_begin?(node)
40
+ node.begin_type? && node.children.size > 1
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -44,8 +44,7 @@ module RuboCop
44
44
  private
45
45
 
46
46
  def preferred_usage(first_arg, second_arg, custom_message = nil)
47
- [first_arg, second_arg, custom_message]
48
- .compact.map(&:source).join(', ')
47
+ [first_arg, second_arg, custom_message].compact.map(&:source).join(', ')
49
48
  end
50
49
 
51
50
  def original_usage(first_part, custom_message)
@@ -19,7 +19,7 @@ module RuboCop
19
19
  include InDeltaMixin
20
20
  extend AutoCorrector
21
21
 
22
- RESTRICT_ON_SEND = %i[refute_equal].freeze
22
+ RESTRICT_ON_SEND = %i[refute_equal].freeze # rubocop:disable InternalAffairs/UselessRestrictOnSend
23
23
 
24
24
  def_node_matcher :equal_floats_call, <<~PATTERN
25
25
  (send nil? :refute_equal $_ $_ $...)
@@ -21,7 +21,7 @@ module RuboCop
21
21
  extend AutoCorrector
22
22
 
23
23
  MSG = 'Prefer using `refute_predicate(%<new_arguments>s)`.'
24
- RESTRICT_ON_SEND = %i[refute].freeze
24
+ RESTRICT_ON_SEND = %i[refute].freeze # rubocop:disable InternalAffairs/UselessRestrictOnSend
25
25
 
26
26
  private
27
27
 
@@ -11,6 +11,7 @@ require_relative 'minitest/assert_empty_literal'
11
11
  require_relative 'minitest/assert_equal'
12
12
  require_relative 'minitest/assert_in_delta'
13
13
  require_relative 'minitest/assert_predicate'
14
+ require_relative 'minitest/assert_raises_compound_body'
14
15
  require_relative 'minitest/assert_with_expected_argument'
15
16
  require_relative 'minitest/assertion_in_lifecycle_hook'
16
17
  require_relative 'minitest/assert_kind_of'
@@ -11,30 +11,21 @@ module RuboCop
11
11
  def first_argument_range(node)
12
12
  first_argument = node.first_argument
13
13
 
14
- range_between(
15
- first_argument.source_range.begin_pos,
16
- first_argument.source_range.end_pos
17
- )
14
+ range_between(first_argument.source_range.begin_pos, first_argument.source_range.end_pos)
18
15
  end
19
16
 
20
17
  def first_and_second_arguments_range(node)
21
18
  first_argument = node.first_argument
22
19
  second_argument = node.arguments[1]
23
20
 
24
- range_between(
25
- first_argument.source_range.begin_pos,
26
- second_argument.source_range.end_pos
27
- )
21
+ range_between(first_argument.source_range.begin_pos, second_argument.source_range.end_pos)
28
22
  end
29
23
 
30
24
  def all_arguments_range(node)
31
25
  first_argument = node.first_argument
32
26
  last_argument = node.arguments.last
33
27
 
34
- range_between(
35
- first_argument.source_range.begin_pos,
36
- last_argument.source_range.end_pos
37
- )
28
+ range_between(first_argument.source_range.begin_pos, last_argument.source_range.end_pos)
38
29
  end
39
30
  end
40
31
  end
@@ -6,7 +6,6 @@ module RuboCop
6
6
  # Common functionality for `Minitest/AssertPredicate` and `Minitest/RefutePredicate` cops.
7
7
  module PredicateAssertionHandleable
8
8
  MSG = 'Prefer using `%<assertion_type>s_predicate(%<new_arguments>s)`.'
9
- RESTRICT_ON_SEND = %i[assert].freeze
10
9
 
11
10
  def on_send(node)
12
11
  return unless (arguments = peel_redundant_parentheses_from(node.arguments))
@@ -46,10 +45,7 @@ module RuboCop
46
45
  def offense_message(arguments)
47
46
  message_argument = arguments.last if arguments.first != arguments.last
48
47
 
49
- new_arguments = [
50
- new_arguments(arguments),
51
- message_argument&.source
52
- ].flatten.compact.join(', ')
48
+ new_arguments = [new_arguments(arguments), message_argument&.source].flatten.compact.join(', ')
53
49
 
54
50
  format(MSG, assertion_type: assertion_type, new_arguments: new_arguments)
55
51
  end
@@ -27,7 +27,7 @@ module RuboCop
27
27
  # end
28
28
  # RUBY
29
29
  #
30
- # Auto-correction can be tested using `assert_correction` after
30
+ # Autocorrection can be tested using `assert_correction` after
31
31
  # `assert_offense`.
32
32
  #
33
33
  # @example `assert_offense` and `assert_correction`
@@ -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.20.1'
7
+ STRING = '0.21.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
+ * [#109](https://github.com/rubocop/rubocop-minitest/issues/109): Add new `Minitest/AssertRaisesCompoundBody` cop. ([@fatkodima][])
4
+
5
+ [@fatkodima]: https://github.com/fatkodima
data/tasks/changelog.rb CHANGED
@@ -30,7 +30,7 @@ class Changelog
30
30
  end
31
31
 
32
32
  def write
33
- Dir.mkdir(ENTRIES_PATH) unless Dir.exist?(ENTRIES_PATH)
33
+ FileUtils.mkdir_p(ENTRIES_PATH)
34
34
  File.write(path, content)
35
35
  path
36
36
  end
@@ -22,7 +22,7 @@ end
22
22
 
23
23
  desc 'Syntax check for the documentation comments'
24
24
  task documentation_syntax_check: :yard_for_generate_documentation do
25
- require 'parser/ruby30'
25
+ require 'parser/ruby31'
26
26
 
27
27
  ok = true
28
28
  YARD::Registry.load!
@@ -37,7 +37,7 @@ task documentation_syntax_check: :yard_for_generate_documentation do
37
37
  examples.to_a.each do |example|
38
38
  buffer = Parser::Source::Buffer.new('<code>', 1)
39
39
  buffer.source = example.text
40
- parser = Parser::Ruby30.new(RuboCop::AST::Builder.new)
40
+ parser = Parser::Ruby31.new(RuboCop::AST::Builder.new)
41
41
  parser.diagnostics.all_errors_are_fatal = true
42
42
  parser.parse(buffer)
43
43
  rescue Parser::SyntaxError => e
@@ -38,10 +38,7 @@ namespace :cut_release do
38
38
  antora_metadata = File.read('docs/antora.yml')
39
39
 
40
40
  File.open('docs/antora.yml', 'w') do |f|
41
- f << antora_metadata.sub(
42
- 'version: ~',
43
- "version: '#{version_sans_patch(new_version)}'"
44
- )
41
+ f << antora_metadata.sub('version: ~', "version: '#{version_sans_patch(new_version)}'")
45
42
  end
46
43
  end
47
44
 
@@ -52,8 +49,7 @@ namespace :cut_release do
52
49
  # Replace `<<next>>` (and variations) with version being cut.
53
50
  def update_cop_versions(_old_version, new_version)
54
51
  update_file('config/default.yml') do |default|
55
- default.gsub(/['"]?<<\s*next\s*>>['"]?/i,
56
- "'#{version_sans_patch(new_version)}'")
52
+ default.gsub(/['"]?<<\s*next\s*>>['"]?/i, "'#{version_sans_patch(new_version)}'")
57
53
  end
58
54
  end
59
55
 
@@ -70,8 +66,7 @@ namespace :cut_release do
70
66
 
71
67
  def user_links(text)
72
68
  names = text.scan(/\[@(\S+)\]\[\]/).map(&:first).uniq
73
- names.map { |name| "[@#{name}]: https://github.com/#{name}" }
74
- .join("\n")
69
+ names.map { |name| "[@#{name}]: https://github.com/#{name}" }.join("\n")
75
70
  end
76
71
 
77
72
  def run(release_type)
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.20.1
4
+ version: 0.21.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-06-13 00:00:00.000000000 Z
13
+ date: 2022-07-31 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rubocop
@@ -103,6 +103,7 @@ files:
103
103
  - lib/rubocop/cop/minitest/assert_output.rb
104
104
  - lib/rubocop/cop/minitest/assert_path_exists.rb
105
105
  - lib/rubocop/cop/minitest/assert_predicate.rb
106
+ - lib/rubocop/cop/minitest/assert_raises_compound_body.rb
106
107
  - lib/rubocop/cop/minitest/assert_respond_to.rb
107
108
  - lib/rubocop/cop/minitest/assert_silent.rb
108
109
  - lib/rubocop/cop/minitest/assert_truthy.rb
@@ -168,6 +169,7 @@ files:
168
169
  - relnotes/v0.2.1.md
169
170
  - relnotes/v0.20.0.md
170
171
  - relnotes/v0.20.1.md
172
+ - relnotes/v0.21.0.md
171
173
  - relnotes/v0.3.0.md
172
174
  - relnotes/v0.4.0.md
173
175
  - relnotes/v0.4.1.md
@@ -192,7 +194,7 @@ metadata:
192
194
  homepage_uri: https://docs.rubocop.org/rubocop-minitest/
193
195
  changelog_uri: https://github.com/rubocop/rubocop-minitest/blob/master/CHANGELOG.md
194
196
  source_code_uri: https://github.com/rubocop/rubocop-minitest
195
- documentation_uri: https://docs.rubocop.org/rubocop-minitest/0.20
197
+ documentation_uri: https://docs.rubocop.org/rubocop-minitest/0.21
196
198
  bug_tracker_uri: https://github.com/rubocop/rubocop-minitest/issues
197
199
  rubygems_mfa_required: 'true'
198
200
  post_install_message: