[mocha-developer] Expecting calls with two different parameters

Bryan Helmkamp bhelmkamp at gmail.com
Sun Oct 8 16:31:13 EDT 2006

Thanks, Kevin and James.  The key is instead of writing the mock like this:


You have to write it like this:


The first example won't work.  If you don't want to specify the
paramaters passed in one of the method calls, you can do:


And that works too.



On 10/7/06, James Mead <jamesmead44 at gmail.com> wrote:
> On 10/6/06, Bryan Helmkamp <bhelmkamp at gmail.com> wrote:
> > How would I setup a mock that expects that a method will be called
> > once with no paramaters, and a second time with a parameter?  I'd be
> > tempted to shortcut and just do something like
> > foo.expects(:bar).times(2), but the value used as the parameter when
> > calling it the second time is very important.
> You shoud be able to do the following...
>   def test_me
>     object = mock()
>     object.expects(:expected_method).with(:important_value)
>      object.expects(:expected_method)
>     object.expected_method(:important_value)
>     object.expected_method(:another_value)
>    end
> Is that what you mean? Calling expects() without a call to with() matches a
> call to the method with any parameters.
> --
> James.
>  http://blog.floehopper.org
> _______________________________________________
> mocha-developer mailing list
> mocha-developer at rubyforge.org
> http://rubyforge.org/mailman/listinfo/mocha-developer

http://www.MyCongress.org/ -- coming soon

More information about the mocha-developer mailing list