将 2 个黄瓜 JSON 报告与 ruby 进行比较

Compare 2 cucumber JSON reports with ruby

问题是:我有2份JSON格式的黄瓜测试报告 我需要从这些报告中删除多余的键值对并进行比较,但我无法理解如何从这 2 个 json 中删除不必要的数据,因为它们在 JSON.parse 之后的结构(具有许多嵌套 [ 的数组或散列) =15=]).如果有一些宝石或已知的解决方案可以做到这一点,请提出建议 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
            }
          }
        ]
      },

既然你要的是 gem,你可以试试 iteraptor 我专门为这类任务创建的。

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

input.iteraptor.reject(/name/)

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