Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(): update get bundle with SPM #190

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
PODS:
- SwiftLint (0.39.1)
- XCTest-Gherkin/Core (0.20.0)
- XCTest-Gherkin/Native (0.20.0):
- XCTest-Gherkin/Core (0.21.2)
- XCTest-Gherkin/Native (0.21.2):
- XCTest-Gherkin/Core

DEPENDENCIES:
- SwiftLint (~> 0.23)
- XCTest-Gherkin/Native (from `../`)

SPEC REPOS:
https://github.com/CocoaPods/Specs:
https://github.com/CocoaPods/Specs.git:
- SwiftLint

EXTERNAL SOURCES:
Expand All @@ -18,8 +18,8 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
SwiftLint: 55e96a4a4d537d4a3156859fc1c54bd24851a046
XCTest-Gherkin: 73452110106863d9c9256d68d7d19cc6734876cc
XCTest-Gherkin: 7c78531780d520bbec90b035077b0bf9fc178717

PODFILE CHECKSUM: 040d56cac22fe93f01093a8f0021b445faf03233

COCOAPODS: 1.10.1
COCOAPODS: 1.10.2
4 changes: 2 additions & 2 deletions Example/Pods/Local Podspecs/XCTest-Gherkin.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Example/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.3
// swift-tools-version:5.4

import PackageDescription

Expand Down Expand Up @@ -81,6 +81,9 @@ let package = Package(
],
resources: [
.process("Native/gherkin-languages.json")
],
swiftSettings: [
.define("SWIFT_PACKAGE")
])
]
)
10 changes: 7 additions & 3 deletions Pod/Core/XCTestCase+Gherkin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,16 @@ class GherkinState: NSObject, XCTestObservation {
self.steps.printStepsDefinitions()
}

func loadAllStepsIfNeeded() {
func loadAllStepsIfNeeded(_ mapStepDefiner: StepDefiner.Type? = nil) {
guard self.steps.count == 0 else { return }

// Create an instance of each step definer and call it's defineSteps method
allSubclassesOf(StepDefiner.self).forEach { subclass in
subclass.init(test: self.test!).defineSteps()
if mapStepDefiner == nil {
allSubclassesOf(StepDefiner.self).forEach { subclass in
subclass.init(test: self.test!).defineSteps()
}
} else {
mapStepDefiner!.init(test: self.test!).defineSteps()
}

UnusedStepsTracker.shared().setSteps(self.steps.map { String(reflecting: $0) })
Expand Down
6 changes: 5 additions & 1 deletion Pod/Native/Language.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ class Language {
private init() {}

private(set) var vocabulary: [String: [String: [String]]]? = {
let bundle = Bundle(for: NativeFeature.self)
var bundle = Bundle(for: NativeFeature.self)
#if SWIFT_PACKAGE
bundle = Bundle.module
#endif

guard let path = bundle.path(forResource: "gherkin-languages", ofType: ".json"),
let data = FileManager.default.contents(atPath: path),
let json = (try? JSONSerialization.jsonObject(with: data)) as? [String: [String: [String]]]
Expand Down
24 changes: 17 additions & 7 deletions Pod/Native/NativeRunner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,31 @@ import XCTest

//Gives us the ability to run features or scenarios directly by specifying file and name
open class NativeRunner {

public class func runScenario(featureFile: String, scenario: String?, testCase: XCTestCase) {
testCase.state.loadAllStepsIfNeeded()

let path = Bundle(for: type(of: testCase)).resourceURL?.appendingPathComponent(featureFile)
public class func runScenario(featureFile: String,
scenario: String?,
testCase: XCTestCase,
mapStepDefiner: StepDefiner.Type? = nil) {
testCase.state.loadAllStepsIfNeeded(mapStepDefiner)

var bundle = Bundle(for: type(of: testCase))
#if SWIFT_PACKAGE
bundle = Bundle.module
#endif
let path = bundle.resourceURL?.appendingPathComponent(featureFile)
let featureFilePath = requireNotNil(path, "Path could not be built for feature file: \(featureFile)")

let features = loadFeatures(path: featureFilePath)

for feature in features {
let scenarios = feature.scenarios.filter {
scenario == nil || $0.name.hasPrefix(scenario!)
let scenarios: [NativeScenario]
if let scenario = scenario {
scenarios = feature.scenarios.filter { $0.name == scenario }
} else {
scenarios = feature.scenarios
}

precondition(!scenarios.isEmpty, "No scenario found with name: \(scenario ?? "<no scenario provided>")")
precondition(!scenarios.isEmpty, "No scenario found with name: \(scenario)")

for scenario in scenarios {
testCase.perform(scenario: scenario, from: feature)
Expand Down