Skip to content

Commit

Permalink
don't warn if ANSICON not installed on Windows. Document ANSICON util…
Browse files Browse the repository at this point in the history
…s 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
  • Loading branch information
weedySeaDragon committed Jul 27, 2015
1 parent b2b5af2 commit c72d232
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 64 deletions.
1 change: 1 addition & 0 deletions features/.nav
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
@@ -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: 2 additions & 12 deletions lib/rspec/core/configuration.rb
Expand Up @@ -695,9 +695,7 @@ def full_backtrace=(true_or_false)
#
# @see color_enabled?
# @return [Boolean]
def color
value_for(:color) { @color }
end
attr_writer :color

# Check if color is enabled for a particular output.
# @param output [IO] an output stream to use, defaults to the current
Expand All @@ -711,15 +709,7 @@ def color_enabled?(output=output_stream)
# @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
@color = !!true_or_false
end

# @private
Expand Down
52 changes: 0 additions & 52 deletions spec/rspec/core/configuration_spec.rb
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

0 comments on commit c72d232

Please sign in to comment.