test "something" do
old_env = Application.get_env(:app, Module)
new_env = Keyword.put(old_env, :key, value)
Application.put_env(:app, Module, new_env)
# Do something that reads the config
Application.put_env(:app, Module, old_env)
end
test "something" do
with_application_env :app, Module, fn(config) -> Keyword.put(config, :key, value), fn ->
# Do something that reads the config
end
end
Hi Michael
I've written a tiny lib for this -> https://github.com/lpil/temporary-env
Perhaps you might find this useful :)
Cheers,
Louis
--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/4b863c84-2062-42f3-b0a0-92b1d122f40c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hey
Mix config is global mutable state, so I'm not sure how you could handle this asynchronously.
Personally I prefer to avoid mix config where possible an instead pass values down through the supervision tree. :)
Cheers,
Louis
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/4eacd1d3-0d61-499a-bf82-076988799a53%40googlegroups.com.