Tor*_*inz 13
这对我来说很有用,就像使用send_data一样 send_data(data, :filename => "inventory_#{Date.today.to_s}.csv", :disposition => 'attachment')
可能不是编写步骤的最佳方式,但它有效!
Then /^I should receive a file(?: "([^"]*)")?/ do |file|
result = page.response_headers['Content-Type'].should == "application/octet-stream"
if result
result = page.response_headers['Content-Disposition'].should =~ /#{file}/
end
result
end
Run Code Online (Sandbox Code Playgroud)
kri*_*ard 11
我发现这是一种测试下载的便捷方式,它是一种简单的方式,只是测试大多数时候放置的标头是合理的.
如果您使用的是capbybara,请将以下内容放在step_definitions.rb中
Then /^I should get a download with the filename "([^\"]*)"$/ do |filename|
page.response_headers['Content-Disposition'].should include("filename=\"#{filename}\"")
end
Run Code Online (Sandbox Code Playgroud)
您可以在功能内部执行以下操作:
When I follow "Export as ZIP"
Then I should get a download with the filename "contacts_20110203.zip"
Run Code Online (Sandbox Code Playgroud)
干杯
| 归档时间: |
|
| 查看次数: |
9936 次 |
| 最近记录: |