This step allows you to add, well, steps to be taken in your test without the need of wrapping them in a subclass of Step
.
You can write things like this. Notice that the GeneralStep
can contain anything:
expect(in: &context) {
Given {
GeneralStep("I log in") {
self.login(name: "John Doe", login: "123456789", password: "***", library: "Bücherhallen Hamburg")
}
ISelect(title: "Computerspiele")
}
When { IRenew() }
Then { RenewalSucceds() }
}
class GeneralStep: Step<Context> {
let content: (() -> ())?
let contentWithContext: ((_ context: inout Context) -> ())?
let t: String
convenience init(_ title: String, contentWithContext: ((_ context: inout Context)->())? = nil) {
self.init(title, contentWithContext: contentWithContext, content: nil)
}
convenience init(_ title: String, content: (()->())? = nil) {
self.init(title, contentWithContext: nil, content: content)
}
init(_ title: String, contentWithContext: ((_ context: inout Context)->())?, content: (()->())?) {
self.content = content
self.contentWithContext = contentWithContext
self.t = title
}
override var title: String {
t
}
override func execute(in context: inout Context) {
content?()
contentWithContext?(&context)
}
}