[mocha-developer] Feature request... I think...
ned.wolpert at gmail.com
Sun Apr 15 17:22:04 EDT 2007
Yeah, that's true. What I really want is
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
> # post-checks here
> # body of test here
> class B
> alias :do_something :original_do_something
> 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
> 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
Virtually, Ned Wolpert
"Settle thy studies, Faustus, and begin..." --Marlowe
More information about the mocha-developer