Kurman Karabukaev
2006-Nov-22 22:12 UTC
[mocha-developer] .class call to the mock object (or any existing methods)
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) ... And thanks for such a nice library. ------------------------------ Kurman Karabukaev Application Developer ThoughtWorks Inc. (312) 282 0231 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mocha-developer/attachments/20061122/fa8a9d14/attachment.html
James Mead
2006-Nov-23 10:30 UTC
[mocha-developer] .class call to the mock object (or any existing methods)
On 22/11/06, Kurman Karabukaev <kkarabuk at thoughtworks.com> wrote:> I run into problem trying to set expectations for the mockobject.classmethod, 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) > ...This is a known problem. There isn''t currently a better way. I hope to release a new version shortly which will allow you to mock methods defined in Object, etc. And thanks for such a nice library. I''m glad you like it. -- James. http://blog.floehopper.org -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mocha-developer/attachments/20061123/7986fd91/attachment.html
Jamie Macey
2006-Nov-24 01:21 UTC
[mocha-developer] .class call to the mock object (or any existing methods)
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