How to use spec method of FunctionalTests_AroundEachSpec class

Best Quick code snippet using FunctionalTests_AroundEachSpec.spec

Run Quick automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

AroundEachTests.swift

Source: AroundEachTests.swift Github

copy
1import XCTest
2import Quick
3import Nimble
4
5private enum AroundEachType {
6    case around0Prefix
7    case around0Suffix
8    case around1Prefix
9    case around1Suffix
10    case before0
11    case before1
12    case before2
13    case after0
14    case after1
15    case after2
16    case innerBefore
17    case innerAfter
18    case innerAroundPrefix
19    case innerAroundSuffix
20}
21
22private var aroundEachOrder = [AroundEachType]()
23
24class FunctionalTests_AroundEachSpec: QuickSpec {
25    override func spec() {
26        describe("aroundEach ordering") {
27            beforeEach { aroundEachOrder.append(.before0) }
28            afterEach { aroundEachOrder.append(.after0) }
29            aroundEach { run in
30                aroundEachOrder.append(.around0Prefix)
31                run()
32                aroundEachOrder.append(.around0Suffix)
33            }
34            beforeEach { aroundEachOrder.append(.before1) }
35            afterEach { aroundEachOrder.append(.after1) }
36            aroundEach { run in
37                aroundEachOrder.append(.around1Prefix)
38                run()
39                aroundEachOrder.append(.around1Suffix)
40            }
41            beforeEach { aroundEachOrder.append(.before2) }
42            afterEach { aroundEachOrder.append(.after2) }
43
44            it("executes the prefix portion before each example, but not the suffix portion [1]") {
45                expect(aroundEachOrder).to(equal([
46                    .before0, .around0Prefix,
47                    .before1, .around1Prefix,
48                    .before2,
49                ]))
50            }
51
52            context("when there are nested aroundEach") {
53                beforeEach { aroundEachOrder.append(.innerBefore) }
54                afterEach { aroundEachOrder.append(.innerAfter) }
55                aroundEach { run in
56                    aroundEachOrder.append(.innerAroundPrefix)
57                    run()
58                    aroundEachOrder.append(.innerAroundSuffix)
59                }
60
61                it("executes the outer and inner aroundEach closures, but not before this closure [2]") {
62                    expect(aroundEachOrder).to(contain(.innerAroundPrefix, .innerBefore))
63                    expect(aroundEachOrder).notTo(contain(.innerAroundSuffix))
64                    expect(aroundEachOrder).notTo(contain(.innerAfter))
65                }
66            }
67        }
68#if canImport(Darwin) && !SWIFT_PACKAGE
69        describe("error handling when misusing ordering") {
70            it("should throw an exception when including aroundEach in it block") {
71                expect {
72                    aroundEach { _ in }
73                }.to(raiseException { (exception: NSException) in
74                    expect(exception.name).to(equal(NSExceptionName.internalInconsistencyException))
75                    expect(exception.reason).to(equal("'aroundEach' cannot be used inside 'it', 'aroundEach' may only be used inside 'context' or 'describe'. "))
76                })
77            }
78        }
79#endif
80    }
81}
82
83final class AroundEachTests: XCTestCase, XCTestCaseProvider {
84    static var allTests: [(String, (AroundEachTests) -> () throws -> Void)] {
85        return [
86            ("testAroundEachIsExecutedInTheCorrectOrder", testAroundEachIsExecutedInTheCorrectOrder),
87        ]
88    }
89
90    func testAroundEachIsExecutedInTheCorrectOrder() {
91        aroundEachOrder = []
92
93        qck_runSpec(FunctionalTests_AroundEachSpec.self)
94        let expectedOrder: [AroundEachType] = [
95            // First spec [1]
96            .before0, .around0Prefix,  // All beforeEaches and aroundEach prefixes happen in order...
97            .before1, .around1Prefix,
98            .before2,
99            .around1Suffix,            // ...then aroundEaches suffixes resolve in order...
100            .around0Suffix,
101            .after0, .after1, .after2, // ...then afterEaches all come last.
102
103            .before0, .around0Prefix,          // Outer setup happens first...
104            .before1, .around1Prefix,
105            .before2,
106            .innerBefore, .innerAroundPrefix,  // ...then inner setup...
107            .innerAroundSuffix, .innerAfter,   // ...then inner cleanup, happily inner after...
108            .around1Suffix,                    // ...then the outer cleanup, as before.
109            .around0Suffix,
110            .after0, .after1, .after2,
111        ]
112        XCTAssertEqual(aroundEachOrder, expectedOrder)
113
114        aroundEachOrder = []
115    }
116}
117
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Most used method in FunctionalTests_AroundEachSpec

Trigger spec code on LambdaTest Cloud Grid

Execute automation tests with spec on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)