rspec-capturing-formatter 1.0.2 → 1.1.0

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: 19503a13ac6bfc68facc76325bd41bd2b440adcd62286043bdc4d640973604ca
4
- data.tar.gz: bbed93a7930a15b1a1b4bd395c474b6e2a725e735bca93a9528d27d67a111e09
3
+ metadata.gz: 86c5a7a4ac477c385790c51f48ec8a541a2ddb98dd7ae54221eabab56cb1cd8d
4
+ data.tar.gz: 4f2dfe985f9cc9fa07e9657c91d2237f8aa4785444636302047845c53a16fa1f
5
5
  SHA512:
6
- metadata.gz: 71c8229f3cd01dc16408afc61e663715a3d10040cc64cd5a8b47e72686647cfd4c2c877b1e9fe6683cf7c825fe17cb9d16a631ef89a61ed433a994c6251719de
7
- data.tar.gz: 7e5390702ff5a2bd814124e03f82bf413e59d8a28332aef8c9e002b8001b635fd22df8a03a0c7e73af0b276eaa315157f7f3df7701ba1c8100518b0273436803
6
+ metadata.gz: 65b49e1b9f9412f070c336a9e0af3678b6b56f297919b076ce2d84216b589ba5b5b556763972cbe4869141d4b69cdc26ae91d7d0a0d84017a8c62e3c3ec5044a
7
+ data.tar.gz: fe4ffca9eb311c1502d51ca61ccc9525361839ad73c11e55564bd5946814391ae329eb755cc2aebbbf64d51be5922da04154ccd42086a6b37104ba7c5c4c56b4
data/README.md CHANGED
@@ -98,9 +98,9 @@ RSpec::CapturingFormatter.configure do |config|
98
98
  end
99
99
  ```
100
100
 
101
- When `config.color == true`, coloring is enabled even when there is no TTY. Coloring is always disabled when `NO_COLOR` or when RSpec's `--no-color` option is set.
101
+ When `config.color == true`, coloring is enabled for TTY destinations and disabled for redirected output by default. `FORCE_COLOR` enables coloring when it is non-empty and not `0`; RSpec's `--force-color` has the same effect. Coloring is always disabled when `NO_COLOR`, `config.color = false`, or RSpec's `--no-color` option is set.
102
102
 
103
- On Windows, interactive coloring is supported in Windows Terminal. Legacy Windows console sessions are not supported color targets and receive plain-text output instead of raw ANSI escape sequences. Redirected reports keep ANSI coloring when enabled, so they can be viewed by ANSI-aware CI logs or tools.
103
+ On Windows, interactive coloring is supported in Windows Terminal. Legacy Windows console sessions are not supported color targets and receive plain-text output instead of raw ANSI escape sequences. Redirected reports are plain by default and remain colored when `FORCE_COLOR` or `--force-color` is used.
104
104
 
105
105
  ## Output capture limitations
106
106
 
data/Rakefile CHANGED
@@ -12,7 +12,8 @@ task :spec do
12
12
  rspec_args << "--format"
13
13
  rspec_args << "RSpec::CapturingFormatter"
14
14
  end
15
- if ENV["FORCE_COLOR"]
15
+ force_color = ENV["FORCE_COLOR"]
16
+ if force_color && !force_color.empty? && force_color != "0"
16
17
  rspec_args << "--force-color"
17
18
  end
18
19
  if (file = ENV["FILE"])
@@ -29,10 +29,11 @@ module RSpec
29
29
 
30
30
  attr_reader :output
31
31
 
32
- def initialize(output, configuration, capture_manager: nil, ansi_supported: nil)
32
+ def initialize(output, configuration, capture_manager: nil, ansi_supported: nil, env: ENV)
33
33
  @output = output || StringIO.new
34
34
  @configuration = configuration
35
35
  @capture_manager = capture_manager
36
+ @env = env
36
37
  @ansi_supported = ansi_supported.nil? ? WindowsTerminal.ansi_supported?(@output) : ansi_supported
37
38
  @entry_started = false
38
39
  @entry_kind = nil
@@ -223,7 +224,7 @@ module RSpec
223
224
  private
224
225
 
225
226
  def emit_captured_text(source, text, nonblocking: false)
226
- text = strip_sgr(text) unless @ansi_supported
227
+ text = strip_sgr(text) unless color_enabled?
227
228
  return if text.empty?
228
229
 
229
230
  # Once application SGR appears, formatter source color stays off until the capture boundary.
@@ -267,7 +268,7 @@ module RSpec
267
268
 
268
269
  def line(value, color = nil)
269
270
  value = value.to_s
270
- value = strip_sgr(value) unless @ansi_supported
271
+ value = strip_sgr(value) unless color_enabled?
271
272
  write_raw(RESET) if color_enabled?
272
273
  write_raw(style(value, color))
273
274
  write_raw("\n")
@@ -363,11 +364,24 @@ module RSpec
363
364
 
364
365
  def color_enabled?
365
366
  return false unless @ansi_supported
366
- return false if ENV["NO_COLOR"] && !ENV["NO_COLOR"].empty?
367
- return false if defined?(RSpec) && RSpec.respond_to?(:configuration) &&
368
- RSpec.configuration.respond_to?(:color_mode) && RSpec.configuration.color_mode == :off
367
+ return false unless @configuration.color
368
+ return false if @env["NO_COLOR"] && !@env["NO_COLOR"].empty?
369
369
 
370
- @configuration.color
370
+ color_mode = rspec_color_mode
371
+ return false if color_mode == :off
372
+ return true if color_mode == :on
373
+
374
+ force_color = @env["FORCE_COLOR"]
375
+ return true if force_color && !force_color.empty? && force_color != "0"
376
+
377
+ @output.respond_to?(:tty?) && @output.tty?
378
+ end
379
+
380
+ def rspec_color_mode
381
+ return unless defined?(RSpec) && RSpec.respond_to?(:configuration)
382
+
383
+ configuration = RSpec.configuration
384
+ configuration.color_mode if configuration.respond_to?(:color_mode)
371
385
  end
372
386
 
373
387
  def style(value, color)
@@ -4,6 +4,6 @@ module RSpec
4
4
  class CapturingFormatter
5
5
  # After updating this value, run `bundle exec rake bundle:install -m`
6
6
  # to sync all Bundler lockfiles.
7
- VERSION = "1.0.2"
7
+ VERSION = "1.1.0"
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-capturing-formatter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hongli Lai