Skip to content

Commit

Permalink
fix: enable color on non-tty if color_enabled
Browse files Browse the repository at this point in the history
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
  • Loading branch information
YOU54F committed Aug 8, 2024
1 parent 169b49c commit 0585424
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/pact/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require 'pact/shared/text_differ'
require 'pact/shared/form_differ'
require 'pact/shared/multipart_form_differ'
require 'rainbow'


module Pact
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/pact/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0585424

Please sign in to comment.