Phoenix fixture json file

ぃ、小莉子 提交于 2019-12-31 04:00:05

问题


How can I load a JSON fixture file in my phoenix project?

When I tried something like Application.app_dir(my_app, "priv"), it gives me a compiled path and I can't use that on my tests .

Is there any other way to load a fixture file from "test/support/somefile.json" ?


回答1:


You can use __DIR__ with Path.expand/2. For example, if your tests are in test/controllers/page_controller_test.exs, you can get the path to test/support/somefile.json using:

path = Path.expand("../support/somefile.json", __DIR__)


来源:https://stackoverflow.com/questions/39735962/phoenix-fixture-json-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!