[rspec-users] How do I specify that a class does not receive any message

J. B. Rainsberger me at jbrains.ca
Wed Aug 22 14:16:46 UTC 2012


On Wed, Aug 22, 2012 at 10:07 AM, David Chelimsky <dchelimsky at gmail.com>wrote:

> On Wed, Aug 22, 2012 at 7:52 AM, J. B. Rainsberger <me at jbrains.ca> wrote:
> > On Tue, Aug 21, 2012 at 11:37 PM, Bas Vodde <basv at odd-e.com> wrote:
> >>
> >>
> >> JB is right.
> >>
> >> Sometimes, for clarity, it is useful to add should_not, but for
> >> functionality it is usually not needed.
> >
> >
> > I know JMock has never() for this people. Should RSpec-mocks have
> something
> > like object.should_receive(:nothing).
>
> never() is not a catch all for _all_ messages. It is for a specific
> message, just like it is in rspec-mocks
>
>   # rspec
>   object.should_receive(:msg).never
>
>   #jmock
>   never(object).msg()
>

In JMock, you can write this:

never(object);

and this means "never anything". Just like

ignoring(object);
allowing(object);

which each equate to mock().as_null_object().
-- 
J. B. (Joe) Rainsberger :: http://www.jbrains.ca ::
http://blog.thecodewhisperer.com
Author, JUnit Recipes
Free Your Mind to Do Great Work :: http://www.freeyourmind-dogreatwork.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20120822/07e5e363/attachment.html>


More information about the rspec-users mailing list