0
votes

Suppose we have a module A that requires a configuration. When we consume A, it's just OK to put [applications: [:a]] in mix.exs and put config :a, [] in config/config.exs in our project.

But when we're developers of the module A, how/when can we configure :a on a command of mix test in the A directory? Can we do that in test/test_helpers.exs or somewhere?

1
Is putting config inside if Mix.env == :test do ... end in config.exs not what you want?Dogbert
@Dogbert Thank you, that's what I want. mix test changes Mix.env to be :test, I see.Soichi Takamura

1 Answers

1
votes

You might want to derive the behaviour from Phoenix. What it does, is basically three additional files in config directory, named dev.exs, prod.exs and test.exs and the following clause in config.exs:

import_config "#{Mix.env}.exs"

Since mix sets the Mix.env appropriately, the respective configuration will be loaded.