非常简单。 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)