FlexMock v. Mocha

There are a couple of bits of functionality I rather like in Mocha, but
I can’t see how to do the same (if it’s at all possible) in FlexMock.

First, Mocha does this:

Mocha::Configuration.prevent :stubbing_non_existent_method

which gives a nice error when your API changes. This is remarkably
handy, and as I say, I can’t see if this functionality is available in
FlexMock.

Secondly, a mocked method on a partial mock in Mocha will call the
underlying method if you don’t supply a return value. I can see how this
might not be a good idea all the time, but I frequently find myself
making my tests more complicated, more verbose, or more coupled to the
innards of the class I’m testing, without better coverage, because I’m
having to work around not having a simple way to do this. Again,
FlexMock may be able to do this, but if it does, I can’t see how
without going through an
#and_return{ mess_with_privates } incantation.

Am I just Doing It Wrong™?


Alex

Alex Y. wrote in post #984436:

There are a couple of bits of functionality I rather like in Mocha, but
I can’t see how to do the same (if it’s at all possible) in FlexMock.

Then use Mocha :slight_smile:

I changed from Flexmock to Mocha several years back. I forget what the
specific functionality was that I needed, but I also found that Mocha
gives much better error messages when tests fail, making it much easier
to trace the problem.

Regards,

Brian

Yeah, it’s looking like a good option right now. For some reason I had
it fixed in my head that Mocha used ObjectSpace, which would have ruled
it out ('cos we’re aiming for both JRuby and MRI), but that doesn’t seem
to be true.


Alex