rubocop-minitest 0.34.5 → 0.35.1

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: cc9ea3b370ec30f86a9e1ddb422255552f643a605b6e744518afcfa1e6ae6de0
4
- data.tar.gz: ba67151e3d30de7f5634ef62feb6663fb0109c69886bdf231417dea06a55ba99
3
+ metadata.gz: '05352938661fc7fcd76a982a2a9154061c503eac54de9f2de2e0f358d8e166a4'
4
+ data.tar.gz: 38db4cb7b31a2829857ccd97f57d4991a482ce7fd7406032bbcf680051581075
5
5
  SHA512:
6
- metadata.gz: d7ab44585e54b9cd0cd85d8e36adfd9ba9f9a7b560c791e15af082691e391a38f313857f323eb897c831d277d73b67e13707cdb76db45bce8cf38286099d7640
7
- data.tar.gz: d592eb50f633074ac727f0fb493d734ca70320ff8fb9441dfab46b45916a7d730a5e439486642755cc83797bacbdfaf85cbb6b6cc95415a491230f64e2645102
6
+ metadata.gz: a0935959142328adc6acedeccabe3abda0cf0284de0a4069a3612101d2cccd67d5374c343f2f3de176c05d9a7db6cc2f85a63eae59c826a888bea6d0505515ae
7
+ data.tar.gz: 033b27f081581b35cc46c55fcea3ac3a2c09c069fe35d0bb41635bbaea4626cbb89b5ff4fa892ec32a9ae8df8f9f9106edb0ac9e4dd7ca3125e218410bb4dc42
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # RuboCop Minitest
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/rubocop-minitest.svg)](https://badge.fury.io/rb/rubocop-minitest)
4
- [![CircleCI](https://circleci.com/gh/rubocop/rubocop-minitest.svg?style=svg)](https://circleci.com/gh/rubocop/rubocop-minitest)
4
+ [![CI](https://github.com/rubocop/rubocop-minitest/actions/workflows/test.yml/badge.svg)](https://github.com/rubocop/rubocop-minitest/actions/workflows/test.yml)
5
5
 
6
6
  A [RuboCop](https://github.com/rubocop/rubocop) extension focused on enforcing [Minitest](https://github.com/minitest/minitest) best practices and coding conventions.
7
7
  The library is based on the guidelines outlined in the community [Minitest Style Guide](https://minitest.rubystyle.guide).
data/config/default.yml CHANGED
@@ -146,6 +146,12 @@ Minitest/EmptyLineBeforeAssertionMethods:
146
146
  Enabled: pending
147
147
  VersionAdded: '0.23'
148
148
 
149
+ Minitest/Focus:
150
+ Description: 'Checks for focused tests.'
151
+ Enabled: pending
152
+ AutoCorrect: contextual
153
+ VersionAdded: '0.35'
154
+
149
155
  Minitest/GlobalExpectations:
150
156
  Description: 'This cop checks for deprecated global expectations.'
151
157
  StyleGuide: 'https://minitest.rubystyle.guide#global-expectations'
@@ -22,7 +22,7 @@ module RuboCop
22
22
  RESTRICT_ON_SEND = %i[assert_equal].freeze
23
23
 
24
24
  def_node_matcher :assert_equal_with_empty_literal, <<~PATTERN
25
- (send nil? :assert_equal ${hash array} $...)
25
+ (send nil? :assert_equal ${hash array} $_+)
26
26
  PATTERN
27
27
 
28
28
  def on_send(node)
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Minitest
6
+ # Enforces tests are not focused.
7
+ #
8
+ # @example
9
+ # # bad
10
+ # focus test 'foo' do
11
+ # end
12
+ #
13
+ # # bad
14
+ # focus
15
+ # test 'foo' do
16
+ # end
17
+ #
18
+ # # good
19
+ # test 'foo' do
20
+ # end
21
+ #
22
+ class Focus < Base
23
+ extend AutoCorrector
24
+ include RangeHelp
25
+
26
+ MSG = 'Remove `focus` from tests.'
27
+ RESTRICT_ON_SEND = [:focus].freeze
28
+
29
+ def_node_matcher :focused?, <<~PATTERN
30
+ (send nil? :focus ...)
31
+ PATTERN
32
+
33
+ def on_send(node)
34
+ return if node.receiver
35
+
36
+ add_offense(node.loc.selector) do |corrector|
37
+ range = if node.arguments.none?
38
+ range_by_whole_lines(node.source_range, include_final_newline: true)
39
+ else
40
+ node.loc.selector.join(node.first_argument.source_range.begin)
41
+ end
42
+
43
+ corrector.remove(range)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -28,11 +28,12 @@ module RuboCop
28
28
  # end
29
29
  #
30
30
  class MultipleAssertions < Base
31
- include ConfigurableMax
32
31
  include MinitestExplorationHelpers
33
32
 
34
33
  MSG = 'Test case has too many assertions [%<total>d/%<max>d].'
35
34
 
35
+ exclude_limit 'Max'
36
+
36
37
  def on_class(class_node)
37
38
  return unless test_class?(class_node)
38
39
 
@@ -30,6 +30,7 @@ require_relative 'minitest/assert_silent'
30
30
  require_relative 'minitest/assert_truthy'
31
31
  require_relative 'minitest/duplicate_test_run'
32
32
  require_relative 'minitest/empty_line_before_assertion_methods'
33
+ require_relative 'minitest/focus'
33
34
  require_relative 'minitest/non_executable_test_method'
34
35
  require_relative 'minitest/redundant_message_argument'
35
36
  require_relative 'minitest/return_in_test_method'
@@ -116,9 +116,9 @@ module RuboCop
116
116
 
117
117
  @processed_source = parse_source!(expected_annotations.plain_source, file)
118
118
 
119
- offenses = _investigate(@cop, @processed_source)
119
+ @offenses = _investigate(@cop, @processed_source)
120
120
 
121
- actual_annotations = expected_annotations.with_offense_annotations(offenses)
121
+ actual_annotations = expected_annotations.with_offense_annotations(@offenses)
122
122
 
123
123
  assert_equal(expected_annotations.to_s, actual_annotations.to_s)
124
124
  end
@@ -143,7 +143,7 @@ module RuboCop
143
143
  break corrected_source if @last_corrector.empty? || corrected_source == @processed_source.buffer.source
144
144
 
145
145
  if iteration > RuboCop::Runner::MAX_ITERATIONS
146
- raise RuboCop::Runner::InfiniteCorrectionLoop.new(@processed_source.path, [])
146
+ raise RuboCop::Runner::InfiniteCorrectionLoop.new(@processed_source.path, [@offenses])
147
147
  end
148
148
 
149
149
  # Prepare for next loop
@@ -155,6 +155,20 @@ module RuboCop
155
155
  assert_equal(correction, new_source)
156
156
  end
157
157
 
158
+ def assert_no_corrections
159
+ raise '`assert_no_corrections` must follow `assert_offense`' unless @processed_source
160
+
161
+ return if @last_corrector.empty?
162
+
163
+ # This is just here for a pretty diff if the source actually got changed
164
+ new_source = @last_corrector.rewrite
165
+ assert_equal(@processed_source.buffer.source, new_source)
166
+
167
+ # There is an infinite loop if a corrector is present that did not make
168
+ # any changes. It will cause the same offense/correction on the next loop.
169
+ raise RuboCop::Runner::InfiniteCorrectionLoop.new(@processed_source.path, [@offenses])
170
+ end
171
+
158
172
  def setup_assertion
159
173
  RuboCop::Formatter::DisabledConfigFormatter.config_to_allow_offenses = {}
160
174
  RuboCop::Formatter::DisabledConfigFormatter.detected_styles = {}
@@ -186,15 +200,9 @@ module RuboCop
186
200
  file = file.path
187
201
  end
188
202
 
189
- processed_source = RuboCop::ProcessedSource.new(source, ruby_version, file)
190
-
191
- # Follow up https://github.com/rubocop/rubocop/pull/10987.
192
- # When support for RuboCop 1.37.1 ends, this condition can be removed.
193
- if processed_source.respond_to?(:config) && processed_source.respond_to?(:registry)
194
- processed_source.config = configuration
195
- processed_source.registry = registry
196
- end
197
-
203
+ processed_source = RuboCop::ProcessedSource.new(source, ruby_version, file, parser_engine: parser_engine)
204
+ processed_source.config = configuration
205
+ processed_source.registry = registry
198
206
  processed_source
199
207
  end
200
208
 
@@ -216,7 +224,12 @@ module RuboCop
216
224
  end
217
225
 
218
226
  def ruby_version
219
- RuboCop::TargetRuby::DEFAULT_VERSION
227
+ # Prism supports parsing Ruby 3.3+.
228
+ ENV['PARSER_ENGINE'] == 'parser_prism' ? 3.3 : RuboCop::TargetRuby::DEFAULT_VERSION
229
+ end
230
+
231
+ def parser_engine
232
+ ENV.fetch('PARSER_ENGINE', :parser_whitequark).to_sym
220
233
  end
221
234
  end
222
235
  # rubocop:enable Metrics/ModuleLength
@@ -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.34.5'
7
+ STRING = '0.35.1'
8
8
 
9
9
  def self.document_version
10
10
  STRING.match('\d+\.\d+').to_s
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.34.5
4
+ version: 0.35.1
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: 2024-01-20 00:00:00.000000000 Z
13
+ date: 2024-07-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rubocop
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ">="
20
20
  - !ruby/object:Gem::Version
21
- version: '1.39'
21
+ version: '1.61'
22
22
  - - "<"
23
23
  - !ruby/object:Gem::Version
24
24
  version: '2.0'
@@ -28,7 +28,7 @@ dependencies:
28
28
  requirements:
29
29
  - - ">="
30
30
  - !ruby/object:Gem::Version
31
- version: '1.39'
31
+ version: '1.61'
32
32
  - - "<"
33
33
  - !ruby/object:Gem::Version
34
34
  version: '2.0'
@@ -38,7 +38,7 @@ dependencies:
38
38
  requirements:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
- version: 1.30.0
41
+ version: 1.31.1
42
42
  - - "<"
43
43
  - !ruby/object:Gem::Version
44
44
  version: '2.0'
@@ -48,7 +48,7 @@ dependencies:
48
48
  requirements:
49
49
  - - ">="
50
50
  - !ruby/object:Gem::Version
51
- version: 1.30.0
51
+ version: 1.31.1
52
52
  - - "<"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2.0'
@@ -88,6 +88,7 @@ files:
88
88
  - lib/rubocop/cop/minitest/assertion_in_lifecycle_hook.rb
89
89
  - lib/rubocop/cop/minitest/duplicate_test_run.rb
90
90
  - lib/rubocop/cop/minitest/empty_line_before_assertion_methods.rb
91
+ - lib/rubocop/cop/minitest/focus.rb
91
92
  - lib/rubocop/cop/minitest/global_expectations.rb
92
93
  - lib/rubocop/cop/minitest/lifecycle_hooks_order.rb
93
94
  - lib/rubocop/cop/minitest/literal_as_actual_argument.rb
@@ -139,7 +140,7 @@ metadata:
139
140
  homepage_uri: https://docs.rubocop.org/rubocop-minitest/
140
141
  changelog_uri: https://github.com/rubocop/rubocop-minitest/blob/master/CHANGELOG.md
141
142
  source_code_uri: https://github.com/rubocop/rubocop-minitest
142
- documentation_uri: https://docs.rubocop.org/rubocop-minitest/0.34
143
+ documentation_uri: https://docs.rubocop.org/rubocop-minitest/0.35
143
144
  bug_tracker_uri: https://github.com/rubocop/rubocop-minitest/issues
144
145
  rubygems_mfa_required: 'true'
145
146
  post_install_message: