From 4f01bc9800ce7ec8c788ec70ac38b4c9cee957d8 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Thu, 8 Aug 2024 18:08:10 +0100 Subject: [PATCH] fix: set color codes even on dumb terms (prev behaviour) --- lib/pact/provider/matchers/messages.rb | 6 +++--- lib/pact/provider/rspec/pact_broker_formatter.rb | 2 +- spec/lib/pact/provider/matchers/messages_spec.rb | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/pact/provider/matchers/messages.rb b/lib/pact/provider/matchers/messages.rb index 6e109826..1ef0419c 100644 --- a/lib/pact/provider/matchers/messages.rb +++ b/lib/pact/provider/matchers/messages.rb @@ -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 diff --git a/lib/pact/provider/rspec/pact_broker_formatter.rb b/lib/pact/provider/rspec/pact_broker_formatter.rb index 2808cf1c..dd29778e 100644 --- a/lib/pact/provider/rspec/pact_broker_formatter.rb +++ b/lib/pact/provider/rspec/pact_broker_formatter.rb @@ -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 diff --git a/spec/lib/pact/provider/matchers/messages_spec.rb b/spec/lib/pact/provider/matchers/messages_spec.rb index 7bec993b..4a1150f4 100644 --- a/spec/lib/pact/provider/matchers/messages_spec.rb +++ b/spec/lib/pact/provider/matchers/messages_spec.rb @@ -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 }