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

时间秒杀一切 提交于 2020-01-01 08:27:11

问题


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


回答1:


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




回答2:


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




回答3:


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



回答4:


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.




回答5:


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.




回答6:


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:




回答7:


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!




回答8:


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



来源:https://stackoverflow.com/questions/1733348/how-do-i-get-colour-with-windows-command-prompt-using-rspec-in-ruby

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!