最佳答案
我的控制器中有以下代码:
format.json { render :json => {
:flashcard => @flashcard,
:lesson => @lesson,
:success => true
}
在 RSpec 控制器测试中,我想验证某个场景是否收到了成功的 json 响应,因此我使用了以下代码行:
controller.should_receive(:render).with(hash_including(:success => true))
尽管在运行测试时会得到以下错误:
Failure/Error: controller.should_receive(:render).with(hash_including(:success => false))
(#<AnnoController:0x00000002de0560>).render(hash_including(:success=>false))
expected: 1 time
received: 0 times
我是不是检查错了?