Skip to content

Commit 0585424

Browse files
committed
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
1 parent 169b49c commit 0585424

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

lib/pact/configuration.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
require 'pact/shared/text_differ'
77
require 'pact/shared/form_differ'
88
require 'pact/shared/multipart_form_differ'
9+
require 'rainbow'
910

1011

1112
module Pact
@@ -114,7 +115,9 @@ def log_path
114115

115116
def color_enabled
116117
# Can't use ||= when the variable might be false, it will execute the expression if it's false
117-
defined?(@color_enabled) ? @color_enabled : true
118+
color_enabled = defined?(@color_enabled) ? @color_enabled : true
119+
Rainbow.enabled = true if color_enabled
120+
color_enabled
118121
end
119122

120123
def color_enabled= color_enabled

spec/lib/pact/configuration_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module Pact
1313
expect(subject.color_enabled).to be true
1414
end
1515

16-
it "allows configuration of colour_enabled" do
16+
it "allows configuration of color_enabled" do
1717
subject.color_enabled = false
1818
expect(subject.color_enabled).to be false
1919
end

0 commit comments

Comments
 (0)