Closed andrewjensen closed 5 years ago
You have to set the default value inside the :env key in def application in your mix.exs file. The values in config are never loaded from libraries, to avoid libraries messing up the global configuration. --
José Valim www.plataformatec.com.br Skype: jv.ptec Founder and Director of R&D
Hi friends! I am working on implementing mox inside of a library at work, and I ran into problems with wiring up mox.
I had code like this to reference my implementation in prod code:
And I had config like this to provide either the real implementation or the mock:
But when I imported my library into my app and hit the
Datemath.Interpreter.evaluate_date_relative
function, I got an error sayingnil.now
was undefined. My config did not take effect in an app.The workaround I found was to call
get_env
with a default provided as a third parameter:This worked because the library will use its config while in dev or test, and apps that consume the library will fall back to the default implementation.
But is there a better way to do this? Thanks!