我有一个请求规范,试图在我的Rails 3.1中测试文件下载功能。该规范(部分)如下:如何使用Rails,Paperclip和RSpec请求规范测试文件下载?
get document_path(Document.first)
logger(response.body)
response.should be_success
它失败:
Failure/Error: response.should be_success
expected success? to return true, got false
但是,如果我在浏览器中测试下载,它正确地下载文件。
这里是在控制器中的作用:
def show
send_file @document.file.path, :filename => @document.file_file_name,
:content_type => @document.file_content_type
end
我的记录器提供了有关回应此信息:
<html><body>You are being <a href="http://www.example.com/">redirected</a>.</body></html>
我怎样才能得到这个测试通过?
更新:
正如一些人士指出,我before_filters的人做重定向。原因是我使用Capybara登录测试,但没有使用它的方法来浏览网站。这是什么工作(部分):
click_link 'Libraries'
click_link 'Drawings'
click_link 'GS2 Drawing'
page.response.should be_success #this still fails
但现在我想不出一种方法来测试实际的响应是成功的。我在这里做错了什么。
声音对我喜欢之前的过滤器(例如,检查用户登录的过滤器)在动作运行之前重定向。 – 2012-01-05 19:29:01
你真的很棒。不过,我仍然无法测试回应。 – croceldon 2012-01-05 19:59:38
@croceldon:让我知道下面的登录方法(在AuthenticationHelpers中)是否有所作为 - 我很想知道它是否是同样的问题。 – 2012-01-11 19:34:41