constable-rails 1.3.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e3b589fed13c38522dab7443ab1bb967bedeaec7abb34beaecd5c4f2c9a4298a
4
- data.tar.gz: b646c7160830f81bc2c6c5af9fe60728a8c7e1f40236e594fb64a51eed04080f
3
+ metadata.gz: c9f421fcc02a9f1c30aae54819a543cf548bdd997f8e638899ac6e448d093907
4
+ data.tar.gz: 506be0d669595b7e3f965f81f6449b4c074f4ade3a98c15d9283d78eca1cd584
5
5
  SHA512:
6
- metadata.gz: ee0579e80cb81345601ce2c40090db63b87b1498698a77fbc8c34d0df478d36f3210295b3909bd8290835a1f245f2522952f491caca6776d7ac28981dcae7b74
7
- data.tar.gz: aea8a0a67d5bdc8868706db9820af271ded921871da905c9e09fe83ac74a359c8c5e9ef8649d737367075f8faa9fabc32fff13156a8f2a9f6e9f69516464441a
6
+ metadata.gz: bf1762345ec78b7e7133e724fc9e525d2b037013eb940d49c1fdb6de2940a56284fa67c476e93c229840410e344a92e342bd344f9d21ba7c18c3a6217c3e7a2c
7
+ data.tar.gz: 74b67cd3a65966adc81147e272d08a3b5f092e8602dc3b543c6b2aa878f1bbead4eaabf555d072cc66b97c2137d4bf9593658478235730f3229f15cac0ef1096
data/CHANGELOG.md CHANGED
@@ -5,6 +5,32 @@ 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
+
8
34
  ## [1.3.1]
9
35
 
10
36
  ### Cold cases now read `.rspec`
@@ -528,7 +554,8 @@ Initial release.
528
554
  - Diff-based coverage gate — only lines changed in the current diff are held to the
529
555
  threshold. `constable beat` for the full picture, `--html` for a browsable report.
530
556
 
531
- [Unreleased]: https://github.com/Ray-Hughes/constable/compare/v1.3.1...HEAD
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
532
559
  [1.3.1]: https://github.com/Ray-Hughes/constable/compare/v1.3.0...v1.3.1
533
560
  [1.3.0]: https://github.com/Ray-Hughes/constable/compare/v1.2.0...v1.3.0
534
561
  [1.2.0]: https://github.com/Ray-Hughes/constable/compare/v1.1.0...v1.2.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. `Rails.logger`, SQL and request/response logging go to
426
- `log/test.log`; `--verbose` streams it back for active debugging.
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
@@ -501,14 +501,19 @@ module Constable
501
501
 
502
502
  def color?
503
503
  return false if options[:"no-color"]
504
- return false unless $stdout.tty?
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: $stdout, config: config, color: color?, mode: output_mode)
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
@@ -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 — nothing to route, stdout is already results only"
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Constable
4
- VERSION = "1.3.1"
4
+ VERSION = "1.3.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: constable-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ray Hughes