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?
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.
json_response.gsub!(/id: \d*/, 'id: 999')
Perhaps it would better to rewrite the expectation as something like this:
And the JSON should contain these attributes:
| id | <integer> |
| name | Pop! Pop! |
| body | party over here yo! |
精彩评论