From 5a40985dbcac5eff4ef5f814dd463305b75a91a7 Mon Sep 17 00:00:00 2001 From: Matt Brictson Date: Wed, 15 Jul 2015 14:06:45 -0700 Subject: [PATCH] Fix color expectations when $stdout.tty? is false --- test/airbrussh/formatter_test.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/test/airbrussh/formatter_test.rb b/test/airbrussh/formatter_test.rb index b9d9130..56873d9 100644 --- a/test/airbrussh/formatter_test.rb +++ b/test/airbrussh/formatter_test.rb @@ -402,14 +402,15 @@ def command_failed(exit_status) :bold_yellow => "1;33;49" }.each do |color, code| define_method(color) do |string| - color_if_legacy(string, code) + color_if_expected(string, code) end end - def color_if_legacy(text, color) - # SSHKit versions up to 1.7.1 added colors to the log file even though it did not have a tty. - # Versions after this don't, so we must match output both with, and without colors - # depending on the SSHKit version. + # Whether or not SSHKit emits color depends on the test environment. SSHKit + # versions up to 1.7.1 added colors to the log file, but only if + # `$stdout.tty?` is true. Later versions never output color to the log file. + def color_if_expected(text, color) + return text unless $stdout.tty? if sshkit_after?("1.7.1") || sshkit_master? text else