在 cuke 断言中包含或忽略未知变量
您好,我有一个 Cuke 测试,正在测试带有 json 的 REST 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。有没有办法让断言忽略该元素?
Greetings, I have a Cuke test that is testing a rest web service w/ json. it looks something like this:
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!"
}
"""
The problem is the Id which I will not know because it's a auto incremented datebase Id. Is there a way I can tel the assert to ignore that element?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这有点令人讨厌,但您可以修改 JSON 字符串中的 ID,使其每次都相同。
也许最好将期望重写为如下所示:
It's a bit of a nasty hack, but you could modify the ID in the JSON string to make it the same every time.
Perhaps it would better to rewrite the expectation as something like this: