简体   繁体   English

如何在Ruby中使用RSpec获取Windows命令提示符?

[英]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). 在其他o / s RSpec返回漂亮的彩色结果(红色,绿色等)。

However in the windows (Vista) command prompt my text output is just plain old boring white. 但是在Windows(Vista)命令提示符下,我的文本输出只是普通的老无聊白色。

How can I bring colour to my RSpec test results? 如何为我的RSpec测试结果带来颜色?

Thanks 谢谢

Evolve 发展

UPDATE: Win32Console no longer works with rspec. 更新:Win32Console不再适用于rspec。 ANSICON recommended. ANSICON推荐。 https://github.com/rspec/rspec-rails/issues/487#issuecomment-3556806 https://github.com/rspec/rspec-rails/issues/487#issuecomment-3556806

I had to install ansicon, and now everything is fine. 我不得不安装ansicon,现在一切都很好。 (Even in my Aptana terminal). (即使在我的Aptana终端)。

Install ansicon description: http://qastuffs.blogspot.com/2011/02/how-to-install-ansicon-for-cucumber-to.html 安装ansicon说明: 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? 你在rake rspec任务'spec_opts中指定'--color'了吗? 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. 您需要安装win32console gem。 BTW: which version of RSpec are you using? 顺便说一句:您使用的是哪个版本的RSpec? Every single version of RSpec I have ever used, actually prints out 我曾经使用过的每个版本的RSpec,实际上是打印出来的

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. 我在Windows XP中运行,我相信它是一个NT系统。 The ANSICON claims that this is not supported. ANSICON声称不支持此功能。 Yes it does not work for cmd. 是的,它不适用于cmd。 But if you put the files in system32 folder, just run the ansicon.exe from anywhere. 但是如果你把文件放在system32文件夹中,只需从任何地方运行ansicon.exe。 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. 对于rspec,不推荐使用Win32Console,但如果要从命令行输出颜色,仍可以将它用于您编写的其他程序。 see the readmes in the gem. 看看宝石中的自述文件。 I put ansicon in my start>run>open text box. 我把ansicon放在我的开始>运行>打开文本框中。 It works just fine. 它工作得很好。

When using the MINGW64 bash shell provided by Git on Windows rspec displays things without any color. 当在Windows上使用Git提供的MINGW64 bash shell时,rspec显示没有任何颜色的东西。 While this shell environment is perfectly capable of displaying ANSI color, rspec fails to detect it as a TTY. 虽然这个shell环境完全能够显示ANSI颜色,但rspec无法将其检测为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. 我一直无法让ansicon工作,因为它从cmd运行时崩溃了。

To fix I added the Win32console gem to my gem file and then ran bundle update. 为了解决这个问题,我将Win32console gem添加到我的gem文件中 ,然后运行bundle update。

**As an update: Put the gem in the test group of your gemfile: **作为更新:将gem放在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 这将防止推送到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: 最好的方法是在应用程序的根文件夹中创建文件名.rspec,并在其中包含以下单行代码:

--colour

Done and dusted 尘埃落定

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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