diff --git a/config/dev.exs b/config/dev.exs index 4a906a5..82fae0c 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -1,3 +1,4 @@ import Config config(:onigumo, :http_client, HTTPoison) +config(:onigumo, :downloader, Onigumo.Downloader) diff --git a/config/test.exs b/config/test.exs index acade56..995249c 100644 --- a/config/test.exs +++ b/config/test.exs @@ -1,3 +1,4 @@ import Config config(:onigumo, :http_client, HTTPoisonMock) +config(:onigumo, :downloader, OnigumoDownloaderMock) diff --git a/lib/cli.ex b/lib/cli.ex index 53e2f6f..0e91033 100644 --- a/lib/cli.ex +++ b/lib/cli.ex @@ -1,6 +1,6 @@ defmodule Onigumo.CLI do @components %{ - :downloader => Onigumo.Downloader + :downloader => Application.compile_env(:onigumo, :downloader) } def main(argv) do diff --git a/test/onigumo_cli_test.exs b/test/onigumo_cli_test.exs index d388889..4d05313 100644 --- a/test/onigumo_cli_test.exs +++ b/test/onigumo_cli_test.exs @@ -18,13 +18,15 @@ defmodule OnigumoCLITest do 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) - Onigumo.CLI.main(["downloader"]) + + assert Onigumo.CLI.main(["downloader"]) == tmp_dir end for argument <- @invalid_arguments do diff --git a/test/test_helper.exs b/test/test_helper.exs index e6511e3..e16a0ae 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -1,3 +1,4 @@ ExUnit.start() Mox.defmock(HTTPoisonMock, for: HTTPoison.Base) +Mox.defmock(OnigumoDownloaderMock, for: Onigumo.Component)