I sometimes have to log a user in at the top of all the tests of a describe block. Like so:
describe "some set of tests" do
test "A", %{conn: conn} do
conn = log_in_user(conn, user)
# do something
# assert or refute something
end
test "B", %{conn: conn} do
conn = log_in_user(conn, user)
# do something
# assert or refute something
end
test "C", %{conn: conn} do
conn = log_in_user(conn, user)
# do something
# assert or refute something
end
end
Is there anyway to log in a user in a setup tag, instead? Something like:
describe "some set of tests" do
setup do
%{conn: log_in_user(new_conn(), user_fixture())}
end
test "A", %{conn: conn} do
# do something
# assert or refute something
end
test "B", %{conn: conn} do
# do something
# assert or refute something
end
test "C", %{conn: conn} do
# do something
# assert or refute something
end
end
I looked for solutions online, and mainly in the official documentation, but I can’t seem to find the info I am looking for.