【发布时间】:2012-02-13 17:11:49
【问题描述】:
使用我的第一台 Mac 进行开发时,我注意到我的 Rspec 输出在我的终端中没有着色,即使我在命令中使用了“-c”标志:bundle exec rspec -c -fd。有任何想法吗?
【问题讨论】:
使用我的第一台 Mac 进行开发时,我注意到我的 Rspec 输出在我的终端中没有着色,即使我在命令中使用了“-c”标志:bundle exec rspec -c -fd。有任何想法吗?
【问题讨论】:
将以下内容添加到 .rspec 文件到您的项目目录根目录中。
--color
【讨论】:
如果您最近从 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 有效。
【讨论】:
如果您不想在每次运行 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 对我有用。