Object.any_instance should_receive vs expect () to get

The following code snippet works as expected:

Object.any_instance.should_receive(:subscribe) 

But when using the new rspec wait, it does not work:

 expect(Object.any_instance).to receive(:subscribe) 

Mistake:

 expected: 1 time with any arguments received: 0 times with any arguments 

How can I do this work pending () to receive?

+67
rspec rspec-rails rspec2
Jul 10 '13 at 9:11
source share
1 answer

There is currently a not-so-well-documented method called expect_any_instance_of that handles the special case of any_instance . You should use:

 expect_any_instance_of(Object).to receive(:subscribe) 

Google expect_any_instance_of for more information.

+141
Jul 10 '13 at 18:14
source share



All Articles