[rspec-users] Another RSpec on Rails issue: how to test send_file()

Tobias Grimm listaccount at e-tobi.net
Sun Dec 31 04:58:52 EST 2006


s.ross wrote:
> Well, here's one I just dealt with. The spec might not be great, but  
> here it is:
>   

This is kinda different from what I want to do. My controller looks like
this:

...
def images
  image_file_name = get_image_file_name_by_id(params[:id])
  send_file(image_file_name, :type => 'image/png', :disposition => 'inline')
end
..

I can test with response.should_be_success that this request works.

setup do
  get(:images, :id => 'test-image')
end

spec "should be successful" do
  response.should_be_success
end

spec "should return mime type image/png'
  # dont know how to test this
end

spec "image data should be inline'
  # dont know how to test this
end

spec "should return the content of the image file"
  # test-images simply contains "dummy-data" - but how do I check this?
end

But I don't know how to check, if the content sent to the client with
send_file is correct. During running the spec, the image file is a
simple text file - But how do I get access to the content, the mime
header and the content disposition field to check if these are correct?

Tobias



More information about the rspec-users mailing list