1
votes

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

1 Answers

7
votes

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__)