constable-rails 1.3.0 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +95 -1
- data/README.md +10 -2
- data/lib/constable/cli.rb +8 -3
- data/lib/constable/cold_case/rspec.rb +44 -0
- data/lib/constable/importer/reopener.rb +29 -4
- data/lib/constable/log_router.rb +47 -2
- data/lib/constable/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c9f421fcc02a9f1c30aae54819a543cf548bdd997f8e638899ac6e448d093907
|
|
4
|
+
data.tar.gz: 506be0d669595b7e3f965f81f6449b4c074f4ade3a98c15d9283d78eca1cd584
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bf1762345ec78b7e7133e724fc9e525d2b037013eb940d49c1fdb6de2940a56284fa67c476e93c229840410e344a92e342bd344f9d21ba7c18c3a6217c3e7a2c
|
|
7
|
+
data.tar.gz: 74b67cd3a65966adc81147e272d08a3b5f092e8602dc3b543c6b2aa878f1bbead4eaabf555d072cc66b97c2137d4bf9593658478235730f3229f15cac0ef1096
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,98 @@ All notable changes to this project are documented here. This project adheres to
|
|
|
5
5
|
|
|
6
6
|
## [Unreleased]
|
|
7
7
|
|
|
8
|
+
## [1.3.2]
|
|
9
|
+
|
|
10
|
+
### stdout is results only — the app's stdout too, not just Constable's
|
|
11
|
+
|
|
12
|
+
`log/test.log` has taken Rails' loggers since 1.0.0. It did not take anything a gem writes
|
|
13
|
+
directly to `$stdout` or `$stderr`, and a warning fired once per file lands in the middle
|
|
14
|
+
of the live stream:
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
Address ✓✓✓✓✓✓✓✓✓✓✓To use retry middleware with Faraday v2.0+, install `faraday-retry` gem
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Both streams are now pointed at the log for the duration of a run, and the reporter keeps
|
|
21
|
+
the terminal it captured beforehand. `--verbose` tees them back, which is what that flag
|
|
22
|
+
is for.
|
|
23
|
+
|
|
24
|
+
Two ordering bugs came with it, both caught before release. The console has to be taken
|
|
25
|
+
**before** the Rails check, because `route!` runs before the app boots and most of the
|
|
26
|
+
noise is emitted *by* booting it. And colour detection was asking `$stdout.tty?` — which
|
|
27
|
+
by then is a file, and a file is never a tty, so colour would have silently switched off
|
|
28
|
+
for everybody.
|
|
29
|
+
|
|
30
|
+
Not intercepted: a write straight to file descriptor 2. Capturing that would also swallow
|
|
31
|
+
a real crash and break `binding.pry`, so `2>/dev/null` stays the user's decision.
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
## [1.3.1]
|
|
35
|
+
|
|
36
|
+
### Cold cases now read `.rspec`
|
|
37
|
+
|
|
38
|
+
The bug that mattered. `.rspec` is where an RSpec suite says what to load before any spec
|
|
39
|
+
file:
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
--require spec_helper
|
|
43
|
+
--require rails_helper
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
That is what `rspec --init` generates, and it is why a real spec file usually has no
|
|
47
|
+
`require` line of its own — there is nothing for it to repeat. RSpec's own runner reads
|
|
48
|
+
those files. Constable's cold-case driver did not.
|
|
49
|
+
|
|
50
|
+
So a cold case ran with no `rails_helper` at all: no FactoryBot, no shoulda-matchers, no
|
|
51
|
+
`spec/support/**`. On a 1,277-file suite that is **entirely green under
|
|
52
|
+
`bundle exec rspec`**, `constable test spec/models --full` reported:
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
✓ 774 passed ✗ 3589 failed
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
2,637 of them `undefined method 'create'`, the rest `belong_to`,
|
|
59
|
+
`validate_presence_of`, missing support constants. Every one of them Constable's fault,
|
|
60
|
+
and every one of them looking like the user's.
|
|
61
|
+
|
|
62
|
+
Cold cases now apply the `--require` directives from `.rspec`, `~/.rspec`, `.rspec-local`
|
|
63
|
+
and `SPEC_OPTS`, parsed by RSpec itself so the precedence is its own rather than a guess.
|
|
64
|
+
Only `--require` is taken: formatters, colour and output streams belong to Constable's
|
|
65
|
+
reporter, ordering is Constable's job, and a `--tag` filter meant for a different run
|
|
66
|
+
should not silently drop tests from this one.
|
|
67
|
+
|
|
68
|
+
The same file is now 14 passed, 0 failed — matching `bundle exec rspec` exactly.
|
|
69
|
+
|
|
70
|
+
This never showed up before because the app it was developed against wrote
|
|
71
|
+
`require "rails_helper"` at the top of every spec, which is the one arrangement that
|
|
72
|
+
hides it.
|
|
73
|
+
|
|
74
|
+
### `constable import` says what it actually did
|
|
75
|
+
|
|
76
|
+
It reported `did reopen 1277 file(s)`. "Reopen" is this code's internal word and means
|
|
77
|
+
nothing to a reader, and "import" on its own suggests the files were copied somewhere —
|
|
78
|
+
which is the opposite of what happened. A real user read it exactly that way and asked
|
|
79
|
+
why their specs had not moved into `test/`.
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
Adopted 1277 rspec files as cold cases.
|
|
83
|
+
|
|
84
|
+
Your rspec files stay exactly where they are and are not changed.
|
|
85
|
+
One line was added to .constable/config.yml:
|
|
86
|
+
|
|
87
|
+
cold_cases:
|
|
88
|
+
- spec/**/*_spec.rb
|
|
89
|
+
|
|
90
|
+
Constable runs them from there, through real RSpec, and folds
|
|
91
|
+
the results into its own reporting, flake history and CI gate.
|
|
92
|
+
|
|
93
|
+
Next: constable test --full run everything, cold and native
|
|
94
|
+
constable test --unsafe run only these
|
|
95
|
+
constable modernize PATH see what one file would look like
|
|
96
|
+
as a native case (writes nothing)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
|
|
8
100
|
## [1.3.0]
|
|
9
101
|
|
|
10
102
|
Adoption at scale. Everything here came from installing 1.2.0 into a 1,277-spec-file
|
|
@@ -462,7 +554,9 @@ Initial release.
|
|
|
462
554
|
- Diff-based coverage gate — only lines changed in the current diff are held to the
|
|
463
555
|
threshold. `constable beat` for the full picture, `--html` for a browsable report.
|
|
464
556
|
|
|
465
|
-
[Unreleased]: https://github.com/Ray-Hughes/constable/compare/v1.3.
|
|
557
|
+
[Unreleased]: https://github.com/Ray-Hughes/constable/compare/v1.3.2...HEAD
|
|
558
|
+
[1.3.2]: https://github.com/Ray-Hughes/constable/compare/v1.3.1...v1.3.2
|
|
559
|
+
[1.3.1]: https://github.com/Ray-Hughes/constable/compare/v1.3.0...v1.3.1
|
|
466
560
|
[1.3.0]: https://github.com/Ray-Hughes/constable/compare/v1.2.0...v1.3.0
|
|
467
561
|
[1.2.0]: https://github.com/Ray-Hughes/constable/compare/v1.1.0...v1.2.0
|
|
468
562
|
[1.1.0]: https://github.com/Ray-Hughes/constable/compare/v1.0.0...v1.1.0
|
data/README.md
CHANGED
|
@@ -422,8 +422,16 @@ and says why — slow is a trade-off, wrong is not.
|
|
|
422
422
|
|
|
423
423
|
### Output
|
|
424
424
|
|
|
425
|
-
stdout is reserved for results
|
|
426
|
-
|
|
425
|
+
stdout is reserved for results — not just Constable's own output, but the app's. Rails
|
|
426
|
+
loggers, SQL, request/response logging, and anything a gem prints to `$stdout` or
|
|
427
|
+
`$stderr` mid-run all go to `log/test.log`; `--verbose` streams it back for active
|
|
428
|
+
debugging.
|
|
429
|
+
|
|
430
|
+
That matters more than it sounds. A gem warning fired once per file lands in the middle of
|
|
431
|
+
the live stream, and you get `Address ✓✓✓✓✓✓To use retry middleware with Faraday...`
|
|
432
|
+
instead of a readable run. The one thing Constable deliberately does not intercept is a
|
|
433
|
+
write straight to file descriptor 2 — capturing that would also swallow a real crash and
|
|
434
|
+
break `binding.pry`, so `2>/dev/null` stays yours to decide on.
|
|
427
435
|
|
|
428
436
|
**While it runs**, the live stream has two modes. `concise` is the default: one glyph per
|
|
429
437
|
test, grouped into a run per case, so a thousand-test suite stays inside one screen and a
|
data/lib/constable/cli.rb
CHANGED
|
@@ -168,8 +168,8 @@ module Constable
|
|
|
168
168
|
strategy: options[:strategy].to_sym
|
|
169
169
|
)
|
|
170
170
|
|
|
171
|
+
# The summary says this in full now, in the reader's own terms.
|
|
171
172
|
say result.summary
|
|
172
|
-
say "\nNothing was rewritten -- cold cases run through their own engine, unchanged." if result.any_changes?
|
|
173
173
|
exit(EXIT_CLEAN)
|
|
174
174
|
end
|
|
175
175
|
|
|
@@ -501,14 +501,19 @@ module Constable
|
|
|
501
501
|
|
|
502
502
|
def color?
|
|
503
503
|
return false if options[:"no-color"]
|
|
504
|
-
|
|
504
|
+
# The console, not $stdout -- which by now is log/test.log, and a file is never a
|
|
505
|
+
# tty. Asking the wrong one silently turns colour off for everybody.
|
|
506
|
+
return false unless LogRouter.console.tty?
|
|
505
507
|
return false unless ENV["NO_COLOR"].to_s.empty?
|
|
506
508
|
|
|
507
509
|
true
|
|
508
510
|
end
|
|
509
511
|
|
|
512
|
+
# LogRouter.console, not $stdout: by this point route! has pointed $stdout at
|
|
513
|
+
# log/test.log so a stray gem warning cannot land in the middle of the live stream.
|
|
514
|
+
# The reporter is the one thing that still writes to the terminal.
|
|
510
515
|
def reporter(config)
|
|
511
|
-
Reporter.new(io:
|
|
516
|
+
Reporter.new(io: LogRouter.console, config: config, color: color?, mode: output_mode)
|
|
512
517
|
end
|
|
513
518
|
|
|
514
519
|
# nil means "the config file decides". The explicit --output wins over the two
|
|
@@ -278,9 +278,53 @@ module Constable
|
|
|
278
278
|
# rspec-core's own default; restated because rspec-rails turns it off and a
|
|
279
279
|
# verbatim legacy file may well open with a bare `describe`.
|
|
280
280
|
configuration.expose_dsl_globally = true if configuration.respond_to?(:expose_dsl_globally=)
|
|
281
|
+
apply_rspec_options(configuration)
|
|
281
282
|
@session_prepared = true
|
|
282
283
|
end
|
|
283
284
|
|
|
285
|
+
# `.rspec` is where a suite says what to load before any spec file.
|
|
286
|
+
#
|
|
287
|
+
# --require spec_helper
|
|
288
|
+
# --require rails_helper
|
|
289
|
+
#
|
|
290
|
+
# That is what `rspec --init` generates, and it is why a real spec file usually
|
|
291
|
+
# has no `require` line of its own -- there is nothing for it to repeat. RSpec's
|
|
292
|
+
# own runner reads those files; driving example groups directly does not, so
|
|
293
|
+
# without this a cold case runs with no rails_helper at all: no FactoryBot, no
|
|
294
|
+
# shoulda-matchers, no spec/support. In one real suite that was 2,637 tests
|
|
295
|
+
# failing on `undefined method 'create'` -- a suite that is entirely green under
|
|
296
|
+
# `bundle exec rspec`.
|
|
297
|
+
#
|
|
298
|
+
# Only `--require` is taken. Formatters, colour and output streams belong to
|
|
299
|
+
# Constable's reporter, ordering is Constable's job, and a `--tag` filter from a
|
|
300
|
+
# file RSpec would apply to its own run should not silently drop tests from this
|
|
301
|
+
# one. Requires are the part that decides whether the suite can run at all.
|
|
302
|
+
def apply_rspec_options(configuration)
|
|
303
|
+
requires = rspec_option_requires
|
|
304
|
+
return if requires.empty?
|
|
305
|
+
|
|
306
|
+
# `requires=` rather than plain Kernel#require: it is RSpec's own accessor, and
|
|
307
|
+
# it puts `lib` and the default path (`spec`) on the load path first, which is
|
|
308
|
+
# what makes a bare `require "rails_helper"` resolve.
|
|
309
|
+
configuration.requires = requires
|
|
310
|
+
rescue StandardError => e
|
|
311
|
+
# A helper that will not load is the suite's problem to fix, and it will say so
|
|
312
|
+
# loudly on the first file. Constable's job here is not to disappear.
|
|
313
|
+
Constable.warn!("could not load what .rspec requires (#{e.class}: #{e.message}). " \
|
|
314
|
+
"Cold cases will run without it.", kind: :cold_case)
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
# Parsed by RSpec itself, so `.rspec`, `~/.rspec`, `.rspec-local` and SPEC_OPTS are
|
|
318
|
+
# all read with its precedence rather than a guess at the format.
|
|
319
|
+
def rspec_option_requires
|
|
320
|
+
return [] unless defined?(::RSpec::Core::ConfigurationOptions)
|
|
321
|
+
|
|
322
|
+
options = ::RSpec::Core::ConfigurationOptions.new([]).options
|
|
323
|
+
Array(options[:requires])
|
|
324
|
+
rescue StandardError
|
|
325
|
+
[]
|
|
326
|
+
end
|
|
327
|
+
|
|
284
328
|
def clear_examples
|
|
285
329
|
world = ::RSpec.instance_variable_get(:@world)
|
|
286
330
|
world.reset if world.respond_to?(:reset)
|
|
@@ -114,12 +114,26 @@ module Constable
|
|
|
114
114
|
}
|
|
115
115
|
end
|
|
116
116
|
|
|
117
|
+
# Written for somebody who has just typed `constable import` and does not yet know
|
|
118
|
+
# what a cold case is. "reopen" is the word this code uses internally and it means
|
|
119
|
+
# nothing to a reader; "import" itself suggests files were copied somewhere, which
|
|
120
|
+
# is the opposite of what happened. So: say where the files are, say what changed,
|
|
121
|
+
# and say what to do next.
|
|
117
122
|
def summary
|
|
118
|
-
verb = dry_run? ? "
|
|
119
|
-
|
|
123
|
+
verb = dry_run? ? "Would adopt" : "Adopted"
|
|
124
|
+
noun = imported_count == 1 ? "file" : "files"
|
|
125
|
+
lines = ["#{verb} #{imported_count} #{@from} #{noun} as cold cases."]
|
|
126
|
+
|
|
120
127
|
unless @globs_added.empty?
|
|
121
|
-
lines << "
|
|
122
|
-
|
|
128
|
+
lines << ""
|
|
129
|
+
lines << " Your #{@from} files stay exactly where they are and are not changed."
|
|
130
|
+
lines << " #{dry_run? ? "One line would be added to" : "One line was added to"} " \
|
|
131
|
+
"#{@config_path}:"
|
|
132
|
+
lines << ""
|
|
133
|
+
@globs_added.each { |glob| lines << " cold_cases:\n - #{glob}" }
|
|
134
|
+
lines << ""
|
|
135
|
+
lines << " Constable runs them from there, through real #{engine_label}, and folds"
|
|
136
|
+
lines << " the results into its own reporting, flake history and CI gate."
|
|
123
137
|
unless comments_preserved?
|
|
124
138
|
lines << " note: config.yml was rewritten from parsed YAML; comments were not preserved"
|
|
125
139
|
end
|
|
@@ -133,9 +147,20 @@ module Constable
|
|
|
133
147
|
@skipped.each { |s| lines << " - #{s[:path]} (#{s[:reason]})" }
|
|
134
148
|
end
|
|
135
149
|
@errors.each { |e| lines << " error: #{e[:path]} -- #{e[:message]}" }
|
|
150
|
+
|
|
151
|
+
unless dry_run? || imported_count.zero?
|
|
152
|
+
lines << ""
|
|
153
|
+
lines << " Next: constable test --full run everything, cold and native"
|
|
154
|
+
lines << " constable test --unsafe run only these"
|
|
155
|
+
lines << " constable modernize PATH see what one file would look like"
|
|
156
|
+
lines << " as a native case (writes nothing)"
|
|
157
|
+
end
|
|
158
|
+
|
|
136
159
|
lines.join("\n")
|
|
137
160
|
end
|
|
138
161
|
|
|
162
|
+
def engine_label = @from.to_s == "rspec" ? "RSpec" : "Minitest"
|
|
163
|
+
|
|
139
164
|
def superclass_name = ENGINES.fetch(@from)[:superclass]
|
|
140
165
|
|
|
141
166
|
def covered_by(glob)
|
data/lib/constable/log_router.rb
CHANGED
|
@@ -55,6 +55,14 @@ module Constable
|
|
|
55
55
|
def sync = true
|
|
56
56
|
def tty? = false
|
|
57
57
|
|
|
58
|
+
# Something that has been handed $stdout may ask it for a file descriptor. Answer
|
|
59
|
+
# with the first target that has one rather than raising NoMethodError from inside
|
|
60
|
+
# somebody else's gem.
|
|
61
|
+
def fileno
|
|
62
|
+
@targets.each { |t| return t.fileno if t.respond_to?(:fileno) }
|
|
63
|
+
nil
|
|
64
|
+
end
|
|
65
|
+
|
|
58
66
|
def sync=(value)
|
|
59
67
|
@targets.each { |target| target.sync = value if target.respond_to?(:sync=) }
|
|
60
68
|
end
|
|
@@ -89,12 +97,18 @@ module Constable
|
|
|
89
97
|
def route!(verbose: false, path: nil, io: $stdout, root: nil)
|
|
90
98
|
target = path ? File.expand_path(path.to_s, root || Constable.root) : default_path(root)
|
|
91
99
|
|
|
100
|
+
# Taking the console does not depend on Rails, and the ordering matters: route! runs
|
|
101
|
+
# before the app boots, so anything that waited for Rails would miss every warning
|
|
102
|
+
# emitted *by* booting it -- which is most of them. A suite with no Rails at all
|
|
103
|
+
# still wants its stdout kept for results.
|
|
104
|
+
file = open_log(target)
|
|
105
|
+
capture_console!(file, verbose ? io : nil)
|
|
106
|
+
|
|
92
107
|
unless rails_loaded?
|
|
93
|
-
reason = "Rails is not loaded —
|
|
108
|
+
reason = "Rails is not loaded — no loggers to route, but stdout is held for results"
|
|
94
109
|
return @current = Routing.new(routed: false, path: target, verbose: verbose, reason: reason)
|
|
95
110
|
end
|
|
96
111
|
|
|
97
|
-
file = open_log(target)
|
|
98
112
|
logger = build_logger(verbose ? Tee.new(file, io) : file)
|
|
99
113
|
|
|
100
114
|
remember_previous!
|
|
@@ -103,9 +117,40 @@ module Constable
|
|
|
103
117
|
@current = Routing.new(routed: true, path: target, verbose: verbose, reason: nil)
|
|
104
118
|
end
|
|
105
119
|
|
|
120
|
+
# The terminal, as it was before route! took it. The reporter writes here; everything
|
|
121
|
+
# else writes to the log.
|
|
122
|
+
def console = @console_out || $stdout
|
|
123
|
+
|
|
124
|
+
# Rails loggers are not the only thing that writes to a terminal. A gem warning --
|
|
125
|
+
# Faraday's "install the faraday-retry gem", say -- goes straight to $stderr, once
|
|
126
|
+
# per file that triggers it, and lands in the middle of the live stream:
|
|
127
|
+
#
|
|
128
|
+
# Address ✓✓✓✓✓✓✓✓✓✓✓To use retry middleware with Faraday v2.0+...
|
|
129
|
+
#
|
|
130
|
+
# stdout is supposed to be results only. So the app's stdout and stderr are pointed
|
|
131
|
+
# at log/test.log for the duration of the run, and the reporter keeps the real
|
|
132
|
+
# terminal it captured beforehand. `--verbose` tees both back, which is the whole
|
|
133
|
+
# point of that flag.
|
|
134
|
+
def capture_console!(file, tee_to)
|
|
135
|
+
@console_out = $stdout
|
|
136
|
+
@console_err = $stderr
|
|
137
|
+
|
|
138
|
+
replacement = tee_to ? Tee.new(file, tee_to) : file
|
|
139
|
+
$stdout = replacement
|
|
140
|
+
$stderr = replacement
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def restore_console!
|
|
144
|
+
$stdout = @console_out if @console_out
|
|
145
|
+
$stderr = @console_err if @console_err
|
|
146
|
+
@console_out = nil
|
|
147
|
+
@console_err = nil
|
|
148
|
+
end
|
|
149
|
+
|
|
106
150
|
# Puts back whatever the app had before route!. Only useful in-process (our own
|
|
107
151
|
# suite, or a REPL); a real run never wants its logs back on stdout.
|
|
108
152
|
def restore!
|
|
153
|
+
restore_console!
|
|
109
154
|
(@previous || {}).each do |constant_name, (setter, logger)|
|
|
110
155
|
constant = resolve(constant_name)
|
|
111
156
|
constant&.public_send(setter, logger)
|
data/lib/constable/version.rb
CHANGED