From: Brian Candler Date: 2007-05-26T03:04:19+09:00 Subject: Re: Mocking Net::HTTP On Sat, May 26, 2007 at 01:45:06AM +0900, Enrique Comba Riepenhausen wrote: > I am currently finishing up a release of Rannel, a library for > sending sms messages through the open source SMS/WAP Gateway Kannel. > > I have a couple of Unit tests that assure that the commands are send > correctly to Kannel and all the tests are passing (i.e. it's > working :) ). > > Looking at the unit test code though, I realized, that I am violating > one of the unit test premisses; The Independence of the Tests! > > Therefore I thought that I could mock up the Net::HTTP requests done > to Kannel, but my problem here is that I am not quite sure how I can > do that, as the adapters (for GET and POST requests) actually use > this package (Net::HTTP). > > What would you recommend? Should I write a MockGet/Post adapter that > will do the job? Or is there a transparent way to change the behavior > of Net::HTTP without touching the adapters? I'm pretty sure Flexmock can do this. http://onestepback.org/software/flexmock/ Scan down to "Mocking Class Objects". I've used it to mock calls to my own classes (but not Net::HTTP)