From b0b2f5031825a668707b072e63bf18bae097eb6d Mon Sep 17 00:00:00 2001 From: Glutexo Date: Sat, 6 Apr 2024 21:29:25 +0200 Subject: [PATCH] Test CLI default working dir MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Onigumo.Downloader is now mocked, thus it’s not necessary to verify its inner workings. Testing only its call, mocking the behavior, it’s no longer required to assume what’s happening inside the module and at the same time, it became possible to check the call arugments. The root_path argument can be now checked to be set to the current working directory. --- test/onigumo_cli_test.exs | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/test/onigumo_cli_test.exs b/test/onigumo_cli_test.exs index 4d05313..fd9dd68 100644 --- a/test/onigumo_cli_test.exs +++ b/test/onigumo_cli_test.exs @@ -14,21 +14,6 @@ defmodule OnigumoCLITest do ] describe("Onigumo.CLI.main/1") do - @tag :tmp_dir - test("run CLI with 'downloader' argument", %{tmp_dir: tmp_dir}) do - expect(HTTPoisonMock, :start, fn -> nil end) - expect(HTTPoisonMock, :get!, length(@urls), &HttpSupport.response/1) - expect(OnigumoDownloaderMock, :main, fn root_path -> root_path end) - - input_path_env = Application.get_env(:onigumo, :input_path) - input_path_tmp = Path.join(tmp_dir, input_path_env) - input_file_content = InputSupport.url_list(@urls) - File.write!(input_path_tmp, input_file_content) - File.cd(tmp_dir) - - assert Onigumo.CLI.main(["downloader"]) == tmp_dir - end - for argument <- @invalid_arguments do test("run CLI with invalid argument #{inspect(argument)}") do assert_raise(MatchError, fn -> Onigumo.CLI.main([unquote(argument)]) end) @@ -47,6 +32,14 @@ defmodule OnigumoCLITest do assert usage_message_printed?(fn -> Onigumo.CLI.main(["--invalid"]) end) end + @tag :tmp_dir + test("run CLI with 'downloader' argument passing cwd", %{tmp_dir: tmp_dir}) do + expect(OnigumoDownloaderMock, :main, fn root_path -> root_path end) + + File.cd(tmp_dir) + assert Onigumo.CLI.main(["downloader"]) == tmp_dir + end + defp usage_message_printed?(function) do output = capture_io(function) String.starts_with?(output, "Usage: onigumo ")