当使用DHH的JBuilder测试来自RSpec控制器测试的JSON响应时,我的response.body总是"{}".它在开发/生产模式下工作得很好,并且当我使用to_json方法而不是jbuilder时,我的response.body中得到了适当的JSON.

Anyone have a clue as to why my response.body would always be "{}" when testing?

-----调试器

它"应该通过JSON返回购物车项目",focus do

get :index, :format => :json
end

(rdb:1) response.body

"{}"

推荐答案

For anyone that is having the same issue. I have figured it out.

You must call render_views within the controller tests you are doing. If you do that, you should then see a response.body with your JSON contained :)

Json相关问答推荐

JOLT拉平数组

最新版本的Deneb在数据溢出时不支持滚动

为什么JQ筛选器不将原始输入打印为$var|.';文档?

Python将Pandas转换为嵌套的JSON

创建Json嵌套文件 struct

419(未知状态)使用laravel处理PUT请求

Moshi:序列化 List 时出现问题

在 JOLT 中重新排列值

通过 xslt 将内部 json 转换为 xml 时遇到问题

使用 jq 获取特定键的所有父键

TSQL FOR JSON 嵌套值

如何为包含一些固定值并可能具有其他附加值的数组字符串创建数组 json 架构

使用 Jolt 使用键中的值创建带有硬编码键和值的 JSON 数组

C# 合并 2 个几乎相同的 JSON 对象

如何比较 JSON 文档并返回与 Jackson 或 Gson 的差异?

JSON extract\set 的 SQLite JSON1 示例

在 JSON 编码的 HTML5 数据属性中转义/编码单引号

在 Django 1.9 中,使用 JSONField(本机 postgres jsonb)的约定是什么?

将 CoffeeScript 项目转换为 JavaScript(不缩小)?

通过 JSON 发送 64 位值的公认方式是什么?