Rails引用本地路径的夹具

时间:2012-08-31 20:03:08

标签: ruby-on-rails ruby ruby-on-rails-3 unit-testing fixtures

我正在使用灯具,我正在运行测试,我需要访问某个人的文件的URL。我不想每次都通过互联网获取此内容,因此我已下载文件并将其放入我的测试目录"/test/sample/somefile.html"

如何在fixture文件中编写本地路径,以便在测试中访问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 个答案:

答案 0 :(得分:1)

执行:

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

如果你有旧版本的Rails,请使用RAILS_ROOT