我有以下 rspec 代码来测试二进制文件的上传和下载。我知道我可以检查“内容类型”以验证文件是否已正确上传和下载。但是我如何根据以下内容运行 MD5 以确保它们实际上是同一个文件。
it "should upload a file" do
file = Rack::Test::UploadedFile.new("./HelloWorld.bin", "application/octet-stream")
json = {:md5sum => "0cd74c7a3cf2207ffd68d43177681e6b", :config => "./testconfig.yaml"}.to_json
post "/upload", :json => json, :file => file
last_response.should be_ok
(JSON.parse(last_response.body)["status"]).should be_true
(JSON.parse(last_response.body)["filename"]).should eq("HelloWorld.bin")
end
it "download a file successfully" do
filename = "HelloWorld.bin"
get '/download/' + filename
last_response.should be_ok
last_response.headers['Content-Type'].should eq "application/octet-stream"
end
'last_response.body'可以在get '/download'中分配为二进制文件吗?