【发布时间】:2014-10-27 03:40:53
【问题描述】:
我正在编写一个黄瓜框架来测试一组使用长 JSON 格式参数的 API 调用。我想将 JSON 隐藏在模板文件中,以使我的用户更容易阅读和 DRYer 的场景,因为模板可能被其他场景和功能文件使用。模板包含占位符,我想装配 cucumber/ruby 代码以填写示例表中定义的值。看来 ERB 是最接近替代的方法。但是,我还没有找到绑定示例表中定义的方法。
解决这个问题的唯一方法可能是通过预处理器运行特征文件和模板,预处理器将它们组合起来并制造最终的特征文件。如果可能的话,我正在寻找更优雅的单步解决方案。
示例功能文件代码:
Feature: Create users
Scenario Outline: Test create a merchant user
Given I am logged in
When I send a :post request to "createUser" using the "Merchant" template:
Then the JSON response should have "$..status" with the text "success"
Examples:
| OrgName | KeyName | KeyValue |
| CClient_RMBP_0_UNIQ_ | paramX | TRUE |
| CClient_RMBP_1_UNIQ_ | paramY | some text |
| CClient_RMBP_2_UNIQ_ | paramZ | 12345 |
示例 Merchant.json 文件:
{
"Organization": {
"parameters": [
{
"key": "orgName",
"value": {
"value": "<OrgName>"
}
},
{
"key": "<KeyName>",
"value": {
"value": "<KeyValue>"
}
}
]
},
"parentOrganizationId": "1",
"User": {
"firstName": "Mary",
"lastName": "Smith",
"id": "<OrgName>",
"language": "en",
"locale": "US",
"primaryEmail": "primary@mailaddr.com",
"cellPhone": "1-123-456-7890"
},
"active": "true"
}
【问题讨论】:
标签: ruby json templates cucumber placeholder