From 0585424a617c2aac5b0eb73ae6915087c70b3b00 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Thu, 8 Aug 2024 17:50:40 +0100 Subject: [PATCH] fix: enable color on non-tty if color_enabled see https://github.com/ku1ik/rainbow\?tab\=readme-ov-file\#advanced-usage preserves original behaviour of outputting color codes on non-tty/dumb terminals which caused failures in checking output when tested in gha via pact-ruby --- lib/pact/configuration.rb | 5 ++++- spec/lib/pact/configuration_spec.rb | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/pact/configuration.rb b/lib/pact/configuration.rb index 8793222..1cfc70e 100644 --- a/lib/pact/configuration.rb +++ b/lib/pact/configuration.rb @@ -6,6 +6,7 @@ require 'pact/shared/text_differ' require 'pact/shared/form_differ' require 'pact/shared/multipart_form_differ' +require 'rainbow' module Pact @@ -114,7 +115,9 @@ def log_path def color_enabled # Can't use ||= when the variable might be false, it will execute the expression if it's false - defined?(@color_enabled) ? @color_enabled : true + color_enabled = defined?(@color_enabled) ? @color_enabled : true + Rainbow.enabled = true if color_enabled + color_enabled end def color_enabled= color_enabled diff --git a/spec/lib/pact/configuration_spec.rb b/spec/lib/pact/configuration_spec.rb index 06de209..50db5e6 100644 --- a/spec/lib/pact/configuration_spec.rb +++ b/spec/lib/pact/configuration_spec.rb @@ -13,7 +13,7 @@ module Pact expect(subject.color_enabled).to be true end - it "allows configuration of colour_enabled" do + it "allows configuration of color_enabled" do subject.color_enabled = false expect(subject.color_enabled).to be false end