specguard-ruby 0.3.35 → 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/delivery_warning.rb +4 -2
- 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/client/sink_writer.rb +53 -0
- data/lib/specguard/minitest/reporter.rb +10 -13
- data/lib/specguard/rspec/formatter.rb +26 -43
- data/lib/specguard/version.rb +1 -1
- metadata +3 -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
|
|
|
@@ -13,8 +13,10 @@ module SpecGuard
|
|
|
13
13
|
# wording change cannot reach one client and miss the other.
|
|
14
14
|
#
|
|
15
15
|
# What stays in each client: the prefix, the warning budget (`@warned`),
|
|
16
|
-
# and
|
|
17
|
-
#
|
|
16
|
+
# and what it does with the answer of the shared write ({SinkWriter}) —
|
|
17
|
+
# whether `error` is nil, and which sentence that earns. The write itself
|
|
18
|
+
# no longer differs between the clients; what each does with its answer
|
|
19
|
+
# does, by design. Only the clause text is shared here.
|
|
18
20
|
module DeliveryWarning
|
|
19
21
|
module_function
|
|
20
22
|
|
|
@@ -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
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
require "fileutils"
|
|
5
|
+
|
|
6
|
+
module SpecGuard
|
|
7
|
+
module Client
|
|
8
|
+
# The local JSON-line sink writer shared by the two framework clients'
|
|
9
|
+
# sinks: the RSpec formatter's replay queue and local development record,
|
|
10
|
+
# and the Minitest reporter's (see {Configuration#output_path} and
|
|
11
|
+
# {Configuration#local_output_path}). One definition here means the write
|
|
12
|
+
# — the guarded `mkdir_p`, the single append-mode write of the full line,
|
|
13
|
+
# the exception-as-value contract — cannot drift between the two clients,
|
|
14
|
+
# which hand-copied it until SPGD-2124 and had already been co-edited in
|
|
15
|
+
# separate commits (SPGD-1413).
|
|
16
|
+
#
|
|
17
|
+
# What stays in each client: which sink the run warrants (`#deliver`
|
|
18
|
+
# decides), and what each does with the write's answer — the formatter's
|
|
19
|
+
# fall-back folds it into the delivery line its budget is already spent
|
|
20
|
+
# on, the reporter's keyless branch names the configured path in its own
|
|
21
|
+
# line. The write itself is shared.
|
|
22
|
+
module SinkWriter
|
|
23
|
+
module_function
|
|
24
|
+
|
|
25
|
+
# Appends one line to `path`. Opened in append mode and written with a
|
|
26
|
+
# single call so that two suites sharing an output path (parallel CI
|
|
27
|
+
# shards, say) interleave whole runs rather than halves of one.
|
|
28
|
+
#
|
|
29
|
+
# `path` is passed in rather than read here, so the line a client's
|
|
30
|
+
# fall-back composes and the file it describes are provably the same
|
|
31
|
+
# string — a second read of a process-wide singleton could answer
|
|
32
|
+
# differently and name a path nothing was written to.
|
|
33
|
+
#
|
|
34
|
+
# Returns the exception the write died of, or `nil` when it landed,
|
|
35
|
+
# rather than warning itself or raising — the clients need the outcome
|
|
36
|
+
# *in* their own sentence, and a raise here could not be folded into
|
|
37
|
+
# one: it would fall through to a client's generic handler and spend
|
|
38
|
+
# the run's one warning budget on a sentence this module's answer was
|
|
39
|
+
# meant to replace (SPGD-1413). `Interrupt` stays deliberately outside
|
|
40
|
+
# the clause, as everywhere else in these files: Ctrl-C must stay
|
|
41
|
+
# Ctrl-C.
|
|
42
|
+
def append(data, path)
|
|
43
|
+
directory = File.dirname(path)
|
|
44
|
+
FileUtils.mkdir_p(directory) unless directory == "." || File.directory?(directory)
|
|
45
|
+
|
|
46
|
+
File.open(path, "a") { |file| file.write("#{JSON.generate(data)}\n") }
|
|
47
|
+
nil
|
|
48
|
+
rescue ScriptError, StandardError => e
|
|
49
|
+
e
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "json"
|
|
4
|
-
require "fileutils"
|
|
5
|
-
|
|
6
3
|
# Configuration and Transport are the framework-free halves of the client
|
|
7
4
|
# (env resolution, wire delivery, the never-raise contract), under
|
|
8
5
|
# `SpecGuard::Client`. Required here rather than assumed because nothing else
|
|
@@ -10,6 +7,7 @@ require "fileutils"
|
|
|
10
7
|
require_relative "../client"
|
|
11
8
|
require_relative "../client/configuration"
|
|
12
9
|
require_relative "../client/delivery_warning"
|
|
10
|
+
require_relative "../client/sink_writer"
|
|
13
11
|
|
|
14
12
|
# The annotation lookup is the third framework-free half: what counts as a
|
|
15
13
|
# test's annotation is a property of the source line, not of the framework
|
|
@@ -350,21 +348,20 @@ module SpecGuard
|
|
|
350
348
|
# One JSON run per line, to whichever file this delivery's outcome
|
|
351
349
|
# warrants (see `#deliver` for which and why).
|
|
352
350
|
#
|
|
353
|
-
#
|
|
354
|
-
#
|
|
355
|
-
#
|
|
351
|
+
# A one-line delegation to {SpecGuard::Client::SinkWriter.append}, the
|
|
352
|
+
# write both clients share (this reporter carried a hand-copy of it, and
|
|
353
|
+
# the RSpec formatter the second, until SPGD-2124). It returns the
|
|
354
|
+
# exception the write died of, or `nil` when it landed, rather than
|
|
355
|
+
# warning itself. Both call sites need the outcome *in* their own
|
|
356
|
+
# sentence — the keyless branch has no preceding line and says so
|
|
356
357
|
# directly, the fall-back folds it into the delivery line it is already
|
|
357
358
|
# spending the run's one warning on — and a warning here would reach
|
|
358
359
|
# `warn_once` first on the fall-back path and spend that budget on the
|
|
359
360
|
# generic write message, losing the HTTP status the operator needs
|
|
360
|
-
# (SPGD-1413). `Interrupt` stays outside the clause, as
|
|
361
|
-
# in this class.
|
|
361
|
+
# (SPGD-1413). `Interrupt` stays outside the writer's clause, as
|
|
362
|
+
# everywhere else in this class.
|
|
362
363
|
def append(data, path)
|
|
363
|
-
|
|
364
|
-
File.open(path, "a") { |f| f.puts(JSON.generate(data)) }
|
|
365
|
-
nil
|
|
366
|
-
rescue ScriptError, StandardError => e
|
|
367
|
-
e
|
|
364
|
+
SpecGuard::Client::SinkWriter.append(data, path)
|
|
368
365
|
end
|
|
369
366
|
|
|
370
367
|
# The keyless branch's write, and its own warning. Nothing preceded it on
|
|
@@ -37,8 +37,6 @@
|
|
|
37
37
|
# directions.
|
|
38
38
|
require "rspec/core"
|
|
39
39
|
require "rspec/core/formatters/base_formatter"
|
|
40
|
-
require "json"
|
|
41
|
-
require "fileutils"
|
|
42
40
|
|
|
43
41
|
# `specguard/rspec` is what defines `SpecGuard::RSpec` — the namespace whose
|
|
44
42
|
# existence is the shadowing hazard documented below, and the home of the
|
|
@@ -49,6 +47,7 @@ require_relative "../rspec"
|
|
|
49
47
|
require_relative "../client/configuration"
|
|
50
48
|
require_relative "../client/transport"
|
|
51
49
|
require_relative "../client/delivery_warning"
|
|
50
|
+
require_relative "../client/sink_writer"
|
|
52
51
|
require_relative "../client/path_root"
|
|
53
52
|
require_relative "../client/root_binding"
|
|
54
53
|
# Brings the linter's discovery chain with it (Scanner, Finding, Schema). That
|
|
@@ -742,12 +741,14 @@ module SpecGuard
|
|
|
742
741
|
# Called from inside {#never_fail_the_run}, so a raise below it cannot
|
|
743
742
|
# fail the run — but neither arm leaves its failure to that generic
|
|
744
743
|
# envelope, because each spends the run's one warning on a line that has
|
|
745
|
-
# to say what actually happened. {#append}
|
|
746
|
-
#
|
|
747
|
-
#
|
|
748
|
-
#
|
|
749
|
-
#
|
|
750
|
-
#
|
|
744
|
+
# to say what actually happened. {#append} hands the sink's outcome back
|
|
745
|
+
# as a value — the write and its rescue live in {Client::SinkWriter},
|
|
746
|
+
# shared with the Minitest reporter (SPGD-2124) — so the one line
|
|
747
|
+
# {#fall_back} is spending can report whether the queue took the run
|
|
748
|
+
# rather than promise it (SPGD-1413); the keyless {#append_local} does
|
|
749
|
+
# the same and names the configured sink path in the line it emits, the
|
|
750
|
+
# way the Minitest twin does (SPGD-1400). Nothing raises out of either
|
|
751
|
+
# way.
|
|
751
752
|
#
|
|
752
753
|
# == Why a failure writes the file rather than shrugging
|
|
753
754
|
#
|
|
@@ -866,7 +867,7 @@ module SpecGuard
|
|
|
866
867
|
# whose accessors are `commit_sha`, `branch`, `run_id`, `shard_id`,
|
|
867
868
|
# `output_path`, `endpoint`, `api_key` and `timeout`, and which has no
|
|
868
869
|
# `dry_run?`. Note that four methods here — {#payload}, {#deliver},
|
|
869
|
-
# {#
|
|
870
|
+
# {#fall_back} and {#append_local} — legitimately call
|
|
870
871
|
# `SpecGuard::RSpec.configuration` for this gem's own settings, so both
|
|
871
872
|
# spellings appear in this file and mean different things.
|
|
872
873
|
#
|
|
@@ -1188,26 +1189,15 @@ module SpecGuard
|
|
|
1188
1189
|
"#{relative_path(rerun)}#{id[rerun.length..]}"
|
|
1189
1190
|
end
|
|
1190
1191
|
|
|
1191
|
-
# Appends one line to the replay queue
|
|
1192
|
-
#
|
|
1193
|
-
#
|
|
1194
|
-
#
|
|
1195
|
-
# `
|
|
1196
|
-
#
|
|
1197
|
-
#
|
|
1198
|
-
# a path nothing was written to.
|
|
1199
|
-
#
|
|
1200
|
-
# Returns the exception the write died of, or `nil` when it landed — the
|
|
1201
|
-
# fall-back's one line is composed from that answer (see {#fall_back}), and
|
|
1202
|
-
# a raise here could not be, because `close`'s {#never_fail_the_run} would
|
|
1203
|
-
# only reach a warning budget the delivery message has already spent.
|
|
1204
|
-
# `Interrupt` is deliberately outside the clause, as everywhere else in this
|
|
1205
|
-
# file: Ctrl-C must stay Ctrl-C.
|
|
1192
|
+
# Appends one line to the replay queue — a one-line delegation to
|
|
1193
|
+
# {Client::SinkWriter.append}, the write both clients share (the
|
|
1194
|
+
# formatter carried a hand-copy of it until SPGD-2124, and the Minitest
|
|
1195
|
+
# reporter carried the second one). The return contract — the exception
|
|
1196
|
+
# as a value, `nil` on success, `Interrupt` outside the clause — lives on
|
|
1197
|
+
# the module now; what stays here is what this client does with the
|
|
1198
|
+
# answer, folding it into the fall-back's one line (see {#fall_back}).
|
|
1206
1199
|
def append(data, path)
|
|
1207
|
-
|
|
1208
|
-
nil
|
|
1209
|
-
rescue ScriptError, StandardError => e
|
|
1210
|
-
e
|
|
1200
|
+
Client::SinkWriter.append(data, path)
|
|
1211
1201
|
end
|
|
1212
1202
|
|
|
1213
1203
|
# The keyless branch's sink: `local_output_path`, a local development
|
|
@@ -1216,14 +1206,14 @@ module SpecGuard
|
|
|
1216
1206
|
# failed deliveries. See {Configuration#local_output_path}.
|
|
1217
1207
|
#
|
|
1218
1208
|
# Its failure is its own line rather than {#never_fail_the_run}'s generic
|
|
1219
|
-
# substitute: the path is knowable here — read once into a local,
|
|
1220
|
-
#
|
|
1221
|
-
# same input (SPGD-1400), as does this file's delivery arm
|
|
1222
|
-
# {#sink_clause} (SPGD-1413). The write goes through {#append} so
|
|
1223
|
-
# exception comes back as a value to compose the line from; left to
|
|
1224
|
-
# it would fall through to {#never_fail_the_run} and spend the
|
|
1225
|
-
# warning on the one sentence this exists to replace.
|
|
1226
|
-
# outside, as everywhere else in this file.
|
|
1209
|
+
# substitute: the path is knowable here — read once into a local, so the
|
|
1210
|
+
# line names exactly the file the write attempted — and the Minitest twin
|
|
1211
|
+
# names it on the same input (SPGD-1400), as does this file's delivery arm
|
|
1212
|
+
# through {#sink_clause} (SPGD-1413). The write goes through {#append} so
|
|
1213
|
+
# the exception comes back as a value to compose the line from; left to
|
|
1214
|
+
# raise, it would fall through to {#never_fail_the_run} and spend the
|
|
1215
|
+
# run's one warning on the one sentence this exists to replace.
|
|
1216
|
+
# `Interrupt` stays outside, as everywhere else in this file.
|
|
1227
1217
|
def append_local(data)
|
|
1228
1218
|
path = SpecGuard::RSpec.configuration.local_output_path
|
|
1229
1219
|
error = append(data, path)
|
|
@@ -1233,13 +1223,6 @@ module SpecGuard
|
|
|
1233
1223
|
"(#{error.class}: #{error.message}). The test run is unaffected.")
|
|
1234
1224
|
end
|
|
1235
1225
|
|
|
1236
|
-
def append_to(data, path)
|
|
1237
|
-
directory = File.dirname(path)
|
|
1238
|
-
FileUtils.mkdir_p(directory) unless directory == "." || File.directory?(directory)
|
|
1239
|
-
|
|
1240
|
-
File.open(path, "a") { |file| file.write("#{JSON.generate(data)}\n") }
|
|
1241
|
-
end
|
|
1242
|
-
|
|
1243
1226
|
# `Errno::*` and `IOError` — the sink's failure modes — are both
|
|
1244
1227
|
# `StandardError` descendants, so they need no separate clause; they are
|
|
1245
1228
|
# named in the ticket because they are the *reason* this rescue is here, not
|
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
|
|
@@ -64,6 +64,7 @@ files:
|
|
|
64
64
|
- lib/specguard/client/root_binding.rb
|
|
65
65
|
- lib/specguard/client/scanner.rb
|
|
66
66
|
- lib/specguard/client/schemas/open-test-intent.v1.json
|
|
67
|
+
- lib/specguard/client/sink_writer.rb
|
|
67
68
|
- lib/specguard/client/transport.rb
|
|
68
69
|
- lib/specguard/client/validator_backend.rb
|
|
69
70
|
- lib/specguard/minitest/reporter.rb
|