Test cases and color code changes for no-color option in detect cmd

Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>
This commit is contained in:
Nikita Mathur 2021-05-18 16:09:41 +05:30
parent 38fd0ef56b
commit f9659bfaf0
2 changed files with 20 additions and 5 deletions

View file

@ -306,11 +306,8 @@ class Inspec::InspecCLI < Inspec::BaseCLI
else
ui.headline("Platform Details")
if ui.color?
ui.plain Inspec::BaseCLI.format_platform_info(params: res, indent: 0, color: 36)
else
ui.plain Inspec::BaseCLI.format_platform_info(params: res, indent: 0)
end
detect_cmd_ui_color = ui.color? ? 36 : 0
ui.plain Inspec::BaseCLI.format_platform_info(params: res, indent: 0, color: detect_cmd_ui_color)
end
rescue ArgumentError, RuntimeError, Train::UserError => e
$stderr.puts e.message

View file

@ -100,6 +100,15 @@ describe "InSpec UI behavior" do
assert_exit_code 0, run_result
end
end
describe "detect command" do
let(:result) { inspec("detect") }
it "has a colorful output" do
_(result.stdout).must_include("\e[1m\e[36m")
assert_exit_code 0, result
end
end
end
describe "with --no-color option" do
@ -130,6 +139,15 @@ describe "InSpec UI behavior" do
assert_exit_code 0, run_result
end
end
describe "detect command" do
let(:result) { inspec("detect --no-color") }
it "has no color in the output" do
_(result.stdout).must_include("\e[1m\e[0m")
assert_exit_code 0, result
end
end
end
describe "exit codes" do