Skip to content

Commit

Permalink
cleanup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tfiedlerdejanze committed Mar 19, 2024
1 parent d69b816 commit 70bf011
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
20 changes: 9 additions & 11 deletions test/lib/changelog_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/lib/expublish_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions test/support/test_helper.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 70bf011

Please sign in to comment.