Hi all! Wondering how to best use a setup block for inserting some duplicate values for a todo_list
struct. For example-
defmodule ToDoTest do
use ExUnit.Case
describe "entries/2" do
test "entries should successfully be fetched when called by a specific date" do
todo_list = %TodoList2{
auto_id: 2,
entries: %{1 => %{date: ~D[2018-12-19], id: 1, title: "Dentist"}}
}
date = ~D[2018-12-19]
assert TodoList2.entries(todo_list, date) == [
%{date: ~D[2018-12-19], title: "Dentist", id: 1}
]
end
test "empty list should be returned when no entries exist for a specific date" do
todo_list = %TodoList2{
auto_id: 2,
entries: %{1 => %{date: ~D[2018-12-19], id: 1, title: "Dentist"}}
}
date = ~D[2018-12-20]
assert TodoList2.entries(todo_list, date) == []
end
end
end
The two tests use the same struct value for todo_list
, how do I correctly use a setup
after my `describe “entries/2” so I’m not repeating myself here? Haven’t quite figured this out from the ExUnit docs as they’re pretty basic. Thanks for any help