2012-08-31 48 views
0

我正在使用灯具,我正在运行测试,需要从某个人访问某个文件的URL。我不想每次都通过互联网去获取这个文件,所以我已经下载了这个文件并把它放在我的测试目录"/test/sample/somefile.html"中。Rails引用本地路径的灯具

如何在夹具文件中写入本地路径,以便在我的测试中访问file_path

#BEFORE 
three: 
id: 3 
user: Joey 
file_path: http://www.google.com/somefile.html 
last_modified: 



#AFTER 
three: 
id: 3 
user: Joey 
file_path: <%= "./test/sample/somefile.html" %> 
last_modified: 

回答

1

务必:

three: 
    id: 3 
    user: Joey 
    file_path: <%= "#{Rails.root}/test/sample/somefile.html" %> 
    last_modified: 

或者使用RAILS_ROOT如果你有一个旧版本的Rails的。

+0

我正在访问该文件,但我可以让它看起来像一个URL而不是我的测试中的文件路径? – alenm

+0

我看不到如何。备用解决方案:将文件放在公用文件夹中,然后您就可以使用它的网址。 – apneadiving