我正在研究一個涉及到Web服務的應用程序。我想開發一個代理類,它返回來自服務的假響應,所以在開發/測試應用程序的其他部分時,我不必一直要求使用請求。在Ruby中生成HTTP響應
我的應用程序期待通過Net :: HTTP生成的響應。
response = Net::HTTP.get(URI.parse('http://foo.com'))
case response
when Net::HTTPOK
# do something fun
when Net::HTTPUnauthorized
# you get the idea
我該如何製造一個響應對象,給它所有正確的標題,返回一個正文字符串等?
response = ProxyClass.response_object
case response
when Net::HTTPOk
# my app doesn't know it's being lied to
謝謝。
謝謝,有時人們依賴於奇怪的庫,即使http應該是如此簡單。很高興知道紅寶石已經建立了生成最低的http響應。 – Alan 2013-11-20 18:54:54