【发布时间】:2013-08-15 16:49:48
【问题描述】:
我正在尝试通过 rspec 测试确认在控制器方法中调用了一个函数。为此,我正在关注confirming an instance of a class receives a message 的 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为什么不确认呢?
【问题讨论】:
-
在发出 post 请求之前先拨打 should_receive 电话。
-
这实际上阻止了规范通过。我现在根据我检查的方法得到不同的错误,但控制器方法永远不会起作用。请参阅此粘贴中错误的详细说明:pastie.org/private/yvvanhw95fnrercqth9ugg
标签: ruby-on-rails rspec