通过检查Content-Type进行RSpec send_file测试

时间:2012-02-04 10:19:36

标签: ruby-on-rails rspec sendfile

我有一个Rails控制器,它发送一个具有不同Content-Type

的文件

Exel-File示例,控制器设置Content-Type = "application/excel"

这是RSpec测试:

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

测试的答案是:

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 个答案:

答案 0 :(得分:0)

如果你愿意(或已经在使用)思想机器人应该是宝石,回形针挂钩它

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

并且有一个s3上传方法。