Skip to content

Commit

Permalink
Test CLI default working dir
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Glutexo committed Apr 6, 2024
1 parent c8d714d commit b0b2f50
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions test/onigumo_cli_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 ")
Expand Down

0 comments on commit b0b2f50

Please sign in to comment.