相关疑难解决方法(0)

如何使用RSpec检查JSON响应?

我的控制器中有以下代码:

format.json { render :json => { 
        :flashcard  => @flashcard,
        :lesson     => @lesson,
        :success    => true
} 
Run Code Online (Sandbox Code Playgroud)

在我的RSpec控制器测试中,我想验证某个场景确实收到了成功的json响应,所以我有以下行:

controller.should_receive(:render).with(hash_including(:success => true))
Run Code Online (Sandbox Code Playgroud)

虽然当我运行我的测试时,我收到以下错误:

Failure/Error: controller.should_receive(:render).with(hash_including(:success => false))
 (#<AnnoController:0x00000002de0560>).render(hash_including(:success=>false))
     expected: 1 time
     received: 0 times
Run Code Online (Sandbox Code Playgroud)

我是否错误地检查了回复?

json rspec ruby-on-rails

142
推荐指数
9
解决办法
14万
查看次数

标签 统计

json ×1

rspec ×1

ruby-on-rails ×1