Gherkin

Build Status

一个用于处理基于 Gherkin 的 .feature 文件的 Swift 包。

警告:此包仅处理 Gherkin 的一个有限子集。 我希望能够改进它。 如果您想提供帮助,请参阅 Gherkin 子集部分。

用法

您可以从 StringData 初始化一个 Feature。 如果解析器无法读取内容,这些初始化程序将抛出一个 Error

import Gherkin

do {
  let text = """
             Feature: Registration
             Users may want to register to save lists

             Scenario: Successful registration
             Given I am on the registration screen
             When I enter <email> into the email field
             And submit the form
             Then I see the registration page

             Examples:
             | email                  |
             | 1@notanemail.com       |
             | 1+gmail@notanemail.com |
             """

  let feature = try Feature(text)
  print(feature.name) // Registration
  let firstScenario = feature.scenarios[0]
  print(firstScenario.steps.count) // 4

  print(firstScenario.examples) // ["1@notanemail.com", "1+gmail@notanemail.com"]
}

Scenario 类型是一个枚举,它有两个 case: .simple(ScenarioSimple).outline(ScenarioOutline)。 解析器确保 “Scenario Outline:” 必须至少有一个示例。

安装

Swift 包管理器

要使用 Swift 包管理器安装,请将以下内容添加到您的 Package.swift 文件中的 dependencies: 部分

.package(url: "https://github.com/iainsmith/SwiftGherkin.git", .upToNextMinor(from: "0.2.0")),
Swift 4 包示例
let package = Package(
    name: "MyPackage",
    products: [
        .library(
            name: "MyPackage",
            targets: ["MyPackage"]),
    ],
    dependencies: [
        .package(url: "https://github.com/iainsmith/SwiftGherkin.git", .upToNextMinor(from: "0.2.0")),
    ],
    targets: [
        .target(
            name: "MyPackage",
            dependencies: ["Gherkin"])
    ]
)

Gherkin 子集

此包目前支持以下 Gherkin 关键字

明显的改进领域包括

如果您想添加任何这些功能,请

  1. 将测试用例添加到 GherkinTests.swift
  2. 更新 Parser.swift 和 Transform.swift 直到所有测试通过
  3. 创建 Pull Request

Gherkin 构建于 Consumer 之上。您可能需要阅读 Consumer 文档才能处理解析和转换。

如果您想向此库添加其他功能,请提出 issue 以讨论细节。

鸣谢

Gherkin 构建于 Nick Lockwood 的一个名为 Consumer 的解析器生成器之上。

支持的 swift 版本

SwiftGherkin 当前支持 swift 4.2 及更高版本。

添加新测试

如果您添加新测试,请运行 swift test --generate-linuxmain 以确保它们被添加到 XCTestManifests.swift 文件中。

版本控制说明

Feature 类型符合 Codable。 JSON 表示形式可能在不同版本之间不兼容。

其他 Cucumber/Gherkin Swift 库