我有一个 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"