Creating an HTTPResponse manually

B

Bryan M.

I'm working on an application that reaches out to a web service. I'd
like to develop a proxy class that returns a fake response from the
service, so I don't have to constantly be hitting it with requests while
I'm developing/testing other parts of the app.

My application is expecting a response generated via 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

How can I manufacture a response object, give it all the right headers,
return a body string, etc? I assumed I need to use Net::HTTPResponse,
but I can't find any documentation on creating an instance without going
through a request.

I'd like it to work like this:

response = ProxyClass.response_object

case response
when Net::HTTPOk
# my app doesn't know it's being lied to

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,112
Latest member
BrentonMcc
Top