[mocha-developer] .class call to the mock object (or any existing methods)

Jamie Macey jamie.macey at gmail.com
Thu Nov 23 20:21:00 EST 2006

On 11/22/06, Kurman Karabukaev <kkarabuk at thoughtworks.com> wrote:
> Hi
> I run into problem trying to set expectations for the mockobject.class
> method, I had to undefine a method before I could set some expectation. Is
> there any better way of doing it?
> object = mock()
> ....
> klass = class <<object; self; end
> klass.send(:undef_method, "class")  # I had to do this because Mocha
> utilizes "method_missing(symbol, *arguments, &block) " method.
> object.expects(:class).returns(SomeClass)
> ...

I presume you're then doing something along the lines of:

  if object.class == SomeClass

Is there some way you could refactor it to use kind_of? or
instance_of? instead of asking directly for the class?  I would assume
those methods would be less of a pain to mock than class.

- Jamie

More information about the mocha-developer mailing list