1
据我所知,should_receive
只适用于模拟对象。我想要检查,如果某个类(不是对象)收到某个消息,如:should_receive in RSpec
User.should_receive(:all).once
我该怎么做?
UPD。一般来说,为模型和控制器编写测试我们可以写入User.should_receive(:smth).once。但在我的情况下,我从lib文件夹测试任意类,不知何故我总是收到以下消息:
<User([fields]) (class)> expected :all with (no args) once, but received it 0 times>
为什么是这样的任何想法?测试不知何故会看到User类,但无法检查它是否收到消息。当然,我有十次检查用户是实际上收到一条消息。
谢谢你的回答,Jörg。我已经用更多的细节更新了这个问题。 – gmile 2010-04-22 09:22:15