我试图用我用蓝图编写的文档检查我的api实现。我预计当从服务器返回的json与文档中指定的不同时,dredd将失败。为了检查这一点,我复制了dredd-example。首先,我使用原始的apib文件运行dredd,以确保所有都是绿色的。然后我修改了文档中的响应,并期望dredd向我显示一些红色...但它并没有......看起来工具只是检查响应头而不是响应体。这是控制台的输出:
pass: GET /machines duration: 18ms
request:
host: localhost
port: 3000
path: /machines
method: GET
headers:
User-Agent: Dredd/0.2.1 (Darwin 13.0.0; x64)
expected:
headers:
Content-Type: application/json
body:
[
{
"_id": "52341870ed55224b15ff07ef",
"type": "bulldozer",
"name": "willyxxxxxx" #HERE IS WHERE I CHANGED RESPONSE IN DOCUMENTATION
}
]
status: 200
actual:
headers:
x-powered-by: Express
content-type: application/json
content-length: 95
date: Thu, 20 Mar 2014 08:22:40 GMT
connection: keep-alive
body:
[
{
"_id": "532aa5507dcdfff362931799",
"type": "bulldozer",
"name": "willy"
}
]
status: 200
我可以使用dredd检查响应体吗?我怎么能这样做?
答案 0 :(得分:2)
在JSON主体中,Dredd仅检查不是值的键。当您更改预期的JSON正文文档中的键时,它肯定会失败。