Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit c72d232

Browse files
don't warn if ANSICON not installed on Windows. Document ANSICON utils for Windows in colors.feature
issue #2020 don't need to test if ANSICON installed on windows (that's up to the user; ok if it isn't) document Windows utils available for showing color (ex: ANSICON and other solutions) moved 'Windows may need solutions to show ANSI codes' into its own feature file. Massaged text to it can stand alone. added new 'color.feature' file into .nav file after 'read_options_from_file.feature' (in configuration section) replaced color= method with attr_writer :color; fixed typo in color.feature. Added link to wikipedia definition for ANSI escape code in color.feature
1 parent b2b5af2 commit c72d232

File tree

4 files changed

+25
-64
lines changed

4 files changed

+25
-64
lines changed

features/.nav

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
- run_all_when_everything_filtered.feature
4141
- configuration:
4242
- read_options_from_file.feature
43+
- color.feature
4344
- fail_fast.feature
4445
- custom_settings.feature
4546
- alias_example_to.feature

features/configuration/color.feature

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Feature: Windows may require additional solutions to display color
2+
3+
The output uses [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) to show text in color. Windows
4+
systems (shells) often don't interpret those codes at all.
5+
6+
If you're on Windows and you see ANSI escape codes in the output
7+
(something like `[1m [31m` ) and your text isn't in different colors,
8+
you may need to install a utility so that your Windows shell will
9+
interpret those codes correctly and show the colors. Here are some
10+
popular solutions:
11+
12+
* [ANSICON](https://github.com/adoxa/ansicon): ANSICON runs 'on top of' cmd or powershell. This is a very
13+
popular solution. You can set it up so that it's always used whenever
14+
you use cmd or powershell, or use it only at specific times.
15+
16+
* Alternatives to cmd.exe or powershell: [ConEmu](http://conemu.github.io/), [Console2](http://sourceforge.net/projects/console/),
17+
[ConsoleZ](https://github.com/cbucher/console)
18+
19+
* Unix-like shells and utilities: [cygwin](https://www.cygwin.com/), [babun](http://babun.github.io/index.html),
20+
[MinGW](http://www.mingw.org/) (Minimalist GNU for Windows)
21+
22+
To find out more, search for information about those solutions.

lib/rspec/core/configuration.rb

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -695,9 +695,7 @@ def full_backtrace=(true_or_false)
695695
#
696696
# @see color_enabled?
697697
# @return [Boolean]
698-
def color
699-
value_for(:color) { @color }
700-
end
698+
attr_writer :color
701699

702700
# Check if color is enabled for a particular output.
703701
# @param output [IO] an output stream to use, defaults to the current
@@ -711,15 +709,7 @@ def color_enabled?(output=output_stream)
711709
# @attr true_or_false [Boolean] toggle color enabled
712710
def color=(true_or_false)
713711
return unless true_or_false
714-
715-
if RSpec::Support::OS.windows? && !ENV['ANSICON']
716-
RSpec.warning "You must use ANSICON 1.31 or later " \
717-
"(http://adoxa.3eeweb.com/ansicon/) to use colour " \
718-
"on Windows"
719-
@color = false
720-
else
721-
@color = true
722-
end
712+
@color = !!true_or_false
723713
end
724714

725715
# @private

spec/rspec/core/configuration_spec.rb

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,58 +1156,6 @@ def metadata_hash(*args)
11561156
end
11571157
end
11581158

1159-
context "on windows" do
1160-
before do
1161-
@original_host = RbConfig::CONFIG['host_os']
1162-
RbConfig::CONFIG['host_os'] = 'mingw'
1163-
allow(config).to receive(:require)
1164-
end
1165-
1166-
after do
1167-
RbConfig::CONFIG['host_os'] = @original_host
1168-
end
1169-
1170-
context "with ANSICON available" do
1171-
around(:each) { |e| with_env_vars('ANSICON' => 'ANSICON', &e) }
1172-
1173-
it "enables colors" do
1174-
config.output_stream = StringIO.new
1175-
allow(config.output_stream).to receive_messages :tty? => true
1176-
config.color = true
1177-
expect(config.color).to be_truthy
1178-
end
1179-
1180-
it "leaves output stream intact" do
1181-
config.output_stream = $stdout
1182-
allow(config).to receive(:require) do |what|
1183-
config.output_stream = 'foo' if what =~ /Win32/
1184-
end
1185-
config.color = true
1186-
expect(config.output_stream).to eq($stdout)
1187-
end
1188-
end
1189-
1190-
context "with ANSICON NOT available" do
1191-
around { |e| without_env_vars('ANSICON', &e) }
1192-
1193-
before do
1194-
allow_warning
1195-
end
1196-
1197-
it "warns to install ANSICON" do
1198-
allow(config).to receive(:require) { raise LoadError }
1199-
expect_warning_with_call_site(__FILE__, __LINE__ + 1, /You must use ANSICON/)
1200-
config.color = true
1201-
end
1202-
1203-
it "sets color to false" do
1204-
allow(config).to receive(:require) { raise LoadError }
1205-
config.color = true
1206-
expect(config.color).to be_falsey
1207-
end
1208-
end
1209-
end
1210-
12111159
it "prefers incoming cli_args" do
12121160
config.output_stream = StringIO.new
12131161
allow(config.output_stream).to receive_messages :tty? => true

0 commit comments

Comments
 (0)