Forum: Ruby on Rails Functional tests with actions that send files

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
De271a04fe7a67b884ce75404c1dcc61?d=identicon&s=25 Chris Gernon (kabigon)
on 2007-01-11 23:08
I have a number of actions that use the spreadsheet/excel library to
generate an Excel spreadsheet based on model data and send it to the
user using the send_file method.

For a while, I've been testing these methods with assert_response
:success, and then checking the response headers to make sure the file
at least looks like what I should be getting. But it occurred to me
recently that I could use the parseexcel library to actually test the
correctness of the contents of the file, if I can access it.

So: is there any way to save the file being sent to a temporary file
from within the functional test? Can the data be accessed using the
response object somehow? I've tried poking around at the response
object, but haven't really gotten anywhere with it.

Here's the code, if it makes a difference:

  def item_list_as_spreadsheet
    filepath = "tmp/items.xls"
    workbook =

    # details of writing data to the spreadsheet omitted for space


    send_file filepath, :filename => 'Item List.xls', :type =>

  def test_item_list_as_spreadsheet
    get :item_list_as_spreadsheet
    assert_response :success
    assert_equal 'binary',
    assert_equal 'application/; charset=utf-8',
    assert_equal 'attachment; filename="Item List.xls"',
    assert @response.headers['Content-Length'] > 1024

This topic is locked and can not be replied to.