Gave up trying to reset env var - set to "*" after test
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
This commit is contained in:
parent
ca4eaf6f54
commit
c848ca17ad
@ -21,6 +21,9 @@ defmodule BasicSignupWhitelist do
|
|||||||
iex> System.delete_env("SIGNUP_ALLOWED_EMAILS")
|
iex> System.delete_env("SIGNUP_ALLOWED_EMAILS")
|
||||||
iex> BasicSignupWhitelist.mail_whitelisted("joe@example.com")
|
iex> BasicSignupWhitelist.mail_whitelisted("joe@example.com")
|
||||||
false
|
false
|
||||||
|
iex> System.put_env("SIGNUP_ALLOWED_EMAILS","*")
|
||||||
|
iex> BasicSignupWhitelist.mail_whitelisted("joe@example.com")
|
||||||
|
true
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def mail_whitelisted(email) do
|
def mail_whitelisted(email) do
|
||||||
|
|||||||
@ -1,21 +1,16 @@
|
|||||||
defmodule BasicSignupWhitelistTest do
|
defmodule BasicSignupWhitelistTest do
|
||||||
use ExUnit.Case
|
use ExUnit.Case, async: false
|
||||||
doctest BasicSignupWhitelist
|
doctest BasicSignupWhitelist
|
||||||
|
|
||||||
defp allow_signups_for(whitelist) do
|
defp allow_signups_for(whitelist) do
|
||||||
System.put_env("SIGNUP_ALLOWED_EMAILS", whitelist)
|
System.put_env("SIGNUP_ALLOWED_EMAILS", whitelist)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "setup in describe block" do
|
||||||
setup do
|
setup do
|
||||||
# Save original env var
|
|
||||||
original_env = System.get_env("SIGNUP_ALLOWED_EMAILS")
|
|
||||||
|
|
||||||
on_exit(fn ->
|
on_exit(fn ->
|
||||||
# Restore original env var after each test
|
# resetting values did not work, so 'just' set it to the effect without this module configured.
|
||||||
case original_env do
|
System.put_env("SIGNUP_ALLOWED_EMAILS", "*")
|
||||||
nil -> System.delete_env("SIGNUP_ALLOWED_EMAILS")
|
|
||||||
value -> System.put_env("SIGNUP_ALLOWED_EMAILS", value)
|
|
||||||
end
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
:ok
|
:ok
|
||||||
@ -30,4 +25,5 @@ defmodule BasicSignupWhitelistTest do
|
|||||||
allow_signups_for("*")
|
allow_signups_for("*")
|
||||||
assert BasicSignupWhitelist.mail_whitelisted("joe@example.com")
|
assert BasicSignupWhitelist.mail_whitelisted("joe@example.com")
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user