Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Add support for bright colors #2913

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion features/formatters/configurable_colors.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ Feature: Configurable colors
* `detail_color`: Color used for miscellaneous test details (default: `:cyan`)

Colors are specified as symbols. Options are `:black`, `:red`, `:green`,
`:yellow`, `:blue`, `:magenta`, `:cyan`, and `:white`.
`:yellow`, `:blue`, `:magenta`, `:cyan`, `:white`, `:bold_black`, `:bold_red`,
`:bold_green`, `:bold_yellow`, `:bold_blue`, `:bold_magenta`, `:bold_cyan`,
and `:bold_white`,

@keep-ansi-escape-sequences
Scenario: Customizing the failure color
Expand Down
34 changes: 34 additions & 0 deletions features/formatters/configurable_colors_pending.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Feature: Configurable colors

RSpec allows you to configure the terminal colors used in the text formatters.

* `failure_color`: Color used when tests fail (default: `:red`)
* `success_color`: Color used when tests pass (default: `:green`)
* `pending_color`: Color used when tests are pending (default: `:yellow`)
* `fixed_color`: Color used when a pending block inside an example passes, but
was expected to fail (default: `:blue`)
* `detail_color`: Color used for miscellaneous test details (default: `:cyan`)

Colors are specified as symbols. Options are `:black`, `:red`, `:green`,
`:yellow`, `:blue`, `:magenta`, `:cyan`, `:white`, `:bold_black`, `:bold_red`,
`:bold_green`, `:bold_yellow`, `:bold_blue`, `:bold_magenta`, `:bold_cyan`,
and `:bold_white`,

@keep-ansi-escape-sequences
Scenario: Customizing the failure color
Given a file named "custom_pending_failure_color_spec.rb" with:
"""ruby
RSpec.configure do |config|
config.fixed_color = :bold_blue
config.color_mode = :on
end

RSpec.describe "pending" do
it "hasn't been implemented yet" do
pending("passing when not implemented is a failure")
true
end
end
"""
When I run `rspec custom_pending_failure_color_spec.rb --format progress`
Then the pending example is printed in bold_blue
26 changes: 17 additions & 9 deletions lib/rspec/core/formatters/console_codes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,23 @@ module ConsoleCodes
# @private
VT100_CODES =
{
:black => 30,
:red => 31,
:green => 32,
:yellow => 33,
:blue => 34,
:magenta => 35,
:cyan => 36,
:white => 37,
:bold => 1,
:black => 30,
:red => 31,
:green => 32,
:yellow => 33,
:blue => 34,
:magenta => 35,
:cyan => 36,
:white => 37,
:bold_black => '1;30',
:bold_red => '1;31',
:bold_green => '1;32',
:bold_yellow => '1;33',
:bold_blue => '1;34',
:bold_magenta => '1;35',
:bold_cyan => '1;36',
:bold_white => '1;37',
:bold => 1,
}
# @private
VT100_CODE_VALUES = VT100_CODES.invert
Expand Down
24 changes: 24 additions & 0 deletions spec/rspec/core/formatters/console_codes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
end
end

context "when given a VT100 compound code" do
it "returns the code" do
expect(console_codes.console_code_for('1;32')).to eq '1;32'
end
end

context "when given a symbolic name" do
it "returns the code" do
expect(console_codes.console_code_for(:green)).to eq 32
Expand Down Expand Up @@ -41,19 +47,37 @@
end
end

context "when given a VT100 compound code" do
it "formats the text with it" do
expect(console_codes.wrap('abc', '1;32')).to eq "\e[1;32mabc\e[0m"
end
end

context "when given a symbolic color name" do
it "translates it to the correct integer code and formats the text with it" do
expect(console_codes.wrap('abc', :green)).to eq "\e[32mabc\e[0m"
end
end

context "when given a symbolic bold color name" do
it "translates it to the correct integer code and formats the text with it" do
expect(console_codes.wrap('abc', :bold_green)).to eq "\e[1;32mabc\e[0m"
end
end

context "when given an rspec code" do
it "returns the console code" do
RSpec.configuration.success_color = :blue # blue is 34
expect(console_codes.wrap('abc', :success)).to eq "\e[34mabc\e[0m"
end
end

context "when given a compound rspec code" do
it "returns the console code" do
RSpec.configuration.success_color = :bold_blue # blue is 34
expect(console_codes.wrap('abc', :success)).to eq "\e[1;34mabc\e[0m"
end
end

context "when given :bold" do
it "formats the text as bold" do
Expand Down