rubocop-minitest 0.35.0 → 0.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ad79ea9356e7da6ffabb9e38d689691f31a87b3bffc156e77c071290d20aec1
|
4
|
+
data.tar.gz: c142cdc5b3e0855e1d54bd6899d5a01c87b9efcc7abb60ebb6c4852c763a1199
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fda798b03c1883da9465da94ec0d70e3170f5d71a624dc29a73559f14a9888e1b43c78f1e888ef2e0e2c40a05d6f6b5cb6d2a9b5315a48136fc02b172e6b72f4
|
7
|
+
data.tar.gz: daa8a4405a1815cfafd52809fce1f6cff4ac68b8af4b63038fab69da0594e8c84a8a60b2a5df40e2c89f16a04df578674e82060745ebad949297558d4b933ddc
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# RuboCop Minitest
|
2
2
|
|
3
3
|
[](https://badge.fury.io/rb/rubocop-minitest)
|
4
|
-
[](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).
|
@@ -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
|
|
@@ -74,7 +75,11 @@ module RuboCop
|
|
74
75
|
end
|
75
76
|
|
76
77
|
def assertions_count_in_assignment(node)
|
77
|
-
|
78
|
+
unless node.masgn_type?
|
79
|
+
return 0 unless node.expression # for-style loop
|
80
|
+
|
81
|
+
return assertions_count_based_on_type(node.expression)
|
82
|
+
end
|
78
83
|
|
79
84
|
rhs = node.children.last
|
80
85
|
|
@@ -75,7 +75,9 @@ module RuboCop
|
|
75
75
|
private
|
76
76
|
|
77
77
|
def find_skip(node)
|
78
|
-
|
78
|
+
return unless (body = node.node_parts.first)
|
79
|
+
|
80
|
+
body.descendants.detect { |n| n.send_type? && n.receiver.nil? && n.method?(:skip) }
|
79
81
|
end
|
80
82
|
|
81
83
|
def use_skip_in_rescue?(skip_method)
|
@@ -75,11 +75,13 @@ module RuboCop
|
|
75
75
|
module AssertOffense
|
76
76
|
private
|
77
77
|
|
78
|
-
def
|
79
|
-
|
80
|
-
|
78
|
+
def cop
|
79
|
+
@cop ||= begin
|
80
|
+
cop_name = self.class.to_s.delete_suffix('Test')
|
81
|
+
raise "Cop not defined: #{cop_name}" unless RuboCop::Cop::Minitest.const_defined?(cop_name)
|
81
82
|
|
82
|
-
|
83
|
+
RuboCop::Cop::Minitest.const_get(cop_name).new(configuration)
|
84
|
+
end
|
83
85
|
end
|
84
86
|
|
85
87
|
def format_offense(source, **replacements)
|
@@ -95,7 +97,7 @@ module RuboCop
|
|
95
97
|
def assert_no_offenses(source, file = nil)
|
96
98
|
setup_assertion
|
97
99
|
|
98
|
-
offenses = inspect_source(source,
|
100
|
+
offenses = inspect_source(source, cop, file)
|
99
101
|
|
100
102
|
expected_annotations = RuboCop::RSpec::ExpectOffense::AnnotatedSource.parse(source)
|
101
103
|
actual_annotations = expected_annotations.with_offense_annotations(offenses)
|
@@ -105,8 +107,7 @@ module RuboCop
|
|
105
107
|
|
106
108
|
def assert_offense(source, file = nil, **replacements)
|
107
109
|
setup_assertion
|
108
|
-
|
109
|
-
@cop.instance_variable_get(:@options)[:autocorrect] = true
|
110
|
+
enable_autocorrect
|
110
111
|
|
111
112
|
source = format_offense(source, **replacements)
|
112
113
|
expected_annotations = RuboCop::RSpec::ExpectOffense::AnnotatedSource.parse(source)
|
@@ -116,9 +117,9 @@ module RuboCop
|
|
116
117
|
|
117
118
|
@processed_source = parse_source!(expected_annotations.plain_source, file)
|
118
119
|
|
119
|
-
offenses = _investigate(
|
120
|
+
@offenses = _investigate(cop, @processed_source)
|
120
121
|
|
121
|
-
actual_annotations = expected_annotations.with_offense_annotations(offenses)
|
122
|
+
actual_annotations = expected_annotations.with_offense_annotations(@offenses)
|
122
123
|
|
123
124
|
assert_equal(expected_annotations.to_s, actual_annotations.to_s)
|
124
125
|
end
|
@@ -130,6 +131,10 @@ module RuboCop
|
|
130
131
|
report.offenses
|
131
132
|
end
|
132
133
|
|
134
|
+
def enable_autocorrect
|
135
|
+
cop.instance_variable_get(:@options)[:autocorrect] = true
|
136
|
+
end
|
137
|
+
|
133
138
|
def assert_correction(correction, loop: true)
|
134
139
|
raise '`assert_correction` must follow `assert_offense`' unless @processed_source
|
135
140
|
|
@@ -143,18 +148,32 @@ module RuboCop
|
|
143
148
|
break corrected_source if @last_corrector.empty? || corrected_source == @processed_source.buffer.source
|
144
149
|
|
145
150
|
if iteration > RuboCop::Runner::MAX_ITERATIONS
|
146
|
-
raise RuboCop::Runner::InfiniteCorrectionLoop.new(@processed_source.path, [])
|
151
|
+
raise RuboCop::Runner::InfiniteCorrectionLoop.new(@processed_source.path, [@offenses])
|
147
152
|
end
|
148
153
|
|
149
154
|
# Prepare for next loop
|
150
155
|
@processed_source = parse_source!(corrected_source, @processed_source.path)
|
151
156
|
|
152
|
-
_investigate(
|
157
|
+
_investigate(cop, @processed_source)
|
153
158
|
end
|
154
159
|
|
155
160
|
assert_equal(correction, new_source)
|
156
161
|
end
|
157
162
|
|
163
|
+
def assert_no_corrections
|
164
|
+
raise '`assert_no_corrections` must follow `assert_offense`' unless @processed_source
|
165
|
+
|
166
|
+
return if @last_corrector.empty?
|
167
|
+
|
168
|
+
# This is just here for a pretty diff if the source actually got changed
|
169
|
+
new_source = @last_corrector.rewrite
|
170
|
+
assert_equal(@processed_source.buffer.source, new_source)
|
171
|
+
|
172
|
+
# There is an infinite loop if a corrector is present that did not make
|
173
|
+
# any changes. It will cause the same offense/correction on the next loop.
|
174
|
+
raise RuboCop::Runner::InfiniteCorrectionLoop.new(@processed_source.path, [@offenses])
|
175
|
+
end
|
176
|
+
|
158
177
|
def setup_assertion
|
159
178
|
RuboCop::Formatter::DisabledConfigFormatter.config_to_allow_offenses = {}
|
160
179
|
RuboCop::Formatter::DisabledConfigFormatter.detected_styles = {}
|
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.
|
4
|
+
version: 0.36.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: 2024-
|
13
|
+
date: 2024-08-31 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rubocop
|
@@ -140,7 +140,7 @@ metadata:
|
|
140
140
|
homepage_uri: https://docs.rubocop.org/rubocop-minitest/
|
141
141
|
changelog_uri: https://github.com/rubocop/rubocop-minitest/blob/master/CHANGELOG.md
|
142
142
|
source_code_uri: https://github.com/rubocop/rubocop-minitest
|
143
|
-
documentation_uri: https://docs.rubocop.org/rubocop-minitest/0.
|
143
|
+
documentation_uri: https://docs.rubocop.org/rubocop-minitest/0.36
|
144
144
|
bug_tracker_uri: https://github.com/rubocop/rubocop-minitest/issues
|
145
145
|
rubygems_mfa_required: 'true'
|
146
146
|
post_install_message:
|