Simple Net::Http stubbing / mocking

Posted by Andre Foeken Wed, 03 Sep 2008 07:02:07 GMT

Recently I've been implementing a simple web-service protocol that used Net::Http instead of ActiveResource magic. Although it was easy to mock ActiveResource objects, I found it hard to find any intel on how to mock actual Net::Http calls.

Below is a very basic example (which you can easily expand to fit your needs) of how to mock your calls. The example below shows a simple snippet that results in all 'posts' to be result in a Net::HttpSuccess object with a given XML body (which you can define)

Now define the XML data as follows:

Net::HTTP::xml_data = nil

Comments

(leave url/email »)

   Preview comment