一个用于处理基于 Gherkin 的 .feature 文件的 Swift 包。
警告:此包仅处理 Gherkin 的一个有限子集。 我希望能够改进它。 如果您想提供帮助,请参阅 Gherkin 子集部分。
您可以从 String
或 Data
初始化一个 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 包管理器安装,请将以下内容添加到您的 Package.swift 文件中的 dependencies: 部分
.package(url: "https://github.com/iainsmith/SwiftGherkin.git", .upToNextMinor(from: "0.2.0")),
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 构建于 Consumer 之上。您可能需要阅读 Consumer 文档才能处理解析和转换。
如果您想向此库添加其他功能,请提出 issue 以讨论细节。
Gherkin 构建于 Nick Lockwood 的一个名为 Consumer 的解析器生成器之上。
SwiftGherkin 当前支持 swift 4.2 及更高版本。
如果您添加新测试,请运行 swift test --generate-linuxmain
以确保它们被添加到 XCTestManifests.swift
文件中。
Feature
类型符合 Codable。 JSON 表示形式可能在不同版本之间不兼容。