specguard-ruby 0.3.34 → 0.3.35
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 +15 -2
- data/lib/specguard/client/file_selector.rb +3 -2
- data/lib/specguard/client/path_root.rb +100 -0
- data/lib/specguard/client/root_binding.rb +57 -0
- data/lib/specguard/minitest/reporter.rb +24 -18
- data/lib/specguard/rspec/formatter.rb +39 -19
- data/lib/specguard/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b6af757f15b338064d2ca49b34d49e95d8b07a75076d0f930e4a13db88f0018b
|
|
4
|
+
data.tar.gz: d3f3c8e41eb3abc927641245be8f1f33237e1620eb6fa212caefa207f17e88a6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 36137b031aac012cee6f6c8c19d5b91961ebc82d5adc40a1c597d881cc58296f9062c91224ff91464ce236ccb76dd0077e47b9c7f2ab22216e599e9886c07f3a
|
|
7
|
+
data.tar.gz: bdb773396d4161b40637e9bb566c1dbd8d9de7d9a2c8d7f158cf97a5b051659f7930420967bc47583c93c6e6754c66a5b5d9b26cda03a464cf3abf97fb8bdf1a
|
data/README.md
CHANGED
|
@@ -423,6 +423,19 @@ have named, not against a `spec/support/` helper.
|
|
|
423
423
|
`file_path` and `line_number` keep meaning the **definition** site — that is the line the `@intent:`
|
|
424
424
|
annotation is read from.
|
|
425
425
|
|
|
426
|
+
**Paths are relative to the git repository root.** Run from a gem or engine subdirectory of a
|
|
427
|
+
monorepo (`gems/a`, `gems/b`), the formatter and the Minitest reporter ship `gems/a/spec/util_spec.rb`
|
|
428
|
+
— not the working-directory-relative `spec/util_spec.rb` that every sibling package would share, which
|
|
429
|
+
made two packages' same-named specs collide on one run id and silently drop one package's rows. The
|
|
430
|
+
root is `git rev-parse --show-toplevel`, resolved once per run; outside a git repository (or when git
|
|
431
|
+
is missing) it is the working directory, and a run from the repository root ships exactly what it
|
|
432
|
+
always did. Annotations are still read from the working directory, so annotated specs in a
|
|
433
|
+
subdirectory run stay annotated. `specguard-lint` output stays working-directory-relative (display
|
|
434
|
+
only). **One-time discontinuity:** if you already run from a subdirectory of a repository, the
|
|
435
|
+
`file_path`, `spec_file_path` and `id` values change on the first run after upgrading
|
|
436
|
+
(`spec/util_spec.rb` → `gems/a/spec/util_spec.rb`), so per-file history for those specs restarts under
|
|
437
|
+
the new names.
|
|
438
|
+
|
|
426
439
|
An example counts as **annotated** when an `@intent:` sits on its `it` line, or on the comment line
|
|
427
440
|
immediately above it:
|
|
428
441
|
|
|
@@ -1180,8 +1193,8 @@ body is encoded on the wire, never what is in it.
|
|
|
1180
1193
|
|
|
1181
1194
|
| Field | What it holds | Where it comes from |
|
|
1182
1195
|
| --- | --- | --- |
|
|
1183
|
-
| `id` | RSpec's own example id, `./spec/orders_spec.rb[1:2]` — the re-run argument | `example.id` |
|
|
1184
|
-
| `spec_file_path` | the spec file that **ran** the example, relative to the
|
|
1196
|
+
| `id` | RSpec's own example id, `./spec/orders_spec.rb[1:2]` — the re-run argument. From a subdirectory of a git repository the path half is repo-relative (`gems/a/spec/orders_spec.rb[1:2]`) | `example.id` |
|
|
1197
|
+
| `spec_file_path` | the spec file that **ran** the example, relative to the git repository root (the working directory when not in a git repo) when it lives under it — an absolute path when it does not, because a spec outside that root has no relative name | `metadata[:rerun_file_path]` |
|
|
1185
1198
|
| `file_path` | the spec file the example is **defined** in, on the same terms | `metadata[:file_path]` |
|
|
1186
1199
|
| `line_number` | the line it is defined on | `metadata[:line_number]` |
|
|
1187
1200
|
| `name` | the composed `describe`/`context`/`it` string | `example.full_description` |
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "open3"
|
|
4
|
+
require_relative "path_root"
|
|
4
5
|
|
|
5
6
|
module SpecGuard
|
|
6
7
|
module Client
|
|
@@ -401,8 +402,8 @@ module SpecGuard
|
|
|
401
402
|
# Empty when git cannot say, in which case the caller falls back to `root`
|
|
402
403
|
# (the top level *is* root for the common case of running from there).
|
|
403
404
|
def toplevel(root)
|
|
404
|
-
|
|
405
|
-
|
|
405
|
+
# The one probe the reporters' path root shares (SPGD-2109).
|
|
406
|
+
PathRoot.toplevel(root) || ""
|
|
406
407
|
end
|
|
407
408
|
|
|
408
409
|
# The merge base of HEAD with the default branch.
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "open3"
|
|
4
|
+
require "pathname"
|
|
5
|
+
|
|
6
|
+
module SpecGuard
|
|
7
|
+
module Client
|
|
8
|
+
# The directory a run's row paths are relative to: the git toplevel of the
|
|
9
|
+
# working directory, so a run started from a gem/engine subdirectory of a
|
|
10
|
+
# monorepo (`gems/a`, `gems/b`) ships `gems/a/spec/util_spec.rb`, not
|
|
11
|
+
# `spec/util_spec.rb`. Two packages each holding `spec/util_spec.rb` would
|
|
12
|
+
# otherwise ship identical `file_path`/`id` values, and the platform's
|
|
13
|
+
# per-run upsert keeps one writer's rows and drops the other's.
|
|
14
|
+
#
|
|
15
|
+
# This is the Ruby twin of specguard-ts's `resolveRunRoots()` (SPGD-2105).
|
|
16
|
+
# Like that, it is two values, not one: the clients keep reading spec
|
|
17
|
+
# SOURCE (annotation lookup) from the working directory — the cwd-relative
|
|
18
|
+
# spelling — and only SHIP paths relative to the path root. Collapsing the
|
|
19
|
+
# two would resolve a repo-relative spelling against the cwd and ship
|
|
20
|
+
# every annotated spec of a subdirectory run as `unannotated`.
|
|
21
|
+
#
|
|
22
|
+
# Falls back to the working directory itself when git is absent, the
|
|
23
|
+
# directory is not in a repository, or the reported toplevel does not
|
|
24
|
+
# contain it (compared by real path, so a symlinked tmpdir such as macOS
|
|
25
|
+
# `/var` vs `/private/var` does not read as "outside"). In that case —
|
|
26
|
+
# and when the cwd *is* the toplevel — the answer is the cwd string
|
|
27
|
+
# exactly as given, so output is byte-identical to a run with no path
|
|
28
|
+
# root at all.
|
|
29
|
+
module PathRoot
|
|
30
|
+
module_function
|
|
31
|
+
|
|
32
|
+
# The repository's top level, as a real path.
|
|
33
|
+
# @param dir [String] where to ask git from
|
|
34
|
+
# @return [String, nil] nil when git cannot say
|
|
35
|
+
def toplevel(dir)
|
|
36
|
+
out, _err, status = Open3.capture3("git", "rev-parse", "--show-toplevel", chdir: dir)
|
|
37
|
+
return nil unless status.success?
|
|
38
|
+
|
|
39
|
+
top = out.strip
|
|
40
|
+
top.empty? ? nil : real_path(top)
|
|
41
|
+
rescue SystemCallError
|
|
42
|
+
# git not installed / not executable / `dir` unreadable.
|
|
43
|
+
nil
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# The path root for a run started in `cwd`.
|
|
47
|
+
#
|
|
48
|
+
# Returned in the spelling of `cwd` (an ancestor of it, so absolute paths
|
|
49
|
+
# the test framework built through the same spelling still start with
|
|
50
|
+
# it) whenever that spelling can be recovered; the real toplevel
|
|
51
|
+
# otherwise.
|
|
52
|
+
# @param cwd [String]
|
|
53
|
+
# @return [String]
|
|
54
|
+
def resolve(cwd)
|
|
55
|
+
top = toplevel(cwd)
|
|
56
|
+
return cwd if top.nil?
|
|
57
|
+
|
|
58
|
+
real_cwd = real_path(cwd)
|
|
59
|
+
return cwd if real_cwd == top
|
|
60
|
+
return cwd unless real_cwd.start_with?(top.end_with?("/") ? top : "#{top}/")
|
|
61
|
+
|
|
62
|
+
suffix = real_cwd.delete_prefix(top)
|
|
63
|
+
cwd.end_with?(suffix) ? cwd.delete_suffix(suffix) : top
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# The working directory relative to the path root; empty when they are
|
|
67
|
+
# the same directory.
|
|
68
|
+
def prefix(cwd, root)
|
|
69
|
+
return "" if cwd == root
|
|
70
|
+
|
|
71
|
+
cwd.delete_prefix("#{root}/")
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# A path as the test framework spells it relative to the working
|
|
75
|
+
# directory (or absolute, for a file outside it), re-expressed relative
|
|
76
|
+
# to the path root. With an empty `prefix` the two roots coincide and
|
|
77
|
+
# the path is returned untouched.
|
|
78
|
+
#
|
|
79
|
+
# An absolute path under the root loses the root; an absolute path
|
|
80
|
+
# outside it, or a relative one that climbs out of it, keeps today's
|
|
81
|
+
# spelling.
|
|
82
|
+
def rebase(path, root:, prefix:)
|
|
83
|
+
return path if prefix.empty?
|
|
84
|
+
|
|
85
|
+
if path.start_with?("/")
|
|
86
|
+
path.start_with?("#{root}/") ? path.delete_prefix("#{root}/") : path
|
|
87
|
+
else
|
|
88
|
+
joined = Pathname.new(File.join(prefix, path)).cleanpath.to_s
|
|
89
|
+
joined.start_with?("../") || joined == ".." ? path : joined
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def real_path(path)
|
|
94
|
+
File.realpath(path)
|
|
95
|
+
rescue SystemCallError
|
|
96
|
+
File.expand_path(path)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "path_root"
|
|
4
|
+
|
|
5
|
+
module SpecGuard
|
|
6
|
+
module Client
|
|
7
|
+
# The class-level root binding shared by the RSpec formatter and the
|
|
8
|
+
# Minitest reporter: `repo_root`, `path_root` and `path_prefix`.
|
|
9
|
+
#
|
|
10
|
+
# Both clients carried the same three methods, differing only in their
|
|
11
|
+
# comments, and every fix to the one-binding discipline had to land once
|
|
12
|
+
# per client (SPGD-1408/1421 for Minitest, SPGD-1429 for RSpec, SPGD-2109
|
|
13
|
+
# in both). One definition here means a binding fix cannot reach one
|
|
14
|
+
# client and miss the other.
|
|
15
|
+
#
|
|
16
|
+
# Use with `extend`, never `include`: the methods run with the CLASS as
|
|
17
|
+
# `self`, so the memos stay class-level ivars (`@repo_root`,
|
|
18
|
+
# `@path_root_binding`) on each client. Specs that save, clear and restore
|
|
19
|
+
# them on the client class depend on that.
|
|
20
|
+
module RootBinding
|
|
21
|
+
# `Dir.pwd` bound once — by the first client construction (whose
|
|
22
|
+
# `#initialize` reads it, SPGD-1421 / SPGD-1429) or the first direct
|
|
23
|
+
# read — never per row: a suite that changes the working directory after
|
|
24
|
+
# the client was built would otherwise relativize one run's rows against
|
|
25
|
+
# two different roots. The memo is what binds it — an unmemoized
|
|
26
|
+
# `Dir.pwd` here re-reads the cwd on every read and is exactly the
|
|
27
|
+
# two-root split the constructors' comments name, with both spellings
|
|
28
|
+
# individually well-formed so nothing downstream can detect the drift.
|
|
29
|
+
# The memo is also the ONE value the annotation lookup reads against:
|
|
30
|
+
# `#initialize` hands it over, so the relativization root and the
|
|
31
|
+
# lookup's read root cannot drift apart the way they did when each bound
|
|
32
|
+
# `Dir.pwd` at its own moment.
|
|
33
|
+
def repo_root
|
|
34
|
+
@repo_root ||= Dir.pwd
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# The directory every shipped row path is relative to (SPGD-2109): the
|
|
38
|
+
# git toplevel of {#repo_root}, or {#repo_root} itself outside a
|
|
39
|
+
# repository. Derived from the ONE bound {#repo_root} and probed once
|
|
40
|
+
# per binding — the same one-binding discipline, so a run started from a
|
|
41
|
+
# monorepo package subdirectory ships `gems/a/spec/x_spec.rb` rather
|
|
42
|
+
# than a name every sibling package shares. {#repo_root} stays the READ
|
|
43
|
+
# root (the annotation lookup resolves spec source against it); the two
|
|
44
|
+
# are deliberately not one value.
|
|
45
|
+
def path_root
|
|
46
|
+
bound = repo_root
|
|
47
|
+
@path_root_binding = nil unless @path_root_binding&.first == bound
|
|
48
|
+
(@path_root_binding ||= [bound, SpecGuard::Client::PathRoot.resolve(bound)]).last
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# {#repo_root} relative to {#path_root}; empty when they coincide.
|
|
52
|
+
def path_prefix
|
|
53
|
+
SpecGuard::Client::PathRoot.prefix(repo_root, path_root)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -21,6 +21,8 @@ require_relative "../client/delivery_warning"
|
|
|
21
21
|
# `specguard/client` does not require `rspec/core`, so a minitest-only machine
|
|
22
22
|
# stays loadable.
|
|
23
23
|
require_relative "../client/annotation_lookup"
|
|
24
|
+
require_relative "../client/path_root"
|
|
25
|
+
require_relative "../client/root_binding"
|
|
24
26
|
|
|
25
27
|
# The Minitest half of `specguard-ruby`. Everything the RSpec formatter knows
|
|
26
28
|
# about the platform — the envelope's field names, the transport's
|
|
@@ -60,23 +62,7 @@ module SpecGuard
|
|
|
60
62
|
# whose file cannot be named fits no by-file aggregate on the platform
|
|
61
63
|
# and would surface as noise. The RSpec formatter's `capture` makes the
|
|
62
64
|
# equivalent call about a metadata-less example.
|
|
63
|
-
|
|
64
|
-
# `Dir.pwd` bound once — by the first `Reporter.new` (whose
|
|
65
|
-
# `#initialize` reads it, SPGD-1421) or the first direct read — never
|
|
66
|
-
# per row: a reporter constructed inside a test that changes the
|
|
67
|
-
# working directory would otherwise relativize one suite's rows
|
|
68
|
-
# against two different roots. The memo is what binds it — an
|
|
69
|
-
# unmemoized `Dir.pwd` here re-reads the cwd on every row and is
|
|
70
|
-
# exactly the two-root split this comment names, with both spellings
|
|
71
|
-
# individually well-formed so nothing downstream can detect the
|
|
72
|
-
# drift. The memo is also the ONE value the annotation lookup reads
|
|
73
|
-
# against: `#initialize` hands it over, so the relativization root
|
|
74
|
-
# and the lookup's read root cannot drift apart the way they did when
|
|
75
|
-
# each bound `Dir.pwd` at its own moment.
|
|
76
|
-
def repo_root
|
|
77
|
-
@repo_root ||= Dir.pwd
|
|
78
|
-
end
|
|
79
|
-
end
|
|
65
|
+
extend SpecGuard::Client::RootBinding
|
|
80
66
|
|
|
81
67
|
def initialize(configuration: SpecGuard.configuration,
|
|
82
68
|
transport: nil, output: $stderr,
|
|
@@ -108,6 +94,8 @@ module SpecGuard
|
|
|
108
94
|
# binds one root, hands it to the default lookup, and pins rspec-core's
|
|
109
95
|
# lazily memoized relativization regex to the same moment.)
|
|
110
96
|
root = self.class.repo_root
|
|
97
|
+
# Probed at the same moment, once, never mid-run (SPGD-2109).
|
|
98
|
+
self.class.path_root
|
|
111
99
|
@annotations = annotations || SpecGuard::Client::AnnotationLookup.new(root: root)
|
|
112
100
|
@clock = clock
|
|
113
101
|
@rows = []
|
|
@@ -264,10 +252,15 @@ module SpecGuard
|
|
|
264
252
|
# the RSpec formatter makes about a metadata-less example.
|
|
265
253
|
return nil if file.to_s.strip.empty? || line.to_i.zero?
|
|
266
254
|
|
|
255
|
+
# `read_file` is the cwd-relative spelling the annotation lookup
|
|
256
|
+
# resolves against the read root; `file` is what ships, relative to
|
|
257
|
+
# the path root (SPGD-2109). Equal unless the run started below the
|
|
258
|
+
# git toplevel.
|
|
259
|
+
read_file = read_relative_path(file)
|
|
267
260
|
file = relative_path(file)
|
|
268
261
|
name = "#{result.klass}##{result.name}"
|
|
269
262
|
line_number = line&.to_i
|
|
270
|
-
intent = annotation_for(
|
|
263
|
+
intent = annotation_for(read_file, line_number)
|
|
271
264
|
{
|
|
272
265
|
# Minitest has no RSpec-style rerun path or nested ids, so the
|
|
273
266
|
# definition site is the row's id — the run-local primary key for
|
|
@@ -328,7 +321,20 @@ module SpecGuard
|
|
|
328
321
|
"passed"
|
|
329
322
|
end
|
|
330
323
|
|
|
324
|
+
# Relative to the path root (the git toplevel; the working directory
|
|
325
|
+
# outside a repository) — the identity a platform aggregate groups by.
|
|
331
326
|
def relative_path(path)
|
|
327
|
+
root = self.class.path_root
|
|
328
|
+
prefix = self.class.path_prefix
|
|
329
|
+
return SpecGuard::Client::PathRoot.rebase(path, root: root, prefix: prefix) unless prefix.empty?
|
|
330
|
+
return path unless path.start_with?("#{root}/")
|
|
331
|
+
|
|
332
|
+
path.delete_prefix("#{root}/")
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
# The cwd-relative spelling: what the annotation lookup reads against
|
|
336
|
+
# the read root.
|
|
337
|
+
def read_relative_path(path)
|
|
332
338
|
root = self.class.repo_root
|
|
333
339
|
return path unless path.start_with?("#{root}/")
|
|
334
340
|
|
|
@@ -49,6 +49,8 @@ require_relative "../rspec"
|
|
|
49
49
|
require_relative "../client/configuration"
|
|
50
50
|
require_relative "../client/transport"
|
|
51
51
|
require_relative "../client/delivery_warning"
|
|
52
|
+
require_relative "../client/path_root"
|
|
53
|
+
require_relative "../client/root_binding"
|
|
52
54
|
# Brings the linter's discovery chain with it (Scanner, Finding, Schema). That
|
|
53
55
|
# direction is safe — `specguard/rspec` does not require `rspec/core`, so the
|
|
54
56
|
# linter stays loadable without RSpec; it is only the reverse that would break
|
|
@@ -273,23 +275,7 @@ module SpecGuard
|
|
|
273
275
|
example_started example_passed example_failed example_pending dump_summary
|
|
274
276
|
].freeze
|
|
275
277
|
|
|
276
|
-
|
|
277
|
-
# `Dir.pwd` bound once — by the first formatter construction (whose
|
|
278
|
-
# `#initialize` reads it, SPGD-1429) or the first direct read — never
|
|
279
|
-
# per row: a suite that changes the working directory after the
|
|
280
|
-
# formatter was built would otherwise relativize one run's rows
|
|
281
|
-
# against two different roots. The memo is what binds it — an
|
|
282
|
-
# unmemoized `Dir.pwd` here re-reads the cwd on every read and is
|
|
283
|
-
# exactly the two-root split the constructor's comment names, with
|
|
284
|
-
# both spellings individually well-formed so nothing downstream can
|
|
285
|
-
# detect the drift. The memo is also the ONE value the default
|
|
286
|
-
# annotation lookup reads against: `#initialize` hands it over, so
|
|
287
|
-
# the relativization root and the lookup's read root cannot drift
|
|
288
|
-
# apart the way they did when each bound `Dir.pwd` at its own moment.
|
|
289
|
-
def repo_root
|
|
290
|
-
@repo_root ||= Dir.pwd
|
|
291
|
-
end
|
|
292
|
-
end
|
|
278
|
+
extend SpecGuard::Client::RootBinding
|
|
293
279
|
|
|
294
280
|
# @param output [IO] the stream RSpec hands every formatter. This class's
|
|
295
281
|
# product is a file, so nothing in the capture path writes here — but the
|
|
@@ -354,6 +340,9 @@ module SpecGuard
|
|
|
354
340
|
# is left alone: its memoization is correct for what it does, and
|
|
355
341
|
# overwriting a bound value would second-guess it.
|
|
356
342
|
root = self.class.repo_root
|
|
343
|
+
# Probed here too, at the same moment, so the git call happens once at
|
|
344
|
+
# construction and never mid-run (SPGD-2109).
|
|
345
|
+
self.class.path_root
|
|
357
346
|
::RSpec::Core::Metadata.relative_path_regex
|
|
358
347
|
@error_stream = error_stream
|
|
359
348
|
@annotations = annotations || SpecGuard::Client::AnnotationLookup.new(root: root)
|
|
@@ -1112,6 +1101,11 @@ module SpecGuard
|
|
|
1112
1101
|
def capture(example)
|
|
1113
1102
|
metadata = example.metadata || {}
|
|
1114
1103
|
result = example.execution_result
|
|
1104
|
+
# `read_path` is rspec-core's cwd-relative spelling — what the
|
|
1105
|
+
# annotation lookup resolves against the read root. `file_path` is the
|
|
1106
|
+
# same file as shipped: relative to the path root (SPGD-2109). They are
|
|
1107
|
+
# equal unless the run started below the git toplevel.
|
|
1108
|
+
read_path = read_relative_path(metadata[:file_path])
|
|
1115
1109
|
file_path = relative_path(metadata[:file_path])
|
|
1116
1110
|
line_number = metadata[:line_number]
|
|
1117
1111
|
|
|
@@ -1121,7 +1115,7 @@ module SpecGuard
|
|
|
1121
1115
|
# the intent of the examples in it and not the examples themselves. It
|
|
1122
1116
|
# also routes through {#warn_once}, so the operator hears about it exactly
|
|
1123
1117
|
# once however many examples are affected.
|
|
1124
|
-
intent = never_fail_the_run { @annotations.intent_for(file:
|
|
1118
|
+
intent = never_fail_the_run { @annotations.intent_for(file: read_path, line: line_number) }
|
|
1125
1119
|
|
|
1126
1120
|
{
|
|
1127
1121
|
# Not wrapped in `never_fail_the_run`, unlike the annotation lookup
|
|
@@ -1129,7 +1123,7 @@ module SpecGuard
|
|
|
1129
1123
|
# memoized string interpolation over a Hash RSpec has already built, and
|
|
1130
1124
|
# a guard here could only ever add a way to emit an identity-less row
|
|
1131
1125
|
# silently. The outer guard at `#example_finished` still covers it.
|
|
1132
|
-
"id" => example
|
|
1126
|
+
"id" => shipped_id(example, metadata),
|
|
1133
1127
|
# `|| file_path` rather than a bare read: RSpec defaults
|
|
1134
1128
|
# `:rerun_file_path` for every example it builds, so the fallback is
|
|
1135
1129
|
# unreachable in a real run — but if a producer ever hands us metadata
|
|
@@ -1159,7 +1153,19 @@ module SpecGuard
|
|
|
1159
1153
|
# definition of "relative to the project root" rather than inventing a
|
|
1160
1154
|
# second one, then drop the `./` so the value matches what a linter, a
|
|
1161
1155
|
# `git diff --name-only` and the platform all use as a file's identity.
|
|
1156
|
+
#
|
|
1157
|
+
# When the run started below the git toplevel (a monorepo package),
|
|
1158
|
+
# "relative to the project root" means the toplevel, not the cwd: the cwd
|
|
1159
|
+
# spelling is re-expressed against it (SPGD-2109).
|
|
1162
1160
|
def relative_path(path)
|
|
1161
|
+
read = read_relative_path(path)
|
|
1162
|
+
return read if read.nil?
|
|
1163
|
+
|
|
1164
|
+
SpecGuard::Client::PathRoot.rebase(read, root: self.class.path_root, prefix: self.class.path_prefix)
|
|
1165
|
+
end
|
|
1166
|
+
|
|
1167
|
+
# rspec-core's own cwd-relative spelling, `./` dropped.
|
|
1168
|
+
def read_relative_path(path)
|
|
1163
1169
|
return nil if path.nil?
|
|
1164
1170
|
|
|
1165
1171
|
string = path.to_s
|
|
@@ -1168,6 +1174,20 @@ module SpecGuard
|
|
|
1168
1174
|
(::RSpec::Core::Metadata.relative_path(string) || string).sub(%r{\A\./}, "")
|
|
1169
1175
|
end
|
|
1170
1176
|
|
|
1177
|
+
# RSpec's example id is `"#{rerun_file_path}[#{scoped_id}]"`, with the
|
|
1178
|
+
# rerun path cwd-relative. Below the git toplevel the path half is rebased
|
|
1179
|
+
# onto the path root like every other shipped path; at the toplevel (or
|
|
1180
|
+
# outside a repository) the id is RSpec's own, untouched.
|
|
1181
|
+
def shipped_id(example, metadata)
|
|
1182
|
+
id = example.id
|
|
1183
|
+
return id if self.class.path_prefix.empty?
|
|
1184
|
+
|
|
1185
|
+
rerun = metadata[:rerun_file_path].to_s
|
|
1186
|
+
return id if rerun.empty? || !id.to_s.start_with?(rerun)
|
|
1187
|
+
|
|
1188
|
+
"#{relative_path(rerun)}#{id[rerun.length..]}"
|
|
1189
|
+
end
|
|
1190
|
+
|
|
1171
1191
|
# Appends one line to the replay queue. Opened in append mode and written
|
|
1172
1192
|
# with a single call so that two suites sharing an output path (parallel CI
|
|
1173
1193
|
# shards, say) interleave whole runs rather than halves of one.
|
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.35
|
|
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-07 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: json
|
|
@@ -59,7 +59,9 @@ files:
|
|
|
59
59
|
- lib/specguard/client/ingest_reporter.rb
|
|
60
60
|
- lib/specguard/client/json_reporter.rb
|
|
61
61
|
- lib/specguard/client/linter.rb
|
|
62
|
+
- lib/specguard/client/path_root.rb
|
|
62
63
|
- lib/specguard/client/payload_normalizer.rb
|
|
64
|
+
- lib/specguard/client/root_binding.rb
|
|
63
65
|
- lib/specguard/client/scanner.rb
|
|
64
66
|
- lib/specguard/client/schemas/open-test-intent.v1.json
|
|
65
67
|
- lib/specguard/client/transport.rb
|