问题
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