specguard-ruby 0.3.4 → 0.3.5
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/lib/specguard/minitest/reporter.rb +54 -3
- data/lib/specguard/rspec/cli.rb +8 -5
- data/lib/specguard/rspec/file_selector.rb +31 -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: 9a82ff31aaa51455637e6500a2f4cebda11b50dad52947bd36ce535ada84bc1b
|
|
4
|
+
data.tar.gz: 658887600bd0fec337a1d7ddd372b3c481fa761c95ff3c92c25f12fc6e0fcf91
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 88589ddb1374aa792be0199049b7bb204b6479850831db80340344f4d624db96dc9b7c1c345d6c95c24bbb6728b4e711ab7a338899a7a815c09e6eb53f47c4b2
|
|
7
|
+
data.tar.gz: e11192524e6f248aa16d42c522664863a84894b85987f07ef5f54e5b9c2439bdb6146b0f3c693196d0fcc627f85923f24c5655ed330a9809926f1519802e1e0f
|
|
@@ -10,6 +10,17 @@ require "fileutils"
|
|
|
10
10
|
# minitest-only consumer's machine.
|
|
11
11
|
require_relative "../rspec/configuration"
|
|
12
12
|
|
|
13
|
+
# The annotation lookup is the third framework-free half: what counts as a
|
|
14
|
+
# test's annotation is a property of the source line, not of the framework
|
|
15
|
+
# that ran it, so the Minitest reporter asks the same {AnnotationLookup} the
|
|
16
|
+
# RSpec formatter does rather than carrying a second extractor (whose header
|
|
17
|
+
# already warns that a second extractor guarantees scanner and reporter
|
|
18
|
+
# eventually disagree about what an annotation is). Requiring it pulls the
|
|
19
|
+
# linter's chain — the same direction-safe require the formatter itself makes;
|
|
20
|
+
# `specguard/rspec` does not require `rspec/core`, so a minitest-only machine
|
|
21
|
+
# stays loadable.
|
|
22
|
+
require_relative "../rspec/annotation_lookup"
|
|
23
|
+
|
|
13
24
|
# The Minitest half of `specguard-ruby`. Everything the RSpec formatter knows
|
|
14
25
|
# about the platform — the envelope's field names, the transport's
|
|
15
26
|
# never-raise contract, the switch that a missing key is — is framework-free
|
|
@@ -18,7 +29,10 @@ require_relative "../rspec/configuration"
|
|
|
18
29
|
# ship first, neither containing any RSpec). This adapter contributes only the
|
|
19
30
|
# part that is genuinely Minitest's: turning `Minitest::Result` objects into
|
|
20
31
|
# the same row shape the RSpec formatter emits, at the moment Minitest hands
|
|
21
|
-
# them to a reporter
|
|
32
|
+
# them to a reporter — and attaching each test's annotation the same way the
|
|
33
|
+
# formatter does, through the shared {SpecGuard::RSpec::AnnotationLookup} and
|
|
34
|
+
# its one-line lookback (SPGD-12 §2), so a Minitest row carries the same
|
|
35
|
+
# `status` / `intent` pair a RSpec row does.
|
|
22
36
|
#
|
|
23
37
|
# It is a duck-typed Minitest reporter (`start` / `record` / `report` /
|
|
24
38
|
# `passed?`) rather than a subclass of `Minitest::AbstractReporter`, because
|
|
@@ -36,6 +50,12 @@ require_relative "../rspec/configuration"
|
|
|
36
50
|
module SpecGuard
|
|
37
51
|
module Minitest
|
|
38
52
|
class Reporter
|
|
53
|
+
# `Ingest::Payload::STATUSES`, restated — the same call the RSpec
|
|
54
|
+
# formatter makes. The platform validates every row against this pair,
|
|
55
|
+
# so they are the contract and not a local naming choice.
|
|
56
|
+
STATUS_ANNOTATED = "annotated"
|
|
57
|
+
STATUS_UNANNOTATED = "unannotated"
|
|
58
|
+
|
|
39
59
|
# Rows with no usable location are dropped rather than mangled: a row
|
|
40
60
|
# whose file cannot be named fits no by-file aggregate on the platform
|
|
41
61
|
# and would surface as noise. The RSpec formatter's `capture` makes the
|
|
@@ -51,12 +71,14 @@ module SpecGuard
|
|
|
51
71
|
|
|
52
72
|
def initialize(configuration: SpecGuard::RSpec.configuration,
|
|
53
73
|
transport: nil, output: $stderr,
|
|
74
|
+
annotations: SpecGuard::RSpec::AnnotationLookup.new,
|
|
54
75
|
clock: -> { Process.clock_gettime(Process::CLOCK_MONOTONIC) })
|
|
55
76
|
@configuration = configuration
|
|
56
77
|
# Injected for the specs; the real thing is built the same way the
|
|
57
78
|
# RSpec formatter builds it, from the same configuration object.
|
|
58
79
|
@transport = transport
|
|
59
80
|
@output = output
|
|
81
|
+
@annotations = annotations
|
|
60
82
|
@clock = clock
|
|
61
83
|
@rows = []
|
|
62
84
|
@started_at = nil
|
|
@@ -175,6 +197,8 @@ module SpecGuard
|
|
|
175
197
|
|
|
176
198
|
file = relative_path(file)
|
|
177
199
|
name = "#{result.klass}##{result.name}"
|
|
200
|
+
line_number = line&.to_i
|
|
201
|
+
intent = annotation_for(file, line_number)
|
|
178
202
|
{
|
|
179
203
|
# Minitest has no RSpec-style rerun path or nested ids, so the
|
|
180
204
|
# definition site is the identity: stable across runs (which is
|
|
@@ -183,7 +207,7 @@ module SpecGuard
|
|
|
183
207
|
"id" => "#{file}:#{line}",
|
|
184
208
|
"spec_file_path" => file,
|
|
185
209
|
"file_path" => file,
|
|
186
|
-
"line_number" =>
|
|
210
|
+
"line_number" => line_number,
|
|
187
211
|
"name" => name,
|
|
188
212
|
"duration" => result.time,
|
|
189
213
|
# The platform's three outcomes, mapped from Minitest's questions:
|
|
@@ -192,10 +216,37 @@ module SpecGuard
|
|
|
192
216
|
# Minitest distinguishes assertion failures from exceptions, the
|
|
193
217
|
# wire contract does not, and inventing a fourth outcome here would
|
|
194
218
|
# be a lie the schema refuses.
|
|
195
|
-
"outcome" => outcome_for(result)
|
|
219
|
+
"outcome" => outcome_for(result),
|
|
220
|
+
# The RSpec formatter's rationale, restated: the key is written
|
|
221
|
+
# explicitly because a present key says "we looked", where an absent
|
|
222
|
+
# key is indistinguishable from "this producer does not report
|
|
223
|
+
# annotations" — and without it the platform refuses the whole run
|
|
224
|
+
# (`Ingest::Payload` requires `status` on EVERY row). `intent` is
|
|
225
|
+
# likewise explicit: null when unannotated, which is exactly what
|
|
226
|
+
# the platform demands of an unannotated row.
|
|
227
|
+
"status" => intent.nil? ? STATUS_UNANNOTATED : STATUS_ANNOTATED,
|
|
228
|
+
"intent" => intent
|
|
196
229
|
}
|
|
197
230
|
end
|
|
198
231
|
|
|
232
|
+
# The lookup, inside its own envelope. `record`'s rescue would drop the
|
|
233
|
+
# whole row — example, duration, outcome and all — to learn one row's
|
|
234
|
+
# annotation, which is the trade the RSpec formatter already refused:
|
|
235
|
+
# its annotation lookup runs inside a nested guard so a blow-up costs
|
|
236
|
+
# the row only its annotation. The lookup degrades verdicts it could
|
|
237
|
+
# not reach to nil itself (an unusable validator ships unannotated by
|
|
238
|
+
# design); this envelope is for what escapes it anyway — file reads the
|
|
239
|
+
# lookup does not expect, encoding faults, anything else — and it
|
|
240
|
+
# routes through {#warn_once}, so the operator hears about it exactly
|
|
241
|
+
# once however many rows are affected.
|
|
242
|
+
def annotation_for(file, line)
|
|
243
|
+
@annotations.intent_for(file: file, line: line)
|
|
244
|
+
rescue ScriptError, StandardError => e
|
|
245
|
+
warn_once("could not resolve annotations (#{e.class}: #{e.message}). " \
|
|
246
|
+
"Rows continue unannotated. The test run is unaffected.")
|
|
247
|
+
nil
|
|
248
|
+
end
|
|
249
|
+
|
|
199
250
|
def outcome_for(result)
|
|
200
251
|
return "pending" if result.skipped?
|
|
201
252
|
return "failed" unless result.passed?
|
data/lib/specguard/rspec/cli.rb
CHANGED
|
@@ -244,25 +244,28 @@ module SpecGuard
|
|
|
244
244
|
def empty_reason(selection)
|
|
245
245
|
case selection.mode
|
|
246
246
|
when :changed then changed_empty_reason(selection)
|
|
247
|
-
else "no *_spec.rb found under #{Dir.pwd}"
|
|
247
|
+
else "no *_spec.rb or *_test.rb file found under #{Dir.pwd}"
|
|
248
248
|
end
|
|
249
249
|
end
|
|
250
250
|
|
|
251
251
|
# Names the filter that actually emptied the selection. Saying "nothing in
|
|
252
|
-
# the diff matched
|
|
252
|
+
# the diff matched" when a test file demonstrably changed —
|
|
253
253
|
# just not under this directory — is worse than saying nothing: it reads
|
|
254
|
-
# as a conclusion and stops the reader looking.
|
|
254
|
+
# as a conclusion and stops the reader looking. Both naming conventions
|
|
255
|
+
# are named because either would have been selected; a Minitest-only
|
|
256
|
+
# repository must not be told the silence is about `*_spec.rb` files it
|
|
257
|
+
# does not have.
|
|
255
258
|
def changed_empty_reason(selection)
|
|
256
259
|
stats = selection.stats
|
|
257
260
|
base = selection.base
|
|
258
261
|
|
|
259
|
-
return "nothing in the diff against #{base} matched *_spec.rb" if stats.nil?
|
|
262
|
+
return "nothing in the diff against #{base} matched a *_spec.rb or *_test.rb file" if stats.nil?
|
|
260
263
|
|
|
261
264
|
if stats.changed.zero?
|
|
262
265
|
"nothing changed against #{base}"
|
|
263
266
|
elsif stats.spec_matches.zero?
|
|
264
267
|
"#{stats.changed} file#{'s' unless stats.changed == 1} changed against #{base}, " \
|
|
265
|
-
"none matching *_spec.rb"
|
|
268
|
+
"none matching *_spec.rb or *_test.rb"
|
|
266
269
|
else
|
|
267
270
|
changed_excluded_reason(stats, base)
|
|
268
271
|
end
|
|
@@ -6,8 +6,15 @@ module SpecGuard
|
|
|
6
6
|
module RSpec
|
|
7
7
|
# Chooses which spec files the linter reads.
|
|
8
8
|
#
|
|
9
|
-
# Two modes: every
|
|
10
|
-
# only those in the current diff (`--changed`).
|
|
9
|
+
# Two modes: every Ruby test file under the working directory (the
|
|
10
|
+
# default), or only those in the current diff (`--changed`). Both modes
|
|
11
|
+
# recognize the two Ruby test-framework naming conventions — RSpec's
|
|
12
|
+
# `*_spec.rb` and Minitest's `*_test.rb` — so a suite is visible to the
|
|
13
|
+
# linter whichever framework wrote it. The default walk scopes Minitest
|
|
14
|
+
# files to `test/` (the directory both Rails and `minitest` own as the
|
|
15
|
+
# convention), while `--changed` filters on the file-name suffix alone: a
|
|
16
|
+
# diff names paths, not directories, and a changed test file is a test
|
|
17
|
+
# file wherever the author put it.
|
|
11
18
|
#
|
|
12
19
|
# == Why `--changed` is not `git diff --name-only`
|
|
13
20
|
#
|
|
@@ -41,9 +48,10 @@ module SpecGuard
|
|
|
41
48
|
# found no annotations" from "checked 0 files" — {Selection} carries the
|
|
42
49
|
# count, the emptiness, and {Stats} explaining *which* filter emptied it, so
|
|
43
50
|
# the CLI can say so on stderr, accurately. A confidently wrong reason is
|
|
44
|
-
# worse than a quiet one: a human who reads "nothing in the diff matched
|
|
45
|
-
#
|
|
46
|
-
#
|
|
51
|
+
# worse than a quiet one: a human who reads "nothing in the diff matched a
|
|
52
|
+
# test file" stops looking — and on a Minitest-only repository the silence
|
|
53
|
+
# must not be explained in RSpec vocabulary the tree does not use. The exit
|
|
54
|
+
# code is not the lever: the spec fixes 0 for "no annotations".
|
|
47
55
|
#
|
|
48
56
|
# == Scope: `--changed` selects changed specs **under `root`**
|
|
49
57
|
#
|
|
@@ -74,7 +82,20 @@ module SpecGuard
|
|
|
74
82
|
# clean checkout of a commit) that cannot arise; locally the loud empty
|
|
75
83
|
# selection is what surfaces it.
|
|
76
84
|
module FileSelector
|
|
77
|
-
|
|
85
|
+
# `test/**/*_test.rb` rather than `**/*_test.rb`: the `test/` directory
|
|
86
|
+
# is where both Rails and Minitest itself put Minitest files, and
|
|
87
|
+
# keeping the second convention scoped stops the walk from adopting
|
|
88
|
+
# unrelated `*_test.rb` files elsewhere in the tree (fixture generators,
|
|
89
|
+
# vendored code). `*_spec.rb` stays unscoped because `spec/` already has
|
|
90
|
+
# no competitor convention to fence against.
|
|
91
|
+
DEFAULT_GLOB = ["**/*_spec.rb", "test/**/*_test.rb"].freeze
|
|
92
|
+
|
|
93
|
+
# The `--changed` counterparts of {DEFAULT_GLOB}: git hands back paths,
|
|
94
|
+
# so the filter is a match over the whole path rather than a glob walk,
|
|
95
|
+
# and the suffix alone decides. Deliberately not directory-scoped — a
|
|
96
|
+
# changed Minitest file outside `test/` is still this client's business
|
|
97
|
+
# in the one mode that answers "what did this branch touch".
|
|
98
|
+
CHANGED_PATTERNS = ["*_spec.rb", "*_test.rb"].freeze
|
|
78
99
|
|
|
79
100
|
# Ordered probes for the default branch when no explicit base is given.
|
|
80
101
|
DEFAULT_BRANCH_REFS = %w[origin/HEAD origin/main origin/master main master].freeze
|
|
@@ -116,8 +137,9 @@ module SpecGuard
|
|
|
116
137
|
changed ? select_changed(base: base, root: root) : select_all(root: root)
|
|
117
138
|
end
|
|
118
139
|
|
|
119
|
-
# Every
|
|
120
|
-
#
|
|
140
|
+
# Every test file under `root`, recursively, in either naming
|
|
141
|
+
# convention. Hidden directories are not traversed (no
|
|
142
|
+
# `File::FNM_DOTMATCH`), so `.git` and friends are skipped.
|
|
121
143
|
def select_all(root: Dir.pwd)
|
|
122
144
|
files = Dir.glob(DEFAULT_GLOB, base: root).select { |f| File.file?(File.join(root, f)) }.sort
|
|
123
145
|
Selection.new(files: files, mode: :all)
|
|
@@ -146,7 +168,7 @@ module SpecGuard
|
|
|
146
168
|
# @return [[Array<String>, Stats]]
|
|
147
169
|
def changed_files(base, root)
|
|
148
170
|
names = diff_names(base, root)
|
|
149
|
-
specs = names.select { |name| File.fnmatch?(
|
|
171
|
+
specs = names.select { |name| CHANGED_PATTERNS.any? { |pattern| File.fnmatch?(pattern, name) } }
|
|
150
172
|
|
|
151
173
|
top = toplevel(root)
|
|
152
174
|
prefix = directory_prefix(top.empty? ? root : top)
|
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.5
|
|
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
|
+
date: 2026-09-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: json
|