Skip to content

Instantly share code, notes, and snippets.

@q231950
Created July 9, 2020 19:23
Show Gist options
  • Save q231950/4ad87b95569cc62bbc2084534111c0af to your computer and use it in GitHub Desktop.
Save q231950/4ad87b95569cc62bbc2084534111c0af to your computer and use it in GitHub Desktop.

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)
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment