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

Issue 2020 remove ansicon warning #2038

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions features/.nav
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
- run_all_when_everything_filtered.feature
- configuration:
- read_options_from_file.feature
- color.feature
- fail_fast.feature
- custom_settings.feature
- alias_example_to.feature
Expand Down
22 changes: 22 additions & 0 deletions features/configuration/color.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Feature: Windows may require additional solutions to display color

The output uses [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) to show text in color. Windows
systems (shells) often don't interpret those codes at all.

If you're on Windows and you see ANSI escape codes in the output
(something like `[1m [31m` ) and your text isn't in different colors,
you may need to install a utility so that your Windows shell will
interpret those codes correctly and show the colors. Here are some
popular solutions:

* [ANSICON](https://github.com/adoxa/ansicon): ANSICON runs 'on top of' cmd or powershell. This is a very
popular solution. You can set it up so that it's always used whenever
you use cmd or powershell, or use it only at specific times.

* Alternatives to cmd.exe or powershell: [ConEmu](http://conemu.github.io/), [Console2](http://sourceforge.net/projects/console/),
[ConsoleZ](https://github.com/cbucher/console)

* Unix-like shells and utilities: [cygwin](https://www.cygwin.com/), [babun](http://babun.github.io/index.html),
[MinGW](http://www.mingw.org/) (Minimalist GNU for Windows)

To find out more, search for information about those solutions.
14 changes: 1 addition & 13 deletions lib/rspec/core/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -708,19 +708,7 @@ def color_enabled?(output=output_stream)
end

# Toggle output color.
# @attr true_or_false [Boolean] toggle color enabled
def color=(true_or_false)
return unless true_or_false

if RSpec::Support::OS.windows? && !ENV['ANSICON']
RSpec.warning "You must use ANSICON 1.31 or later " \
"(http://adoxa.3eeweb.com/ansicon/) to use colour " \
"on Windows"
@color = false
else
@color = true
end
end
attr_writer :color

# @private
def libs=(libs)
Expand Down
52 changes: 0 additions & 52 deletions spec/rspec/core/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1156,58 +1156,6 @@ def metadata_hash(*args)
end
end

context "on windows" do
before do
@original_host = RbConfig::CONFIG['host_os']
RbConfig::CONFIG['host_os'] = 'mingw'
allow(config).to receive(:require)
end

after do
RbConfig::CONFIG['host_os'] = @original_host
end

context "with ANSICON available" do
around(:each) { |e| with_env_vars('ANSICON' => 'ANSICON', &e) }

it "enables colors" do
config.output_stream = StringIO.new
allow(config.output_stream).to receive_messages :tty? => true
config.color = true
expect(config.color).to be_truthy
end

it "leaves output stream intact" do
config.output_stream = $stdout
allow(config).to receive(:require) do |what|
config.output_stream = 'foo' if what =~ /Win32/
end
config.color = true
expect(config.output_stream).to eq($stdout)
end
end

context "with ANSICON NOT available" do
around { |e| without_env_vars('ANSICON', &e) }

before do
allow_warning
end

it "warns to install ANSICON" do
allow(config).to receive(:require) { raise LoadError }
expect_warning_with_call_site(__FILE__, __LINE__ + 1, /You must use ANSICON/)
config.color = true
end

it "sets color to false" do
allow(config).to receive(:require) { raise LoadError }
config.color = true
expect(config.color).to be_falsey
end
end
end

it "prefers incoming cli_args" do
config.output_stream = StringIO.new
allow(config.output_stream).to receive_messages :tty? => true
Expand Down