Elixir/PhoenixFramework-如何让test.secret.exs自动加载到测试环境中?
似乎Elixir/PhoenixFramework-如何让test.secret.exs自动加载到测试环境中?,elixir,phoenix-framework,Elixir,Phoenix Framework,似乎test.secret.exs不会在test环境中自动加载 Application.get_env(:my_app,:my_settings)返回nil,即使mytest.secret.exs包含以下内容: use Mix.Config config :my_app, :my_settings, setting1: "blah", setting2: "bleh" 我正在运行Elixir 1.4.0。prod.secret.exs由prod.exs显式加载,在
test.secret.exs
不会在test
环境中自动加载
Application.get_env(:my_app,:my_settings)
返回nil
,即使mytest.secret.exs
包含以下内容:
use Mix.Config
config :my_app, :my_settings,
setting1: "blah",
setting2: "bleh"
我正在运行Elixir 1.4.0。
prod.secret.exs
由prod.exs
显式加载,在默认Phoenix应用程序模板的末尾显示以下行:
import_config "prod.secret.exs"
默认情况下,test.exs
没有此选项,因此如果要加载test.secret.exs
,可以在test.exs
末尾添加以下内容:
import_config "test.secret.exs"
import_config "#{Mix.env}.secret.exs"
除了Dogbert的答案之外,对于那些想要为每个环境加载相应的
*.secret.exs
文件的人,您可以将其放入config/config.exs
:
import_config "test.secret.exs"
import_config "#{Mix.env}.secret.exs"
有了它,您可以从每个特定于环境的配置文件中删除
import\u config
函数调用。在test.exs
的末尾是否有import\u config“test.secret.exs”
类似于prod.exs
的函数调用?如果在config.exs
中,我是否需要这样做import_config“#{Mix.env}.exs”
Yes,它导入test.exs
test.exs
应该导入test.secret.exs
类似prod.exs
does.Gotcha。提交答案!:)再次感谢你,狗伯特!你挽救了这一天。你就像我的长生不老药守护天使。:)