From 092ee12b8c59440b9269ad46b4b9269686dd312a Mon Sep 17 00:00:00 2001 From: dstroch Date: Fri, 26 Jan 2024 19:16:46 +0100 Subject: [PATCH] Fix tests --- test/onigumo_cli_test.exs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/test/onigumo_cli_test.exs b/test/onigumo_cli_test.exs index a8a193a..906c5ff 100644 --- a/test/onigumo_cli_test.exs +++ b/test/onigumo_cli_test.exs @@ -1,5 +1,6 @@ defmodule OnigumoCLITest do use ExUnit.Case + import ExUnit.CaptureIO import Mox @urls [ @@ -33,15 +34,20 @@ defmodule OnigumoCLITest do end test("run CLI with no arguments") do - assert_raise(MatchError, fn -> Onigumo.CLI.main([]) end) + assert usage_message_printed?(fn -> Onigumo.CLI.main([]) end) end test("run CLI with more than one argument") do - assert_raise(MatchError, fn -> Onigumo.CLI.main(["Downloader", "Parser"]) end) + assert usage_message_printed?(fn -> Onigumo.CLI.main(["Downloader", "Parser"]) end) end test("run CLI with invalid switch") do - assert_raise(OptionParser.ParseError, fn -> Onigumo.CLI.main(["--help"]) end) + assert usage_message_printed?(fn -> Onigumo.CLI.main(["--help"]) end) + end + + defp usage_message_printed?(function) do + output = capture_io(function) + String.starts_with?(output, "Usage: ./onigumo ") end end end