首页 > 解决方案 > 将 2 个黄瓜 JSON 报告与 ruby​​ 进行比较

问题描述

问题是:我有 2 个 JSON 格式的黄瓜测试报告我需要从这些报告中删除多余的键值对并进行比较,但是我不明白如何从这 2 个 json 中删除不必要的数据,因为它们的结构之后JSON.parse(具有许多嵌套数组/哈希的数组或哈希)。如果有一些宝石或已知的解决方案可以执行此 JSON 结构,请提出建议,例如:

[
  {
    "uri": "features/home_screen.feature",
    "id": "as-a-user-i-want-to-explore-home-screen",
    "keyword": "Feature",
    "name": "As a user I want to explore home screen",
    "description": "",
    "line": 2,
    "tags": [
      {
        "name": "@home_screen",
        "line": 1
      }
    ],
    "elements": [
      {
        "keyword": "Background",
        "name": "",
        "description": "",
        "line": 3,
        "type": "background",
        "before": [
          {
            "match": {
              "location": "features/step_definitions/support/hooks.rb:1"
            },
            "result": {
              "status": "passed",
              "duration": 505329000
            }
          }
        ],
        "steps": [
          {
            "keyword": "Given ",
            "name": "I click OK button in popup",
            "line": 4,
            "match": {
              "location": "features/step_definitions/registration_steps.rb:91"
            },
            "result": {
              "status": "passed",
              "duration": 2329140000
            }
          },
          {
            "keyword": "And ",
            "name": "I click Allow button in popup",
            "line": 5,
            "match": {
              "location": "features/step_definitions/registration_steps.rb:96"
            },
            "result": {
              "status": "passed",
              "duration": 1861776000
            }
          }
        ]
      },

标签: jsonrubycucumber

解决方案


由于您要的是宝石,因此您可以尝试iteraptor我已经为此类任务创建了确切的内容。

它允许迭代、映射和减少深度嵌套的结构。例如,要过滤掉"name"所有级别上调用的所有键,您可以这样做:

input.iteraptor.reject(/name/)

更详细的描述可以在上面链接的 github 页面上找到。


推荐阅读