From 70bf01184fa531a5ef454928dbc2e214e3a4a27b Mon Sep 17 00:00:00 2001 From: Theodor Fiedler Date: Tue, 19 Mar 2024 21:33:46 +0100 Subject: [PATCH] cleanup tests --- test/lib/changelog_test.exs | 20 +++++++++----------- test/lib/expublish_test.exs | 2 +- test/support/test_helper.ex | 4 ---- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/test/lib/changelog_test.exs b/test/lib/changelog_test.exs index 671de69..90bfcfc 100644 --- a/test/lib/changelog_test.exs +++ b/test/lib/changelog_test.exs @@ -44,23 +44,21 @@ defmodule ChangelogTest do assert Changelog.build_title(version) =~ ~r/#{version} - \d{4}-\d{2}-\d{2}/ end - test "build_title/3 formats date-time to ISO 8601 date by default", %{options: options, version: version} do - dt = DateTime.utc_now() + test "build_title/3 formats datetime to ISO 8601 date by default", %{options: options, version: version} do + naive_datetime = NaiveDateTime.utc_now() - date_format = parts_to_iso([dt.year, dt.month, dt.day]) + title = Changelog.build_title(version, options, naive_datetime) - title = Changelog.build_title(version, options, dt) - - assert title == "## #{version} - #{date_format}" + assert title == "## #{version} - #{NaiveDateTime.to_date(naive_datetime)}" end - test "build_title/3 may format date-time to ISO 8601 date-time", %{version: version} do - dt = DateTime.utc_now() + test "build_title/3 may format datetime to ISO 8601 date-time", %{version: version} do + naive_datetime = NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second) - date_format = parts_to_iso([dt.year, dt.month, dt.day]) - time_format = parts_to_iso([dt.hour, dt.minute, dt.second], ":") + date_format = NaiveDateTime.to_date(naive_datetime) + time_format = NaiveDateTime.to_time(naive_datetime) - title = Changelog.build_title(version, %Options{changelog_date_time: true}, dt) + title = Changelog.build_title(version, %Options{changelog_date_time: true}, naive_datetime) assert title == "## #{version} - #{date_format} #{time_format}" end diff --git a/test/lib/expublish_test.exs b/test/lib/expublish_test.exs index 623aadf..33c666f 100644 --- a/test/lib/expublish_test.exs +++ b/test/lib/expublish_test.exs @@ -23,7 +23,7 @@ defmodule ExpublishTest do assert capture_log(fun) =~ "working directory not clean" - File.rm!("expublish_major_test") + on_exit(fn -> File.rm!("expublish_major_test") end) end test "major/1 runs without errors", %{options: options} do diff --git a/test/support/test_helper.ex b/test/support/test_helper.ex index 7b55d56..aa4574e 100644 --- a/test/support/test_helper.ex +++ b/test/support/test_helper.ex @@ -10,8 +10,4 @@ defmodule Expublish.TestHelper do File.rm!("RELEASE.md") end end - - def parts_to_iso(parts, separator \\ "-") do - Enum.map_join(parts, separator, &String.pad_leading("#{&1}", 2, "0")) - end end