Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get colour with Windows command prompt using RSpec in Ruby?

In other o/s RSpec returns nicely coloured results (red, green etc).

However in the windows (Vista) command prompt my text output is just plain old boring white.

How can I bring colour to my RSpec test results?

Thanks

Evolve

like image 442
Evolve Avatar asked Nov 14 '09 05:11

Evolve


4 Answers

When using the MINGW64 bash shell provided by Git on Windows rspec displays things without any color. While this shell environment is perfectly capable of displaying ANSI color, rspec fails to detect it as a TTY. A super simple workaround is to use:

$ rspec --force-color

For example, take this boring old monochrome: :Boring old monochrome

And make it happy with one simple command line argument: Wow, it's beautiful full color!

like image 83
Steve Bonds Avatar answered Oct 12 '22 13:10

Steve Bonds


UPDATE: Win32Console no longer works with rspec. ANSICON recommended. https://github.com/rspec/rspec-rails/issues/487#issuecomment-3556806

like image 8
ob1 Avatar answered Oct 18 '22 15:10

ob1


I had to install ansicon, and now everything is fine. (Even in my Aptana terminal).

Install ansicon description: http://qastuffs.blogspot.com/2011/02/how-to-install-ansicon-for-cucumber-to.html

like image 7
Stéphane Gerber Avatar answered Oct 18 '22 15:10

Stéphane Gerber


Did you specify '--color' in your rake rspec tasks' spec_opts? Something like this..

  Spec::Rake::SpecTask.new(:your_task_name) do |t|
    t.spec_opts = ["--color"]
    t.spec_files = [] # List of spec files
  end
like image 4
Selva Avatar answered Oct 18 '22 17:10

Selva