rubocop-rspec_parity 1.1.0 → 1.2.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 +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/rubocop/cop/rspec_parity/sufficient_contexts.rb +35 -22
- data/lib/rubocop/rspec_parity/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2d2f62960e2b46b31972221b577d79aed5b54db2f90b6d9cf277dcaa9b432e92
|
|
4
|
+
data.tar.gz: 320594b7e229f9910535fe7e30233a1f0d56a286676cc8fc636cd782f1c8f113
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: da7f6916ecd8946f04ffdf8d67af1c566cbee961d120e2e1ad8fd2d78c8b0238989d4321b5eb5f3179aee0d28197bc88284283bffed042019001cffbaf2d2fc3
|
|
7
|
+
data.tar.gz: 43653613dfcef10d0a7c21485171a9532c045372354fc1df0ae244d436e4076568696b3b38591e015d0cd75360d39762d19243bd9ab1424a089530f2b04cd693
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [1.2.0] - 2026-02-09
|
|
4
|
+
|
|
5
|
+
Added: `SufficientContexts` now counts direct `it` blocks alongside `context` blocks as an additional implicit context
|
|
6
|
+
|
|
3
7
|
## [1.1.0] - 2026-02-06
|
|
4
8
|
|
|
5
9
|
Added: Support for checking wildcard spec files (`<model>_*_spec.rb`) in addition to base spec file, with automatic class validation
|
|
@@ -218,18 +218,25 @@ module RuboCop
|
|
|
218
218
|
|
|
219
219
|
def count_contexts_for_method(spec_content, method_name)
|
|
220
220
|
method_pattern = Regexp.escape(method_name)
|
|
221
|
-
context_count, has_examples = parse_spec_content(spec_content, method_pattern)
|
|
221
|
+
context_count, has_examples, has_direct_examples = parse_spec_content(spec_content, method_pattern)
|
|
222
222
|
|
|
223
|
-
|
|
224
|
-
|
|
223
|
+
if context_count.positive? && has_direct_examples
|
|
224
|
+
context_count + 1
|
|
225
|
+
elsif context_count.zero? && has_examples
|
|
226
|
+
1
|
|
227
|
+
else
|
|
228
|
+
context_count
|
|
229
|
+
end
|
|
225
230
|
end
|
|
226
231
|
|
|
227
232
|
# rubocop:disable Metrics/MethodLength
|
|
228
|
-
def parse_spec_content(spec_content, method_pattern)
|
|
233
|
+
def parse_spec_content(spec_content, method_pattern) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
229
234
|
in_method_block = false
|
|
230
235
|
context_count = 0
|
|
231
236
|
has_examples = false
|
|
237
|
+
has_direct_examples = false
|
|
232
238
|
base_indent = 0
|
|
239
|
+
child_indent = nil
|
|
233
240
|
|
|
234
241
|
spec_content.each_line do |line|
|
|
235
242
|
current_indent = line[/^\s*/].length
|
|
@@ -237,34 +244,30 @@ module RuboCop
|
|
|
237
244
|
if matches_method_describe?(line, method_pattern)
|
|
238
245
|
in_method_block = true
|
|
239
246
|
base_indent = current_indent
|
|
247
|
+
child_indent = nil
|
|
240
248
|
next
|
|
241
249
|
end
|
|
242
250
|
|
|
243
251
|
if in_method_block
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
)
|
|
252
|
+
if exiting_block?(line, current_indent, base_indent)
|
|
253
|
+
in_method_block = false
|
|
254
|
+
elsif nested_context?(line)
|
|
255
|
+
child_indent ||= current_indent
|
|
256
|
+
context_count += 1
|
|
257
|
+
elsif nested_example?(line)
|
|
258
|
+
has_examples = true
|
|
259
|
+
child_indent ||= current_indent
|
|
260
|
+
has_direct_examples = true if current_indent == child_indent
|
|
261
|
+
end
|
|
247
262
|
elsif matches_context_pattern?(line, method_pattern)
|
|
248
263
|
context_count += 1
|
|
249
264
|
end
|
|
250
265
|
end
|
|
251
266
|
|
|
252
|
-
[context_count, has_examples]
|
|
267
|
+
[context_count, has_examples, has_direct_examples]
|
|
253
268
|
end
|
|
254
269
|
# rubocop:enable Metrics/MethodLength
|
|
255
270
|
|
|
256
|
-
def process_method_block_line(line, current_indent, base_indent, context_count, has_examples)
|
|
257
|
-
in_method_block = !exiting_block?(line, current_indent, base_indent)
|
|
258
|
-
|
|
259
|
-
if nested_context?(line)
|
|
260
|
-
context_count += 1
|
|
261
|
-
elsif nested_example?(line)
|
|
262
|
-
has_examples = true
|
|
263
|
-
end
|
|
264
|
-
|
|
265
|
-
[context_count, has_examples, in_method_block]
|
|
266
|
-
end
|
|
267
|
-
|
|
268
271
|
def matches_method_describe?(line, method_pattern)
|
|
269
272
|
line =~ /^\s*describe\s+['"](?:#|\.)?#{method_pattern}['"]/ ||
|
|
270
273
|
line =~ /^\s*describe\s+:#{method_pattern}/
|
|
@@ -434,6 +437,8 @@ module RuboCop
|
|
|
434
437
|
base_indent = lines[describe_line_index].match(/^(\s*)/)[1].length
|
|
435
438
|
context_count = 0
|
|
436
439
|
has_examples = false
|
|
440
|
+
has_direct_examples = false
|
|
441
|
+
child_indent = nil
|
|
437
442
|
|
|
438
443
|
lines[(describe_line_index + 1)..].each do |line|
|
|
439
444
|
indent = line.match(/^(\s*)/)[1].length
|
|
@@ -442,14 +447,22 @@ module RuboCop
|
|
|
442
447
|
next unless indent > base_indent
|
|
443
448
|
|
|
444
449
|
if line.match?(/^\s*(?:context|describe)\s+/)
|
|
450
|
+
child_indent ||= indent
|
|
445
451
|
context_count += 1
|
|
446
452
|
elsif line.match?(/^\s*(?:it|example|specify)\s+/)
|
|
447
453
|
has_examples = true
|
|
454
|
+
child_indent ||= indent
|
|
455
|
+
has_direct_examples = true if indent == child_indent
|
|
448
456
|
end
|
|
449
457
|
end
|
|
450
458
|
|
|
451
|
-
|
|
452
|
-
|
|
459
|
+
if context_count.positive? && has_direct_examples
|
|
460
|
+
context_count + 1
|
|
461
|
+
elsif context_count.zero? && has_examples
|
|
462
|
+
1
|
|
463
|
+
else
|
|
464
|
+
context_count
|
|
465
|
+
end
|
|
453
466
|
end
|
|
454
467
|
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
|
455
468
|
end
|