菲尼克斯装置json文件 [英] Phoenix fixture json file

查看:57
本文介绍了菲尼克斯装置json文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆