Skip to content

Commit

Permalink
Fix color-related test failures
Browse files Browse the repository at this point in the history
The `red`, `yellow`, etc. helpers within `formatter_test.rb` are
specifically used only for testing logfile output, not console output.
Since color is not present in logfile output for SSHKit > 1.7.1, these
helpers essentially do nothing in the latest SSHKit.

Therefore, when asserting color console output, it is necessary to use
the actual ANSI color control codes, as this commit does in the
`test_log_message_levels`. Note that tests that require color must
explicitly turn on color using `airbrussh_config.color = true`.

I removed the color expectations from `test_handles_rake_tasks`, since
color is not enabled for that test.
  • Loading branch information
mattbrictson committed Apr 11, 2017
1 parent 5e8e9c8 commit 4163da1
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions test/airbrussh/formatter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,15 @@ def test_handles_rake_tasks
" 02 command 2\n",
/ ✔ 02 #{@user_at_localhost} \d.\d+s\n/,
"00:00 special_rake_task_2\n",
" #{red('ERROR')} New task starting\n",
" ERROR New task starting\n",
"00:00 special_rake_task_3\n",
" 01 echo command 3\n",
" 01 command 3\n",
/ ✔ 01 #{@user_at_localhost} \d.\d+s\n/,
" 02 echo command 4\n",
" 02 command 4\n",
/ ✔ 02 #{@user_at_localhost} \d.\d+s\n/,
" #{red('WARN')} All done\n"
" WARN All done\n"
)

assert_log_file_lines(
Expand All @@ -268,7 +268,8 @@ def test_handles_rake_tasks
end

def test_log_message_levels
configure do |_airbrussh_config, sshkit_config|
configure do |airbrussh_config, sshkit_config|
airbrussh_config.color = true
sshkit_config.output_verbosity = Logger::DEBUG
end

Expand All @@ -280,9 +281,9 @@ def test_log_message_levels

assert_output_lines(
" Test\n",
" #{red('FATAL')} Test\n",
" #{red('ERROR')} Test\n",
" #{yellow('WARN')} Test\n",
" \e[0;31;49mFATAL\e[0m Test\n",
" \e[0;31;49mERROR\e[0m Test\n",
" \e[0;33;49mWARN\e[0m Test\n",
" Test\n"
)

Expand Down

0 comments on commit 4163da1

Please sign in to comment.