2011-05-07 66 views
1

問候,我有一個Cuke測試正在測試其他Web服務w/json。它看起來是這樣的:包含或忽略cuke聲明中的未知變量

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!" 
    } 
    """ 

的問題是,我不知道,因爲它增加DATEBASE ID的自動編號。有沒有一種方法可以讓斷言忽略該元素?

回答

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