And after doctest. it stayed at "*" after the last test anyway, letting the doctest fail. doctests are not recommended for side effectful tests anyway https://hexdocs.pm/ex_unit/main/ExUnit.DocTest.html
30 lines
797 B
Elixir
30 lines
797 B
Elixir
defmodule BasicSignupWhitelistTest do
|
|
use ExUnit.Case, async: false
|
|
doctest BasicSignupWhitelist
|
|
|
|
defp allow_signups_for(whitelist) do
|
|
System.put_env("SIGNUP_ALLOWED_EMAILS", whitelist)
|
|
end
|
|
|
|
describe "setup in describe block" do
|
|
setup do
|
|
on_exit(fn ->
|
|
# resetting values did not work, so 'just' set it to the effect without this module configured.
|
|
System.put_env("SIGNUP_ALLOWED_EMAILS", "*")
|
|
end)
|
|
|
|
:ok
|
|
end
|
|
|
|
test "When not set, not whitelisted" do
|
|
System.delete_env("SIGNUP_ALLOWED_EMAILS")
|
|
refute BasicSignupWhitelist.mail_whitelisted("joe@example.com")
|
|
end
|
|
|
|
test "When set to star, whitelisted" do
|
|
allow_signups_for("*")
|
|
assert BasicSignupWhitelist.mail_whitelisted("joe@example.com")
|
|
end
|
|
end
|
|
end
|