菲尼克斯装置json文件 [英] Phoenix fixture json file
问题描述
如何在phoenix项目中加载JSON夹具文件?
How can I load a JSON fixture file in my phoenix project?
当我尝试使用类似Application.app_dir(my_app,"priv")的方法时,它会为我提供一个已编译的路径,而我不能在测试中使用它.
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 .
还有其他方法可以从"test/support/somefile.json"中加载灯具文件吗?
Is there any other way to load a fixture file from "test/support/somefile.json" ?
推荐答案
您可以将__DIR__
与Path.expand/2
结合使用.例如,如果您的测试在test/controllers/page_controller_test.exs
中,则可以使用以下命令获取test/support/somefile.json
的路径:
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__)
这篇关于菲尼克斯装置json文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!