Ruby RSpec:使用Mac输出时没有颜色

ste*_*her 29 ruby rspec

使用我的第一台Mac进行开发,我发现即使我-c在命令中使用了' '标志,我的Rspec输出也没有在我的终端中着色:bundle exec rspec -c -fd.有任何想法吗?

小智 57

将以下内容添加到项目目录根目录的.rspec文件中.

--color

  • 或者,将.rspec文件放在主目录中以应用所有项目的设置. (10认同)

fla*_*001 15

如果你从谷歌最近来到这里,你可能会注意到,艾伦春的回答给出了一个NoMethodError.color_enabled使用RSpec的3.0或更高版本时..color_enabled已删除3.0:https://github.com/rspec/rspec-core/blob/master/Changelog.md#300rc1--2014-05-18

只要改变.color_enabled.colorspec_helper.rb:

RSpec.configure do |config|
  # Use color in STDOUT
  config.color = true

  # other config options here...    

end
Run Code Online (Sandbox Code Playgroud)

这对我来说在OS X Mavericks 10.9.4上使用Ruby 2.1.2p95.


All*_*hun 7

如果您不想在每次运行rspec时附加--color,也可以将配置放在spec_helper.rb上.

RSpec.configure do |config|
 # Use color in STDOUT
   config.color_enabled = true

 # Use color not only in STDOUT but also in pagers and files
   config.tty = true

 # Use the specified formatter
   config.formatter = :documentation # :progress, :html, :textmate
end
Run Code Online (Sandbox Code Playgroud)