Andrew Premdas
2012-Aug-21 20:02 UTC
[rspec-users] How do I specify that a class does not receive any message
I want to write it "should ..." do Client.should_not_receive(any_message) # do something here that might do Client.xxx end TIA Andrew -- ------------------------ Andrew Premdas blog.andrew.premdas.org -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20120821/b3ac6708/attachment.html>
J. B. Rainsberger
2012-Aug-21 20:12 UTC
[rspec-users] How do I specify that a class does not receive any message
On Tue, Aug 21, 2012 at 5:02 PM, Andrew Premdas <apremdas at gmail.com> wrote:> I want to write > > it "should ..." do > Client.should_not_receive(any_message) > # do something here that might do Client.xxx > end >I might be wrong, but if you use a mock object and set no expectations on it, it will expect no messages. Have you tried that? -- 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/20120821/fb887d2a/attachment-0001.html>
Bas Vodde
2012-Aug-22 02:37 UTC
[rspec-users] How do I specify that a class does not receive any message
JB is right. Sometimes, for clarity, it is useful to add should_not, but for functionality it is usually not needed. Bas On 22 Aug, 2012, at 4:12 AM, J. B. Rainsberger <me at jbrains.ca> wrote:> On Tue, Aug 21, 2012 at 5:02 PM, Andrew Premdas <apremdas at gmail.com> wrote: > I want to write > > it "should ..." do > Client.should_not_receive(any_message) > # do something here that might do Client.xxx > end > > I might be wrong, but if you use a mock object and set no expectations on it, it will expect no messages. Have you tried that? > -- > 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 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
J. B. Rainsberger
2012-Aug-22 12:52 UTC
[rspec-users] How do I specify that a class does not receive any message
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). -- 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/b419a22a/attachment.html>
David Chelimsky
2012-Aug-22 13:07 UTC
[rspec-users] How do I specify that a class does not receive any message
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()> -- > 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 > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
J. B. Rainsberger
2012-Aug-22 14:16 UTC
[rspec-users] How do I specify that a class does not receive any message
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>
David Chelimsky
2012-Aug-22 14:36 UTC
[rspec-users] How do I specify that a class does not receive any message
On Wed, Aug 22, 2012 at 9:16 AM, J. B. Rainsberger <me at jbrains.ca> wrote:> 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().Perhaps it goes without saying, but I was not aware of that ;) As you noted earlier this thread (not quoted above) RSpec::Mocks::Mock instances (returned by double(), mock(), or stub()) are strict by default - e.g. they''ll complain about any unexpected messages. Obviously that does not account for any real objects. I''m open to adding an API for this, but not object.should_receive(:nothing) since that syntax is for declaring expected messages. Other ideas welcome.
J. B. Rainsberger
2012-Aug-22 15:11 UTC
[rspec-users] How do I specify that a class does not receive any message
On Wed, Aug 22, 2012 at 11:36 AM, David Chelimsky <dchelimsky at gmail.com>wrote:> On Wed, Aug 22, 2012 at 9:16 AM, J. B. Rainsberger <me at jbrains.ca> wrote: > > 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(). > > Perhaps it goes without saying, but I was not aware of that ;) >I am at your service.> As you noted earlier this thread (not quoted above) RSpec::Mocks::Mock > instances (returned by double(), mock(), or stub()) are strict by > default - e.g. they''ll complain about any unexpected messages. > Obviously that does not account for any real objects. > > I''m open to adding an API for this, but not > object.should_receive(:nothing) since that syntax is for declaring > expected messages. >I agree that that doesn''t work. Is object.should_receive_nothing completely out of the question? -- 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/e4e2d213/attachment.html>
Lenny Marks
2012-Aug-22 17:38 UTC
[rspec-users] How do I specify that a class does not receive any message
On Aug 22, 2012, at 10:36 AM, David Chelimsky wrote:> On Wed, Aug 22, 2012 at 9:16 AM, J. B. Rainsberger <me at jbrains.ca> wrote: >> 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(). > > Perhaps it goes without saying, but I was not aware of that ;) > > As you noted earlier this thread (not quoted above) RSpec::Mocks::Mock > instances (returned by double(), mock(), or stub()) are strict by > default - e.g. they''ll complain about any unexpected messages. > Obviously that does not account for any real objects. > > I''m open to adding an API for this, but not > object.should_receive(:nothing) since that syntax is for declaring > expected messages. >+1 for me. I''ve found myself on occasion using should_not_receive(:some_message). OK, see a failing spec, make it pass, but what about when the collaborator method is renamed. All those should_not_receive expectations will still pass no matter what. It would be great to have object.should_receive(:nothing) instead. This would make life easier when collaborators are stubbed out with :as_null_object stubs. -lenny> Other ideas welcome. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
Lenny Marks
2012-Aug-22 18:08 UTC
[rspec-users] How do I specify that a class does not receive any message
On Aug 22, 2012, at 1:38 PM, Lenny Marks wrote:> > On Aug 22, 2012, at 10:36 AM, David Chelimsky wrote: > >> On Wed, Aug 22, 2012 at 9:16 AM, J. B. Rainsberger <me at jbrains.ca> wrote: >>> 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(). >> >> Perhaps it goes without saying, but I was not aware of that ;) >> >> As you noted earlier this thread (not quoted above) RSpec::Mocks::Mock >> instances (returned by double(), mock(), or stub()) are strict by >> default - e.g. they''ll complain about any unexpected messages. >> Obviously that does not account for any real objects. >> >> I''m open to adding an API for this, but not >> object.should_receive(:nothing) since that syntax is for declaring >> expected messages. >> > > +1 for me. I''ve found myself on occasion using should_not_receive(:some_message). OK, see a failing spec, make it pass, but what about when the collaborator method is renamed. All those should_not_receive expectations will still pass no matter what. It would be great to have object.should_receive(:nothing) instead. This would make life easier when collaborators are stubbed out with :as_null_object stubs.I mean some equivalent to object.should_receive(:nothing). Maybe object.should_receive_nothing ??> > -lenny > >> Other ideas welcome. >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users