Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 您是否应该在RSpec中接收_Ruby On Rails_Class_Rspec_Message_Expectations - Fatal编程技术网

Ruby on rails 您是否应该在RSpec中接收

Ruby on rails 您是否应该在RSpec中接收,ruby-on-rails,class,rspec,message,expectations,Ruby On Rails,Class,Rspec,Message,Expectations,据我所知,should\u receive仅适用于模拟对象。我想检查的是,某个类(不是对象)是否收到了某个消息,如: User.should_receive(:all).once 我该怎么做 UPD。通常,为模型和控制器编写测试时,我们可以编写User.should_receive(:smth).once。但在我的例子中,我正在测试lib文件夹中的任意类,不知怎的,我总是收到以下消息: <User( [fields] ) (class)> expected :all with (n

据我所知,
should\u receive
仅适用于模拟对象。我想检查的是,某个类(不是对象)是否收到了某个消息,如:

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>
应为:所有参数(无参数)均为一次,但收到0次>
你知道为什么吗?测试以某种方式看到用户类,但无法检查它是否收到消息。当然,我已经十次检查用户是否真的收到消息。

简单:

User.should_receive(:all).once
我想检查的是,某个类(不是对象)是否收到了某个消息

类是一个对象

简单:

User.should_receive(:all).once
我想检查的是,某个类(不是对象)是否收到了某个消息


类是一个对象

谢谢你的回答,约格。我更新了问题的更多细节。谢谢你的回答,约格。我已经用更多的细节更新了这个问题。