[mocha-developer] Scoping expectations and more ...

Gabriel Birke gabriel.birke at gmail.com
Sat Dec 2 12:49:57 EST 2006


Well,

I didn't know you can "stack" expectations this easily - it makes may
example somewhat moot.

I assumed that each "expect" would override the previous one. Btw,
does that mean that each "expect" call adds 1 to the expected number
of times the mocked method is called?

Gabriel

2006/12/2, James Mead <jamesmead44 at gmail.com>:
> Thanks for your interest in Mocha. It's quite likely that some
> behaviour is not properly documented. I might be missing something,
> but I don't see why you wouldn't write the two tests like this...
>
>  def test_m_call
>    b = B.new
>    A.any_instance.expects(:m).with(5).returns(6)
>    A.any_instance.expects(:m).with(9).returns(10)
>    assert_equal 10, b.m(9)
>    assert_equal 6, b.m(5)
>  end
>
>  def test_twocall
>    b = B.new
>    A.any_instance.expects(:m).with(6).returns(7)
>    A.any_instance.expects(:m).with(7).returns(8)
>    assert_equal 15, b.calltwice(5)
>  end
>
> I don't think the begin...end combinations in your first test buy you
> anything, does it?
>
> While your second test is an example of how to use a block with the
> with() method and a Proc with the returns() method, I don't see why
> you wouldn't just use two expectations as shown above.
>
> --
> James.
> http://blog.floehopper.org
> _______________________________________________
> mocha-developer mailing list
> mocha-developer at rubyforge.org
> http://rubyforge.org/mailman/listinfo/mocha-developer
>


-- 
--
Gabriel Birke
CEO describe europe Ltd.
http://www.d-scribe.de/


More information about the mocha-developer mailing list