Skip to content

Commit

Permalink
fix: set color codes even on dumb terms (prev behaviour)
Browse files Browse the repository at this point in the history
  • Loading branch information
YOU54F committed Aug 8, 2024
1 parent 43bce74 commit e2e581c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ if ENV['X_PACT_DEVELOPMENT']
gem "pact-support", path: '../pact-support'
gem "pact-mock_service", path: '../pact-mock_service'
gem "pry-byebug"
else
gem 'pact-support', '~> 1.16', '>= 1.16.9', git: 'https://github.com/pact-foundation/pact-support.git', branch: 'fix/rainbow_enable_color_on_non_tty'
end

group :local_development do
Expand Down
6 changes: 3 additions & 3 deletions lib/pact/provider/matchers/messages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ def expected_desc_for_it expected
def colorize_if_enabled formatted_diff, color_enabled
if color_enabled
# RSpec wraps each line in the failure message with failure_color, turning it red.
# To ensure the lines in the diff that should be white, stay white, wrap each line
# in ANSI white.
formatted_diff.split("\n").collect{ |line| Rainbow(line).white }.join("\n")
# To ensure the lines in the diff that should be white, stay white, put an
# ANSI reset at the start of each line.
formatted_diff.split("\n").collect{ |line|"\e[0m#{line}" }.join("\n")
else
formatted_diff
end
Expand Down
2 changes: 1 addition & 1 deletion lib/pact/provider/rspec/pact_broker_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def format_example(example)
if example.exception
hash[:exception] = {
class: example.exception.class.name,
message: Rainbow(example.exception.message).white
message: "\e[0m#{example.exception.message}"
}
end

Expand Down
3 changes: 2 additions & 1 deletion spec/lib/pact/provider/matchers/messages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ module Matchers
let(:diff_formatter) { Pact::Matchers::UnixDiffFormatter }
let(:message) { "line1\nline2"}
let(:output_message) { "Actual: actual\n\n#{message}"}
let(:output_message_with_resets) { "Actual: \e[37mactual\e[0m\n\n#{Rainbow('line1').white}\n#{Rainbow('line2').white}"}
let(:r) { "\e[0m" }
let(:output_message_with_resets) { "Actual: \e[37mactual#{r}\n\n#{r}line1\n#{r}line2"}
let(:diff) { double("diff") }
let(:actual) { "actual" }
let(:color_enabled) { true }
Expand Down

0 comments on commit e2e581c

Please sign in to comment.