问候,我有一个Cuke测试正在测试一个带有json的休息Web服务。它看起来像这样:
When "joe" posts the following to "comments" as "application/json":
"""
{
"name": "Pop! Pop!",
"body": "party over here yo!"
}
"""
Then the status code returned should be 201
And the Location header returned should be .*\/comments\/\d+
And the json returned should be
"""
{
"id": 40563
"name": "Pop! Pop!",
"body": "party over here yo!"
}
"""
问题是我不知道的Id,因为它是一个自动递增的数据库Id。有没有办法让断言断言忽略那个元素?
答案 0 :(得分:1)
这是一个讨厌的黑客,但你可以修改JSON字符串中的ID,使其每次都相同。
json_response.gsub!(/id: \d*/, 'id: 999')
或许最好将期望重写为:
And the JSON should contain these attributes:
| id | <integer> |
| name | Pop! Pop! |
| body | party over here yo! |