可配置的颜色

RSpec 允许您配置文本格式化程序中使用的终端颜色。

颜色指定为符号。选项为:black:red:green:yellow:blue:magenta:cyan:white:bold_black:bold_red:bold_green:bold_yellow:bold_blue:bold_magenta:bold_cyan:bold_white

自定义失败颜色

给定一个名为“custom_failure_color_spec.rb”的文件,其中包含

RSpec.configure do |config|
  config.failure_color = :magenta
  config.color_mode = :on
end

RSpec.describe "failure" do
  it "fails and uses the custom color" do
    expect(2).to eq(4)
  end
end

我运行`rspec custom_failure_color_spec.rb --format progress`

那么失败的示例将以洋红色打印。

使用自定义控制台代码自定义失败颜色

给定一个名为“custom_failure_color_spec.rb”的文件,其中包含

RSpec.configure do |config|
  config.failure_color = "1;32"
  config.color_mode = :on
end

RSpec.describe "failure" do
  it "fails and uses the custom color" do
    expect(2).to eq(4)
  end
end

我运行`rspec custom_failure_color_spec.rb --format progress`

那么失败的示例将打印在“1;32”中。