我正在尝试使用 rspec 测试确认在控制器方法中调用了一个函数。为此,我按照 relishapp 文档确认类的实例收到消息。我的实现如下:但是,我不断收到以下错误:
it "does the job" do
expect {
post :create, {:obj => valid_attributes}
}.to change(Object, :count).by(1)
Object.any_instance.should_receive(:delay)
flash[:notice].should eq(I18n.t(:success, obj: 'object', past_participle: 'created'))
response.should redirect_to(new_object_path)
end
但是,我不断收到以下错误:
Failure/Error: Unable to find matching line from backtrace
Exactly one instance should have received the following message(s) but didn't: delay
在这种情况下,我试图确认该delay
方法已被调用。可以清楚的看到在controller方法中调用了方法,rspec为什么不确认呢?