简体   繁体   中英

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

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

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

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

You need to install the win32console gem. BTW: which version of RSpec are you using? Every single version of RSpec I have ever used, actually prints out

You must 'gem install win32console' to use colour on Windows

when you try to colorize output.

I'm running in Windows XP which I believe is an NT system. The ANSICON claims that this is not supported. Yes it does not work for cmd. But if you put the files in system32 folder, just run the ansicon.exe from anywhere. Win32Console is deprecated for rspec but you may still use it for other programs you write if you want color output from the command line. see the readmes in the gem. I put ansicon in my start>run>open text box. It works just fine.

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: : 无聊的旧单色

And make it happy with one simple command line argument: 哇,这是美丽的全彩色!

I had this issue. I've been unable to get ansicon to work, as it crashes when running from cmd.

To fix I added the Win32console gem to my gem file and then ran bundle update.

**As an update: Put the gem in the test group of your gemfile:

    group :test do
      gem 'rails-controller-testing', '1.0.2'
      gem 'minitest-reporters',       '1.1.14'
      gem 'guard',                    '2.13.0'
      gem 'guard-minitest',           '2.4.4'
      gem 'win32console'
    end

This will prevent errors when pushing to heroku

Cheers!

The best method is to create a file name .rspec in the root folder of your app and include this single line of code in it:

--colour

Done and dusted

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM