【问题标题】:Cucumber: read a template with placeholdersCucumber:阅读带有占位符的模板
【发布时间】: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


    【解决方案1】:

    我更喜欢在黄瓜步骤中隐藏任何响应格式的概念。

    相反,我更愿意将步骤设置在更高级别,并在步骤定义中包含验证方法。

    例如

    When I attempt to create a user using the <type> template
    Then the response is successful and contains the user's details
    

    在我的步骤定义中,我将有一个 validate_response 方法,该方法获取最后一个响应并根据输入检查用户详细信息。

    【讨论】:

      猜你喜欢
      • 2014-10-14
      • 2018-07-18
      • 2015-05-10
      • 2016-02-04
      • 2015-05-20
      • 2012-09-10
      • 2012-02-17
      • 2014-12-25
      • 1970-01-01
      相关资源
      最近更新 更多