Duncan Beevers
2007-Oct-25 19:16 UTC
[mocha-developer] Insure a method is called with no arguments.
We''ve been working with the ParameterMatchers (so cool!) but I don''t see a way to insure a method is called with no arguments. I imagined something like: user = mock(''User'') user.expects(:friends).with(nothing) Anyone run into this?
James Mead
2007-Oct-25 21:21 UTC
[mocha-developer] Insure a method is called with no arguments.
On 25/10/2007, Duncan Beevers <duncanbeevers at gmail.com> wrote:> > We''ve been working with the ParameterMatchers (so cool!) but I don''t > see a way to insure a method is called with no arguments. > > I imagined something like: > > user = mock(''User'') > user.expects(:friends).with(nothing) > > Anyone run into this? > _______________________________________________ > mocha-developer mailing list > mocha-developer at rubyforge.org > http://rubyforge.org/mailman/listinfo/mocha-developer >I''m glad you''re finding the ParameterMatchers useful. You should be able to do what you want by using with() with no parameters. mock.expects(:method).with() Let me know if that doesn''t work. In any case I quite like the nothing matcher idea, so I might add it as a more expressive alternative. Thanks -- James. http://blog.floehopper.org http://tumble.floehopper.org
Hello James et al. I was writing a bit of code yesterday and I found myself looking for Foo.never.expects(:bar) Instead of Foo.expects(:bar).never I think the first version is more syntactically friendly. That said, I haven''t looked at what it would take to make this work. Thoughts? Cheers, Jay
+1 for that if it''s straightforward to implement. On Fri, 2007-12-21 at 19:01 -0800, Jay Fields wrote:> Hello James et al. > > I was writing a bit of code yesterday and I found myself looking for > Foo.never.expects(:bar) > Instead of > Foo.expects(:bar).never > > I think the first version is more syntactically friendly. That said, > I haven''t looked at what it would take to make this work. > > Thoughts? > > Cheers, Jay > _______________________________________________ > mocha-developer mailing list > mocha-developer at rubyforge.org > http://rubyforge.org/mailman/listinfo/mocha-developer >-- Jonathan Leighton, Web Developer http://jonathanleighton.com/
On 22/12/2007, Jonathan Leighton <j at jonathanleighton.com> wrote:> > I think the first version is more syntactically friendly.Agreed.> > That said, I haven''t looked at what it would take to make this work.The problem is that the implementation for this would add another method to the Object class which I''d rather avoid because it pollutes the method name-space of every class. However all is not lost - coincidentally I''ve been playing with some significantly different syntax which would address the same issue. More soon... -- James. http://blog.floehopper.org http://tumble.floehopper.org