【问题标题】:Compare 2 cucumber JSON reports with ruby将 2 个黄瓜 JSON 报告与 ruby​​ 进行比较
【发布时间】:2018-11-21 10:43:11
【问题描述】:

问题是:我有 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
            }
          }
        ]
      },

【问题讨论】:

  • 您是否在寻找比较 json 或 hashes 的 gem?
  • 您可以尝试iteraptor 我为此类任务创建的 gem。它允许迭代、映射和减少深度嵌套的结构。
  • @AlekseiMatiushkin 很有趣,现在试试,我会及时通知你结果
  • @AlekseiMatiushkin 看起来这正是我所需要的,非常感谢
  • @Mikhah 很酷,欢迎。

标签: json ruby cucumber


【解决方案1】:

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

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

input.iteraptor.reject(/name/)

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-17
    • 1970-01-01
    • 1970-01-01
    • 2021-11-04
    • 1970-01-01
    • 1970-01-01
    • 2019-12-24
    • 2022-01-27
    相关资源
    最近更新 更多