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

Generalised Steps and Assertions #3

Merged
merged 5 commits into from
May 1, 2021
Merged

Conversation

q231950
Copy link
Owner

@q231950 q231950 commented May 1, 2021

These breaking changes allow for a more flexible use by having general Steps and Assertions. Subclassing of Steps and Assertions is no longer necessary and the obligatory Context has been removed.

Example with multiple defined Steps

Screenshot 2021-05-01 at 06 40 37

func test_uiTest_example() {

        struct Universe {
            var numberOfStars = 0
        }

        struct Context {
            var count = 0
        }

        var universeA = Universe()
        var universeB = Universe()
        var context = Context()

        expect {
            Given {
                Step("I have universe A with 4 stars") {
                    universeA.numberOfStars = 4
                }
                Step("I have another universe B with 6 stars") {
                    universeB.numberOfStars = 6
                }
            }
            When {
                Step("I sum up the stars") {
                    context.count = universeA.numberOfStars + universeB.numberOfStars
                }
                Step("I bring them into a second dimension") {
                    context.count *= context.count
                }
            }
            Then("I can see 100 stars ✨") {
                XCTAssertEqual(context.count, 100)
            }
        }
    }

Example with general Steps and a general Assertion

Screenshot 2021-05-01 at 06 41 20

func test_unitTest_example() {

        let context = UniverseContext()

        expect {
            Given("I have a universe without any stars") {
                context.numberOfStars = 5
            }
            When("I add a couple of stars") {
                context.numberOfStars = 1_000_000_000_023
            }
            Then("I can see the stars I have added ✨") {
                XCTAssertEqual(context.numberOfStars, 1_000_000_000_023)
            }
        }
    }

@q231950 q231950 mentioned this pull request May 1, 2021
@q231950 q231950 force-pushed the general-steps-and-assertions branch from b9f8ca0 to 7160471 Compare May 1, 2021 07:18
@q231950 q231950 marked this pull request as ready for review May 1, 2021 07:21
@q231950 q231950 added the enhancement New feature or request label May 1, 2021
@q231950 q231950 self-assigned this May 1, 2021
@q231950 q231950 changed the title General Steps and Assertions Generalised Steps and Assertions May 1, 2021
@q231950 q231950 merged commit e4ce83d into main May 1, 2021
@q231950 q231950 deleted the general-steps-and-assertions branch May 1, 2021 07:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant