Back

测试文件上传 (test file upload in Rails )

发布时间: 2013-03-16 06:09:00

非常简单。 You can use fixture_file_upload method to test file uploading: Put your test file in "{Rails.root}/spec/fixtures/files" directory

before :each do
  @file = fixture_file_upload('files/test_lic.xml', 'text/xml')
end

it "can upload a license" do
  post :uploadLicense, :upload => @file
  response.should be_success
end

记得第二个参数是 mime类型, 比如  'image/png', 'image/jpeg' 啥的。  ( the second parameter is the MIME type)

Back