2012-08-31 42 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