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

Ned Wolpert ned.wolpert at gmail.com
Sun Apr 15 17:22:04 EDT 2007


Yeah, that's true.  What I really want is
c.proxy(:do_something).times(2)
as a way of calling something that did what you mention below.
It wouldn't be hard to whip up... I just thought it made sense to have
it in Mocha... though I do understand its not 'mocking objects'.

On 4/14/07, Dan North <dan at tastapod.com> wrote:
> You could try something like this:
>
> def test_check_state_of_b
>   class B
>     alias :original_do_something :do_something
>     def do_something(*args)
>       # pre-checks here
>       original_do_something(*args)
>       # post-checks here
>     end
>   end
>
>   # body of test here
>
>   class B
>     alias :do_something :original_do_something
>   end
> end
>
> It's evil, but it works. In fact if you inject the instance of b into a,
> you could just doctor the specific instance of b rather than the whole B
> class.
>
> Cheers,
> Dan
>
>
> Ned Wolpert wrote:
> > Folks-
> >
> > 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.)
> >
> >
>
> _______________________________________________
> mocha-developer mailing list
> mocha-developer at rubyforge.org
> http://rubyforge.org/mailman/listinfo/mocha-developer
>


-- 
Virtually, Ned Wolpert

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

Discere docendo...


More information about the mocha-developer mailing list