开发者

Include or ignore a unknown variable in a cuke assert

开发者 https://www.devze.com 2023-03-03 09:09 出处:网络
Greetings, I have a Cuke test that is testing a rest web service w/ json. it looks something like this:

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! |
0

精彩评论

暂无评论...
验证码 换一张
取 消