[mocha-developer] Feature request... I think...

Ned Wolpert ned.wolpert at gmail.com
Wed Apr 11 16:56:14 EDT 2007


I just started using Mocha and I wanted to try something but I
couldn't get it to work.  I'm coming from the Java world, so my
approach may not be optimal for Ruby.

Say I'm testing a.do_something() which calls b.do_other_thing() twice,
but I really don't want to change b.do_other_thing(), just 'expect' it
to be called twice.  I know I can b.expect(:do_other_thing).times(2)
but it changes the whole method.  Unless I'm doing something wrong, I
can't do this in mocha.

I know its not mocking the object or method.  But what I really want
to do is put in a hook into validate the state of the object at the
point of time into and out of the method.  If this isn't the place of
mocha, where should I do it?

(And yes, one can easily argue that I'm likely making my test case too
complicated if I have to do this, but we found an esoteric bug on a
short-lived object and having a test to check for this specific case
would help make sure that bug stays away.)

Virtually, Ned Wolpert

"Settle thy studies, Faustus, and begin..."   --Marlowe

Discere docendo...

More information about the mocha-developer mailing list