---------- Forwarded message ----------
From: James Mead <jamesmead44 at gmail.com>
Date: 01-Sep-2006 21:35
Subject: Re: Dealing with exec?
To: Kevin Clark <kevin.clark at gmail.com>
On 01/09/06, Kevin Clark <kevin.clark at gmail.com> wrote:
> Sorry to bug you. I was curious how you''d handle a call to exec in
a
> method you were testing. Kernel.stubs(:exec)... doesn''t seem to
work
> but I''m not sure where else an exec call might come from. Ideas?
Hmm. That''s starting to get a bit gnarly. The Kernel module methods are
included into all objects, but they are private. As a safety feature, Mocha
currently requires that the object you are messing with must respond_to? the
method you want to mock/stub. Unfortunately for you, the standard use of
respond_to? returns false for a private method. However, I have put a
slightly nasty workaround here <http://pastie.caboo.se/11299>. See what
you
think. I am loath to change the default behaviour for Mocha in this regard,
but I suppose there could be a :force => true type option.
I''m going to push hard to get mocha and stubba into Rails (or
atleast> allow it for tests on the framework). It just saves me too much work
> to ignore.
>
> http://glu.ttono.us/articles/2006/09/01/the-flexibility-of-mocha
>
Thanks for the kind words and good luck with the efforts at persuasion. Let
me know if I can help.
One final word of caution - I think Mocha gives you plenty of rope to hang
yourself with. I realise that you are retro-fitting tests to an existing
framework, but its far better to avoid use of the "partial mocking"
aspect
of Mocha by test-driving your design in the first place.
--
James.
http://blog.floehopper.org
--
James.
http://blog.floehopper.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://rubyforge.org/pipermail/mocha-developer/attachments/20060903/5005b7c7/attachment-0001.html