specguard-ruby 0.3.36 → 0.3.37
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/README.md +18 -7
- data/lib/specguard/client/cli.rb +8 -7
- data/lib/specguard/client/file_selector.rb +88 -5
- data/lib/specguard/client/json_reporter.rb +1 -1
- data/lib/specguard/client/scanner.rb +79 -9
- data/lib/specguard/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 950542c2a1d40a8eb323faf2dc844eea25e6e742f8a88e61e4839fc7a1f88ed6
|
|
4
|
+
data.tar.gz: fe909d55df8cf5dfca5459005ddba2ed77a05857ee668d987cee35721042c8e2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: eb2ff61c59c505089c4c4ed8ba02cc12e72b3662a300e828c43e7a91ae976dad04d4d751fc5b0cfbb1aa64ed5dc2311456ef19e065b18dc6b99dd50fb61e4ff0
|
|
7
|
+
data.tar.gz: ea93856dd3ca0a29a690cbcb5f6292a53c7e661bb7ae8e8d24a9d53e37d9c03d1296243b831f705df7345370725b8039d4e29238122b61bae3bea843334571ee
|
data/README.md
CHANGED
|
@@ -59,17 +59,17 @@ See [Shipping the run to SpecGuard](#shipping-the-run-to-specguard) for the sett
|
|
|
59
59
|
|
|
60
60
|
## The linter — `specguard-lint`
|
|
61
61
|
|
|
62
|
-
Validates `# @intent:` annotations in changed (or all) `*_spec.rb` files against the OpenTestIntent
|
|
62
|
+
Validates `# @intent:` annotations in changed (or all) `*_spec.rb` / `*_test.rb` files — and any other `.rb` file under `spec/` or `test/` (shared examples, helpers) that carries an `@intent:` token — against the OpenTestIntent
|
|
63
63
|
JSON Schema. Exits `1` on a malformed annotation — or a well-formed but unreachable one (stacked
|
|
64
64
|
above another comment-form `@intent:` line, so the one-line lookback never claims it; separated
|
|
65
65
|
from its example (`it`, `specify`, `xit`, `fit`, `example`, …) by one blank or ordinary comment line, which puts it out of the lookback's reach;
|
|
66
66
|
directly above an example that carries its own trailing `@intent:`, which extraction prefers, so the
|
|
67
|
-
comment is shadowed;
|
|
67
|
+
comment is shadowed; trailing on a `describe`/`context` group line, which no example's extraction can ever reach; or directly above a `describe`/`context` group line or a shared-example invocation (`it_behaves_like`, `include_examples`, …), which no example can claim either) — and
|
|
68
68
|
**never** fails on a *missing* one (adoption is opt-in and gradual).
|
|
69
69
|
|
|
70
70
|
```bash
|
|
71
71
|
bundle exec specguard-lint --changed # CI mode: only files in the current diff
|
|
72
|
-
bundle exec specguard-lint # one-off audit: every *_spec.rb outside dependency/build directories
|
|
72
|
+
bundle exec specguard-lint # one-off audit: every *_spec.rb / *_test.rb (plus any other .rb under spec/ or test/ carrying @intent:) outside dependency/build directories
|
|
73
73
|
```
|
|
74
74
|
|
|
75
75
|
The default walk is fenced out of dependency and build directories — `node_modules`,
|
|
@@ -79,9 +79,20 @@ directory names, so `spec/vendor_helpers/` is still yours. A bundled Rails tree
|
|
|
79
79
|
specs; the walk neither reports on them nor fails over their annotations, and the
|
|
80
80
|
zero-annotation coverage note counts only files you wrote — the same material
|
|
81
81
|
`--changed` fences out with the same directory list. When the fence removed files, the
|
|
82
|
-
`checked N spec files` line says how many (`skipping M in dependency or build
|
|
82
|
+
`checked N spec/test files` line says how many (`skipping M in dependency or build
|
|
83
83
|
directories`); a file named explicitly on the command line is always checked.
|
|
84
84
|
|
|
85
|
+
Shared-example and helper files — `spec/support/`, `spec/shared_examples/`, `spec/shared/`,
|
|
86
|
+
`spec/helpers/`, `test/shared/`, a bare `spec/spec_helper.rb`, any `.rb` under a top-level `spec/` or
|
|
87
|
+
`test/` — match neither `*_spec.rb` nor `*_test.rb`, yet annotating the `it` inside a `shared_examples` group is the highest-leverage place to
|
|
88
|
+
write an `@intent:` (one annotation covers every including file's rows; a comment above the
|
|
89
|
+
`shared_examples` header or an `it_behaves_like` line is unreachable and fails the lint), so both the default walk and
|
|
90
|
+
`--changed` also select such a `.rb` file — but **only when it contains the
|
|
91
|
+
`@intent:` token**. These directories are full of unannotated helpers; those stay unselected, so they
|
|
92
|
+
neither flood the `N of M checked spec/test files carry no @intent` note nor change any count for a
|
|
93
|
+
repository whose helper files carry no annotations. The same dependency/build fence applies, and in
|
|
94
|
+
`--changed` a token-carrying file counts in the `changed spec/test files` figure like any other.
|
|
95
|
+
|
|
85
96
|
`--changed` is the CI selection mode: it diffs against the **merge base with
|
|
86
97
|
the default branch** (`origin/HEAD`, then `origin/main`/`origin/master`, then
|
|
87
98
|
their local names) — never a bare working-tree-vs-index `git diff`, which is
|
|
@@ -94,7 +105,7 @@ or not the change is committed yet. One `git ls-files --others
|
|
|
94
105
|
code, build output) out of the untracked leg alone — and untracked files obey
|
|
95
106
|
the same scoping as diffed ones, so an
|
|
96
107
|
untracked spec outside the current directory is counted as outside, not
|
|
97
|
-
checked. When the untracked leg contributed, the `checked N spec files changed
|
|
108
|
+
checked. When the untracked leg contributed, the `checked N spec/test files changed
|
|
98
109
|
since <base>` line says `including M untracked`. `--changed` applies the same
|
|
99
110
|
dependency/build directory fence to everything it selects: a tracked file is
|
|
100
111
|
never subject to `.gitignore`, so the diff leg needs the fence regardless —
|
|
@@ -167,7 +178,7 @@ what a parser sees.
|
|
|
167
178
|
| `schema` | the OpenTestIntent schema version the payloads were validated against |
|
|
168
179
|
| `mode` | always `"source"` — annotations in spec sources, the port's name for what this tool does. Not the *selection* mode (`--changed` vs named files), which the document has no field for |
|
|
169
180
|
| `ok` | whether the run passed — derived from the exit code, not recomputed, so the two renderers cannot disagree |
|
|
170
|
-
| `summary.files` | spec files selected: the number the text report's leading `checked N spec file(s)` line states |
|
|
181
|
+
| `summary.files` | spec files selected: the number the text report's leading `checked N spec/test file(s)` line states |
|
|
171
182
|
| `summary.annotations` | annotation sites examined: the number its trailing summary line states. A site whose payload could not be captured or parsed still counts; a file that could not be read contributes none |
|
|
172
183
|
| `summary.failed` | findings with `"ok": false`, read failures included. Note this is **not** the text summary's `M malformed`, which counts malformed annotations and reports unread files in its own clause |
|
|
173
184
|
|
|
@@ -351,7 +362,7 @@ is not a verdict, or emits output that is not a report — is **exit 2**, the li
|
|
|
351
362
|
my job" code. It never becomes exit 1, which means "an annotation is malformed" — or well-formed
|
|
352
363
|
but unreachable: stacked above another comment-form `@intent:` line, so the one-line lookback
|
|
353
364
|
never claims it, separated from its example by one blank or ordinary comment line, shadowed by its
|
|
354
|
-
example's own trailing `@intent:`,
|
|
365
|
+
example's own trailing `@intent:`, trailing on a `describe`/`context` group line, which no example's extraction can ever reach, or directly above a group line or shared-example invocation — and nothing else.
|
|
355
366
|
|
|
356
367
|
## The formatter — `SpecGuard::RSpecFormatter`
|
|
357
368
|
|
data/lib/specguard/client/cli.rb
CHANGED
|
@@ -130,8 +130,9 @@ module SpecGuard
|
|
|
130
130
|
# another comment-form `@intent:` line so the one-line lookback never
|
|
131
131
|
# claims it, separated from its example by one blank/comment line,
|
|
132
132
|
# shadowed by its example's own trailing `@intent:`, or trailing on
|
|
133
|
-
# an example-group line no example's extraction can reach
|
|
134
|
-
#
|
|
133
|
+
# an example-group line no example's extraction can reach, or
|
|
134
|
+
# directly above such a line or a shared-example invocation (SPGD-2137)
|
|
135
|
+
# — a dead contract in every case, and still a failure). The only code produced by
|
|
135
136
|
# inspecting content, and the only path that reaches it is a failed
|
|
136
137
|
# {Linter::Result}.
|
|
137
138
|
EXIT_MALFORMED = 1
|
|
@@ -263,7 +264,7 @@ module SpecGuard
|
|
|
263
264
|
# meaning one file — and the client's document carries only FINDINGS,
|
|
264
265
|
# so a clean file in that subtree appears nowhere and "checked N spec
|
|
265
266
|
# files" can never count what was actually validated. The observed
|
|
266
|
-
# result was a run whose header said `checked 1 spec file`, whose
|
|
267
|
+
# result was a run whose header said `checked 1 spec/test file`, whose
|
|
267
268
|
# summary said `checked 3 @intent annotations`, and whose
|
|
268
269
|
# zero-annotation note claimed the directory carried none — three
|
|
269
270
|
# mutually contradicting sentences, and at its sharpest an exit-0
|
|
@@ -315,7 +316,7 @@ module SpecGuard
|
|
|
315
316
|
# name files this run actually checked.
|
|
316
317
|
def report_selection(selection, json:)
|
|
317
318
|
if selection.empty?
|
|
318
|
-
@stderr.puts "specguard-lint: warning: selected 0 spec files — #{empty_reason(selection)}"
|
|
319
|
+
@stderr.puts "specguard-lint: warning: selected 0 spec/test files — #{empty_reason(selection)}"
|
|
319
320
|
@stderr.puts "specguard-lint: warning: #{selection.note}" if selection.note
|
|
320
321
|
else
|
|
321
322
|
json ? @stderr.puts(selection_line(selection)) : @stdout.puts(selection_line(selection))
|
|
@@ -337,7 +338,7 @@ module SpecGuard
|
|
|
337
338
|
def selection_line(selection)
|
|
338
339
|
untracked = selection.mode == :changed ? selection.stats&.untracked.to_i : 0
|
|
339
340
|
skipped = selection.skipped.to_i
|
|
340
|
-
"specguard-lint: checked #{selection.count} spec file#{'s' unless selection.count == 1}" \
|
|
341
|
+
"specguard-lint: checked #{selection.count} spec/test file#{'s' unless selection.count == 1}" \
|
|
341
342
|
"#{" changed since #{selection.base}" if selection.mode == :changed}" \
|
|
342
343
|
"#{" under #{Dir.pwd}" if selection.mode == :all}" \
|
|
343
344
|
"#{" including #{untracked} untracked" if untracked.positive?}" \
|
|
@@ -399,7 +400,7 @@ module SpecGuard
|
|
|
399
400
|
# clauses are additive, and a selection emptied by several causes says
|
|
400
401
|
# so.
|
|
401
402
|
def changed_excluded_reason(stats, base, skipped)
|
|
402
|
-
matched = "#{stats.spec_matches} changed spec file#{'s' unless stats.spec_matches == 1} against #{base}"
|
|
403
|
+
matched = "#{stats.spec_matches} changed spec/test file#{'s' unless stats.spec_matches == 1} against #{base}"
|
|
403
404
|
|
|
404
405
|
if stats.outside_root.positive?
|
|
405
406
|
reason = "#{matched}, but #{stats.outside_root} #{stats.outside_root == 1 ? 'is' : 'are'} " \
|
|
@@ -509,7 +510,7 @@ module SpecGuard
|
|
|
509
510
|
|
|
510
511
|
verb = bare.length == 1 ? "carries" : "carry"
|
|
511
512
|
@stderr.puts "specguard-lint: note: #{bare.length} of #{selected_files.length} checked " \
|
|
512
|
-
"spec file#{'s' unless selected_files.length == 1} #{verb} no @intent " \
|
|
513
|
+
"spec/test file#{'s' unless selected_files.length == 1} #{verb} no @intent " \
|
|
513
514
|
"annotations: #{bare.join(', ')}"
|
|
514
515
|
end
|
|
515
516
|
|
|
@@ -17,6 +17,23 @@ module SpecGuard
|
|
|
17
17
|
# diff names paths, not directories, and a changed test file is a test
|
|
18
18
|
# file wherever the author put it.
|
|
19
19
|
#
|
|
20
|
+
# == Token-carrying Ruby files under `spec/` and `test/` join
|
|
21
|
+
#
|
|
22
|
+
# Shared-example and helper files (`spec/shared_examples/`, `spec/shared/`,
|
|
23
|
+
# `spec/support/`, `test/shared/`, `test/support/`, a bare `spec/helpers.rb`
|
|
24
|
+
# — any `.rb` under a top-level `spec/` or `test/`) match neither naming
|
|
25
|
+
# convention, yet they are where an `@intent:` annotation does the most
|
|
26
|
+
# work — one annotation on a `shared_examples` group covers every including
|
|
27
|
+
# file's rows — and a malformed one there used to lint green because the
|
|
28
|
+
# linter never opened the file. Both modes therefore also select such a
|
|
29
|
+
# file, but ONLY one that contains the `@intent:` token
|
|
30
|
+
# ({carries_intent_token?}): these directories are full of unannotated
|
|
31
|
+
# helpers, and selecting them all would flood the "N of M checked files
|
|
32
|
+
# carry no @intent" note and change the counts of every repository that
|
|
33
|
+
# keeps plain helpers there. A file with the token but no valid annotation
|
|
34
|
+
# is selected on purpose — that is the malformed case the gate exists to
|
|
35
|
+
# catch.
|
|
36
|
+
#
|
|
20
37
|
# Both modes carry a fixed directory fence ({SKIPPED_DIRECTORIES}):
|
|
21
38
|
# dependency, build-output, scratch and VCS directories are never
|
|
22
39
|
# selected, so a bundled tree's `vendor/bundle/` gem specs are neither
|
|
@@ -186,6 +203,23 @@ module SpecGuard
|
|
|
186
203
|
# in the one mode that answers "what did this branch touch".
|
|
187
204
|
CHANGED_PATTERNS = ["*_spec.rb", "*_test.rb"].freeze
|
|
188
205
|
|
|
206
|
+
# The globs of the default walk's token-carrying files: any Ruby file
|
|
207
|
+
# under the two directories the frameworks own, for the same reason
|
|
208
|
+
# {DEFAULT_GLOB} scopes `*_test.rb` to `test/`. A file matched here
|
|
209
|
+
# (whatever its name or depth, `spec/helpers.rb` included) is selected
|
|
210
|
+
# only when it passes {carries_intent_token?}.
|
|
211
|
+
SUPPORT_GLOB = ["spec/**/*.rb", "test/**/*.rb"].freeze
|
|
212
|
+
|
|
213
|
+
# The two top-level directories a token-carrying Ruby file is recognized
|
|
214
|
+
# under (the `--changed` counterpart of {SUPPORT_GLOB}: git hands back
|
|
215
|
+
# paths, so the same shape is decided on the first segment).
|
|
216
|
+
SUPPORT_ROOTS = %w[spec test].freeze
|
|
217
|
+
|
|
218
|
+
# The literal a token-carrying file must contain to be selected. A plain
|
|
219
|
+
# substring, not a parse: the gate only decides whether the linter
|
|
220
|
+
# should open the file, and the validator decides what the token means.
|
|
221
|
+
INTENT_TOKEN = "@intent:"
|
|
222
|
+
|
|
189
223
|
# Ordered probes for the default branch when no explicit base is given.
|
|
190
224
|
DEFAULT_BRANCH_REFS = %w[origin/HEAD origin/main origin/master main master].freeze
|
|
191
225
|
|
|
@@ -256,7 +290,11 @@ module SpecGuard
|
|
|
256
290
|
# carried on the `Selection` (`skipped`) so the CLI can disclose the
|
|
257
291
|
# narrowing instead of doing it silently.
|
|
258
292
|
def select_all(root: Dir.pwd)
|
|
259
|
-
candidates = Dir.glob(DEFAULT_GLOB, base: root).select { |f| File.file?(File.join(root, f)) }
|
|
293
|
+
candidates = Dir.glob(DEFAULT_GLOB, base: root).select { |f| File.file?(File.join(root, f)) }
|
|
294
|
+
support = Dir.glob(SUPPORT_GLOB, base: root).select do |f|
|
|
295
|
+
carries_intent_token?(File.join(root, f))
|
|
296
|
+
end
|
|
297
|
+
candidates = (candidates | support).sort
|
|
260
298
|
kept, fenced = candidates.partition { |f| !skipped_directory?(f) }
|
|
261
299
|
Selection.new(files: kept, mode: :all, skipped: fenced.length)
|
|
262
300
|
end
|
|
@@ -273,6 +311,30 @@ module SpecGuard
|
|
|
273
311
|
segments.any? { |segment| SKIPPED_DIRECTORIES.include?(segment) }
|
|
274
312
|
end
|
|
275
313
|
|
|
314
|
+
# Whether a root-relative (or repository-relative) path is a Ruby file
|
|
315
|
+
# under a top-level `spec/` or `test/` directory — the shape
|
|
316
|
+
# {SUPPORT_GLOB} walks, at any depth, including directly at the root
|
|
317
|
+
# (`spec/spec_helper.rb`). Decided on the first path segment, and the
|
|
318
|
+
# basename is excluded from it: a lone `spec.rb` is not under `spec/`.
|
|
319
|
+
def support_path?(path)
|
|
320
|
+
segments = path.split(File::SEPARATOR)
|
|
321
|
+
basename = segments.pop.to_s
|
|
322
|
+
return false unless basename.end_with?(".rb")
|
|
323
|
+
|
|
324
|
+
SUPPORT_ROOTS.include?(segments.first)
|
|
325
|
+
end
|
|
326
|
+
|
|
327
|
+
# Whether the file at `absolute` contains {INTENT_TOKEN}. Read as bytes,
|
|
328
|
+
# so a file that is not valid in any encoding cannot raise mid-selection;
|
|
329
|
+
# a file that cannot be read at all reads as "no token" — the gate's job
|
|
330
|
+
# is to find files worth opening, and one that cannot be opened has no
|
|
331
|
+
# annotation the linter could validate.
|
|
332
|
+
def carries_intent_token?(absolute)
|
|
333
|
+
File.binread(absolute).include?(INTENT_TOKEN)
|
|
334
|
+
rescue SystemCallError
|
|
335
|
+
false
|
|
336
|
+
end
|
|
337
|
+
|
|
276
338
|
def select_changed(base: nil, root: Dir.pwd)
|
|
277
339
|
unless git_repository?(root)
|
|
278
340
|
raise UsageError, "--changed requires a git repository; #{root} is not inside one"
|
|
@@ -312,13 +374,20 @@ module SpecGuard
|
|
|
312
374
|
top = toplevel(root)
|
|
313
375
|
names += untracked_names(top.empty? ? root : top).map { |name| [name, true] }
|
|
314
376
|
|
|
315
|
-
specs = names.select { |(name, _)|
|
|
316
|
-
CHANGED_PATTERNS.any? { |pattern| File.fnmatch?(pattern, name) }
|
|
317
|
-
}
|
|
318
|
-
|
|
319
377
|
prefix = directory_prefix(top.empty? ? root : top)
|
|
320
378
|
root_prefix = directory_prefix(real_path(root))
|
|
321
379
|
|
|
380
|
+
# A changed file is a spec match by its suffix alone, or — for any Ruby
|
|
381
|
+
# file under `spec/` or `test/` — by carrying the `@intent:` token
|
|
382
|
+
# (see "Token-carrying Ruby files under `spec/` and `test/` join").
|
|
383
|
+
# Such candidates that fail the gate are not spec files at all, so they
|
|
384
|
+
# count nowhere (not in `spec_matches`, not in `unreadable`): the
|
|
385
|
+
# empty-reason ladder keeps meaning "a spec file changed".
|
|
386
|
+
specs = names.select { |(name, _)|
|
|
387
|
+
CHANGED_PATTERNS.any? { |pattern| File.fnmatch?(pattern, name) } ||
|
|
388
|
+
support_changed?(name, prefix, root_prefix)
|
|
389
|
+
}
|
|
390
|
+
|
|
322
391
|
files = []
|
|
323
392
|
outside = 0
|
|
324
393
|
unreadable = 0
|
|
@@ -353,6 +422,20 @@ module SpecGuard
|
|
|
353
422
|
skipped]
|
|
354
423
|
end
|
|
355
424
|
|
|
425
|
+
# The token-carrying arm of the `--changed` match: a Ruby file under
|
|
426
|
+
# `spec/` or `test/` that carries {INTENT_TOKEN}. The directory shape
|
|
427
|
+
# is judged on the root-relative path, matching the default walk; a path
|
|
428
|
+
# outside `root` has no such path, so it is judged on git's own
|
|
429
|
+
# repository-relative name (it is only ever counted as outside, never
|
|
430
|
+
# selected).
|
|
431
|
+
def support_changed?(name, prefix, root_prefix)
|
|
432
|
+
absolute = prefix + name
|
|
433
|
+
relative = strip_prefix(absolute, root_prefix)
|
|
434
|
+
return false unless support_path?(relative || name)
|
|
435
|
+
|
|
436
|
+
carries_intent_token?(absolute)
|
|
437
|
+
end
|
|
438
|
+
|
|
356
439
|
# `--diff-filter=d` drops deleted paths — `git diff --name-only` lists
|
|
357
440
|
# them, and they then fail to open. `-z` makes the output machine-readable:
|
|
358
441
|
# NUL-separated and never `core.quotePath`-quoted, so a non-ASCII path
|
|
@@ -112,7 +112,7 @@ module SpecGuard
|
|
|
112
112
|
|
|
113
113
|
# @param results [Array<Linter::Result>] every verdict, in discovery order
|
|
114
114
|
# @param files [Integer] spec files selected — the count the text path
|
|
115
|
-
# states in its leading `checked N spec file(s)` line
|
|
115
|
+
# states in its leading `checked N spec/test file(s)` line
|
|
116
116
|
# @param annotations [Integer] annotation sites examined — the count the
|
|
117
117
|
# text path states in its trailing summary line
|
|
118
118
|
# @param ok [Boolean] whether the run passed, derived from the exit code
|
|
@@ -290,8 +290,14 @@ module SpecGuard
|
|
|
290
290
|
# example's own annotation before it ever consults the line above),
|
|
291
291
|
# so the comment is shadowed and its LAST line is dead. (Any earlier
|
|
292
292
|
# lines of the run are the stacked arm's.)
|
|
293
|
-
#
|
|
294
|
-
#
|
|
293
|
+
# * the comment-form run ABOVE a group (SPGD-2137): the run's next
|
|
294
|
+
# line is a `describe`/`context`/`shared_examples`/… line or an
|
|
295
|
+
# `it_behaves_like`/`include_examples`/… invocation. Extraction is
|
|
296
|
+
# example-anchored — it reads only the line directly above an
|
|
297
|
+
# EXAMPLE — so no example can claim a run that ends at a group
|
|
298
|
+
# line, and every line of it is dead.
|
|
299
|
+
#
|
|
300
|
+
# Each of these is reported loudly, not skipped — the same stance
|
|
295
301
|
# {AnnotationScanner} takes for NO_PAYLOAD.
|
|
296
302
|
#
|
|
297
303
|
# A comment-form annotation line is a comment-only line
|
|
@@ -337,6 +343,14 @@ module SpecGuard
|
|
|
337
343
|
"claim it. Move it onto its example's `it` line, or to the comment line directly " \
|
|
338
344
|
"above that `it`"
|
|
339
345
|
|
|
346
|
+
UNREACHABLE_ABOVE_GROUP_ANNOTATION =
|
|
347
|
+
"unreachable annotation: this @intent: sits directly above an example-group line or a " \
|
|
348
|
+
"shared-example invocation (describe/context/shared_examples/it_behaves_like/...), and " \
|
|
349
|
+
"annotations attach to examples, never to groups — extraction (SPGD-12 §2) is " \
|
|
350
|
+
"example-anchored, so it reads only the line directly above an example and this " \
|
|
351
|
+
"annotation is silently discarded. Move it onto its example's `it` line, or to the " \
|
|
352
|
+
"comment line directly above that `it` (inside the group)"
|
|
353
|
+
|
|
340
354
|
UNREACHABLE_SEPARATED_ANNOTATION =
|
|
341
355
|
"unreachable annotation: this @intent: is separated from its example by an " \
|
|
342
356
|
"intervening comment or blank line, and the one-line lookback (SPGD-12 §2) claims " \
|
|
@@ -406,14 +420,18 @@ module SpecGuard
|
|
|
406
420
|
# {separated_findings_in_text}), one per run whose example carries its own
|
|
407
421
|
# trailing annotation (see {own_line_shadow_findings_in_text}) plus one
|
|
408
422
|
# per group line carrying the trailing form (see
|
|
409
|
-
# {group_line_findings_in_text})
|
|
423
|
+
# {group_line_findings_in_text}), plus one per line of a run sitting
|
|
424
|
+
# directly above a group line or shared-example invocation (see
|
|
425
|
+
# {group_above_findings_in_text}). The passes are disjoint by
|
|
410
426
|
# construction: the stacked pass flags all but the LAST line of a run
|
|
411
427
|
# when an example directly follows, the shadow pass flags ONLY that last
|
|
412
428
|
# line (and only when the example also carries `@intent: {`), the
|
|
413
429
|
# separated pass needs a blank or comment-only line after the run (one
|
|
414
430
|
# slot cannot be both that and an example), and the group pass reads
|
|
415
|
-
# only lines that are not comment-only
|
|
416
|
-
#
|
|
431
|
+
# only lines that are not comment-only, and the above-group pass
|
|
432
|
+
# flags comment lines only when a group or invocation line (never an
|
|
433
|
+
# example line) directly follows the run — so the merge cannot
|
|
434
|
+
# double-flag a line, and the sort restores the file-then-line order
|
|
417
435
|
# {unreachable_findings} promises.
|
|
418
436
|
def unreachable_findings_in_text(text, file:)
|
|
419
437
|
# A file that is not valid UTF-8 is reported once, loudly, by the
|
|
@@ -424,7 +442,8 @@ module SpecGuard
|
|
|
424
442
|
(stacked_findings_in_text(text, file: file) +
|
|
425
443
|
separated_findings_in_text(text, file: file) +
|
|
426
444
|
own_line_shadow_findings_in_text(text, file: file) +
|
|
427
|
-
group_line_findings_in_text(text, file: file)
|
|
445
|
+
group_line_findings_in_text(text, file: file) +
|
|
446
|
+
group_above_findings_in_text(text, file: file)).sort_by(&:line)
|
|
428
447
|
end
|
|
429
448
|
|
|
430
449
|
# @param text [String] source of one file
|
|
@@ -600,9 +619,8 @@ module SpecGuard
|
|
|
600
619
|
# @return [Array<Finding>] one per example-group line carrying an
|
|
601
620
|
# `@intent:` token, for lines that define no example of their own
|
|
602
621
|
# ({EXAMPLE_ON_LINE}). Comment-only lines are left to
|
|
603
|
-
# {
|
|
604
|
-
#
|
|
605
|
-
# scope here (SPGD-1510 flags the group line ITSELF).
|
|
622
|
+
# {group_above_findings_in_text} and the other comment-run passes:
|
|
623
|
+
# this pass flags the group line ITSELF (SPGD-1510).
|
|
606
624
|
def group_line_findings_in_text(text, file:)
|
|
607
625
|
# Same UTF-8 contract as the stacked pass above.
|
|
608
626
|
return [] unless text.valid_encoding?
|
|
@@ -625,6 +643,58 @@ module SpecGuard
|
|
|
625
643
|
kind: Finding::KIND_UNREACHABLE)
|
|
626
644
|
end
|
|
627
645
|
end
|
|
646
|
+
|
|
647
|
+
# A shared-example invocation line: it includes another file's examples
|
|
648
|
+
# into this group, defines none of its own, and so — like a group line —
|
|
649
|
+
# is no example's line for the lookback to anchor on.
|
|
650
|
+
INVOCATION_LINE =
|
|
651
|
+
/\A\s*(?:it_behaves_like|it_should_behave_like|include_examples|include_context)\b/
|
|
652
|
+
|
|
653
|
+
# @param text [String] source of one file
|
|
654
|
+
# @param file [String] path to record on each Finding
|
|
655
|
+
# @return [Array<Finding>] one per comment-form `@intent:` line of a
|
|
656
|
+
# maximal run whose following line is an example-group line
|
|
657
|
+
# ({GROUP_LINE}) or a shared-example invocation ({INVOCATION_LINE}).
|
|
658
|
+
# The lookback reads only the line directly above an EXAMPLE, so the
|
|
659
|
+
# whole run is dead — every line is flagged, the last included. A group
|
|
660
|
+
# line that also defines an example on the same line
|
|
661
|
+
# ({EXAMPLE_ON_LINE}) is that example's own line, so the run above it
|
|
662
|
+
# is claimed and is not flagged. The run must end at the group line:
|
|
663
|
+
# a blank or comment interleave beforehand is the separated pass's
|
|
664
|
+
# window, and it targets examples only.
|
|
665
|
+
def group_above_findings_in_text(text, file:)
|
|
666
|
+
# Same UTF-8 contract as the stacked pass above.
|
|
667
|
+
return [] unless text.valid_encoding?
|
|
668
|
+
|
|
669
|
+
lines = text.lines
|
|
670
|
+
i = 0
|
|
671
|
+
findings = []
|
|
672
|
+
|
|
673
|
+
while i < lines.length
|
|
674
|
+
unless COMMENT_INTENT_LINE.match?(lines[i])
|
|
675
|
+
i += 1
|
|
676
|
+
next
|
|
677
|
+
end
|
|
678
|
+
|
|
679
|
+
run_start = i
|
|
680
|
+
i += 1 while i < lines.length && COMMENT_INTENT_LINE.match?(lines[i])
|
|
681
|
+
run_end = i # exclusive; lines[run_end] is the line after the run
|
|
682
|
+
|
|
683
|
+
target = lines[run_end]
|
|
684
|
+
next if target.nil?
|
|
685
|
+
next unless GROUP_LINE.match?(target) || INVOCATION_LINE.match?(target)
|
|
686
|
+
# The exemption sees only the code before any trailing token, as in
|
|
687
|
+
# {group_line_findings_in_text}.
|
|
688
|
+
next if EXAMPLE_ON_LINE.match?(target.split("@intent:", 2).first)
|
|
689
|
+
|
|
690
|
+
(run_start...run_end).each do |j|
|
|
691
|
+
findings << Finding.new(file: file, line: j + 1, problem: UNREACHABLE_ABOVE_GROUP_ANNOTATION,
|
|
692
|
+
kind: Finding::KIND_UNREACHABLE)
|
|
693
|
+
end
|
|
694
|
+
end
|
|
695
|
+
|
|
696
|
+
findings
|
|
697
|
+
end
|
|
628
698
|
end
|
|
629
699
|
end
|
|
630
700
|
end
|
data/lib/specguard/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: specguard-ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.37
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- specguard Agent
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-11-
|
|
11
|
+
date: 2026-11-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: json
|