views:

205

answers:

1

As far as I know, should_receive is applied only to mock objects. What I want is to check, if a certain Class (not object) received a certain message, like:

User.should_receive(:all).once

How do I do that?

UPD. Commonly, writing test for models and controllers we can write User.should_receive(:smth).once. But in my case I'm testing an arbitrary class from the lib folder, and somehow I always receive the following message:

<User( [fields] ) (class)> expected :all with (no args) once, but received it 0 times>

Any ideas on why is that so? A test somehow sees the User class, but can't check if it receives a message. Of course I've ten times checked that the User is actually getting a message.

+1  A: 

Easy:

User.should_receive(:all).once

What I want is to check, if a certain Class (not object) received a certain message

A class is an object!

Jörg W Mittag
Thanks for answer, Jörg. I've updated the question with more details.
gmile