jamesmead44 at gmail.com
Thu Sep 14 08:28:32 EDT 2006
On 13/09/06, Anselm Heaton <anselm at netuxo.co.uk> wrote:
> Hello :) I have a problem with the Net::HTTP library...
> The Net::HTTP library  uses a Net::HTTPResponse object for all it's
> responses from web servers. This class has many subclasses, such as
> HTTPSuccess, HTTPRedirecttion, etc.
> When obtaining a response, the library suggests to check what it is by
> the class of the returned object - using case/when or kind_of? (which it
> So I need a mock object which can pass for a Net::HTTPResponse. However I
> can't create a Net::HTTPResponse directly - the "initialize" method is not
> documented, and in the code is commented as "internal use only" - which
> suggests it might just change in the future without warning.
> The second, admitedly evil idea was to stub "kind_of?" but that doesn't
> to work with Mocha.
> I was left having to do this :
> class MySuccess < Net::HTTPSuccess
> def initialise
> success = MySuccess.new
> success.expects(:body).returns("this is the body")
> Which is a little bit frustrating - it's to avoid having to do this type
> code I'm using Mocha in the first place !
> Any ideas ?
> Thanks for this great library btw!,
>  http://ruby-doc.org/stdlib/libdoc/net/http/rdoc/classes/Net/HTTP.html
Sorry I haven't got round to reading your tutorial in detail yet - things
have been a bit hectic the last few days and I'm at RailsConf Europe today &
The problem with not being able to mock kind_of? is a known one - there are
a bunch of methods like this which I need to sort out. As a quick fix you
could patch your Mocha installation by adding this line at the bottom of the
Then you should be able to mock it. I will fix this properly soon.
Hope this helps. BTW your company looks pretty cool!
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the mocha-developer