【问题标题】:Ruby RSpec : No color on output with a MacRuby RSpec:使用 Mac 输出没有颜色
【发布时间】:2012-02-13 17:11:49
【问题描述】:

使用我的第一台 Mac 进行开发时,我注意到我的 Rspec 输出在我的终端中没有着色,即使我在命令中使用了“-c”标志:bundle exec rspec -c -fd。有任何想法吗?

【问题讨论】:

标签: ruby rspec


【解决方案1】:

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

--color

【讨论】:

  • 或者,将 .rspec 文件放在您的主目录中以应用所有项目的设置。
【解决方案2】:

如果您最近从 Google 来到这里,您可能会注意到 Allen Chun 的回答在使用 RSpec 3.0 或更高版本时给出了NoMethodError.color_enabled.color_enabled 在 3.0 中被删除:https://github.com/rspec/rspec-core/blob/master/Changelog.md#300rc1--2014-05-18

只需将spec_helper.rb 中的.color_enabled 更改为.color

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

  # other config options here...    

end

这对我在 OS X Mavericks 10.9.4 上的 Ruby 2.1.2p95 有效。

【讨论】:

  • 谢谢,这很容易!
【解决方案3】:

如果您不想在每次运行 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

【讨论】:

  • config.color_enabled = true 对我不起作用,但 config.color = true 对我有用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-12-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-15
  • 2011-06-06
相关资源
最近更新 更多