RSpec send_file testing with check of Content-Type

2.8k Views Asked by At

I have a Rails Controller that send a file with different Content-Type

Example for Exel-File, the controller set Content-Type = "application/excel"

and here is the RSpec test:

describe "GET getfile" do
  it "Excel File" do
    controller.stub(:render)
    controller.should_receive(:send_file)
    get :getfile, :name => 'test+xls'
    controller.response.header.should == '???'
  end
end

The answer from the test is:

1) ExportController GET getfile Excel File
   Failure/Error: controller.response.header.should == ''
     expected: ""
          got: {"Content-Type"=>"text/html; charset=utf-8"} (using ==)
     Diff:
     @@ -1,2 +1,2 @@
     -""
     +"Content-Type" => "text/html; charset=utf-8"
1

There are 1 best solutions below

0
On

If you're willing (or already using) the thoughtbot shoulda gem, paperclip hooks into it

https://github.com/thoughtbot/paperclip/blob/master/shoulda_macros/paperclip.rb

and has an s3 upload method.