SyncDSLUser
public protocol SyncDSLUser
A protocol for defining the synchronous DSL usable from Quick synchronous specs.
-
beforeSuite(_:Extension method) Defines a closure to be run prior to any examples in the test suite. You may define an unlimited number of these closures, but there is no guarantee as to the order in which they’re run.
If the test suite crashes before the first example is run, this closure will not be executed.
Declaration
Swift
public static func beforeSuite(_ closure: @escaping BeforeSuiteClosure)Parameters
closureThe closure to be run prior to any examples in the test suite.
-
afterSuite(_:Extension method) Defines a closure to be run after all of the examples in the test suite. You may define an unlimited number of these closures, but there is no guarantee as to the order in which they’re run.
If the test suite crashes before all examples are run, this closure will not be executed.
Declaration
Swift
public static func afterSuite(_ closure: @escaping AfterSuiteClosure)Parameters
closureThe closure to be run after all of the examples in the test suite.
-
sharedExamples(_:Extension methodclosure: ) Defines a group of shared examples. These examples can be re-used in several locations by using the
itBehavesLikefunction.Remark
sharedExamplesis untyped. Please useBehaviorinstead, as it offers type-safety.Declaration
Swift
public static func sharedExamples(_ name: String, closure: @escaping () -> Void)Parameters
nameThe name of the shared example group. This must be unique across all shared example groups defined in a test suite.
closureA closure containing the examples. This behaves just like an example group defined using
describeorcontext–the closure may contain any number ofbeforeEachandafterEachclosures, as well as any number of examples (defined usingit). -
sharedExamples(_:Extension methodclosure: ) Defines a group of shared examples. These examples can be re-used in several locations by using the
itBehavesLikefunction.Remark
sharedExamplesand the context passed in to it are untyped. Please useBehaviorinstead, as it offers type-safety.The closure takes a
SharedExampleContextas an argument. This context is a function that can be executed to retrieve parameters passed in via anitBehavesLikefunction.Declaration
Swift
public static func sharedExamples(_ name: String, closure: @escaping SharedExampleClosure)Parameters
nameThe name of the shared example group. This must be unique across all shared example groups defined in a test suite.
closureA closure containing the examples. This behaves just like an example group defined using
describeorcontext–the closure may contain any number ofbeforeEachandafterEachclosures, as well as any number of examples (defined usingit).
-
describe(_:Extension methodclosure: ) Defines an example group. Example groups are logical groupings of examples. Example groups can share setup and teardown code.
Declaration
Swift
public static func describe(_ description: String, closure: () -> Void)Parameters
descriptionAn arbitrary string describing the example group.
closureA closure that can contain other examples.
-
context(_:Extension methodclosure: ) Defines an example group. Equivalent to
describe.Declaration
Swift
public static func context(_ description: String, closure: () -> Void)
-
beforeEach(_:Extension method) Defines a closure to be run prior to each example in the current example group. This closure is not run for pending or otherwise disabled examples. An example group may contain an unlimited number of beforeEach. They’ll be run in the order they’re defined, but you shouldn’t rely on that behavior.
Declaration
Swift
public static func beforeEach(_ closure: @escaping BeforeExampleClosure)Parameters
closureThe closure to be run prior to each example.
-
beforeEach(_:Extension method) Identical to Quick.DSL.beforeEach, except the closure is provided with metadata on the example that the closure is being run prior to.
Declaration
Swift
public static func beforeEach(_ closure: @escaping BeforeExampleWithMetadataClosure)
-
afterEach(_:Extension method) Defines a closure to be run after each example in the current example group. This closure is not run for pending or otherwise disabled examples. An example group may contain an unlimited number of afterEach. They’ll be run in the order they’re defined, but you shouldn’t rely on that behavior.
Declaration
Swift
public static func afterEach(_ closure: @escaping AfterExampleClosure)Parameters
closureThe closure to be run after each example.
-
afterEach(_:Extension method) Identical to Quick.DSL.afterEach, except the closure is provided with metadata on the example that the closure is being run after.
Declaration
Swift
public static func afterEach(_ closure: @escaping AfterExampleWithMetadataClosure)
-
aroundEach(_:Extension method) Defines a closure to that wraps each example in the current example group. This closure is not run for pending or otherwise disabled examples.
The closure you pass to aroundEach receives a callback as its argument, which it MUST call exactly one for the example to run properly:
aroundEach { runExample in doSomeSetup() runExample() doSomeCleanup() }
This callback is particularly useful for test decartions that can’t split into a separate beforeEach and afterEach. For example, running each example in its own autorelease pool (provided by Task) requires aroundEach:
aroundEach { runExample in autoreleasepool { runExample() } checkObjectsNoLongerRetained() }
You can also use aroundEach to guarantee proper nesting of setup and cleanup operations in situations where their relative order matters.
An example group may contain an unlimited number of aroundEach callbacks. They will nest inside each other, with the first declared in the group nested at the outermost level.
Declaration
Swift
public static func aroundEach(_ closure: @escaping AroundExampleClosure)Parameters
closureThe closure that wraps around each example.
-
aroundEach(_:Extension method) Identical to Quick.DSL.aroundEach, except the closure receives metadata about the example that the closure wraps.
Declaration
Swift
public static func aroundEach(_ closure: @escaping AroundExampleWithMetadataClosure)
-
justBeforeEach(_:Extension method) Defines a closure to be run prior to each example but after any beforeEach blocks. This closure is not run for pending or otherwise disabled examples. An example group may contain an unlimited number of justBeforeEach. They’ll be run in the order they’re defined, but you shouldn’t rely on that behavior.
Declaration
Swift
public static func justBeforeEach(_ closure: @escaping BeforeExampleClosure)Parameters
closureThe closure to be run prior to each example and after any beforeEach blocks
-
it(_:Extension methodfile: line: closure: ) Defines an example. Examples use assertions to demonstrate how code should behave. These are like “tests” in XCTest.
Declaration
Swift
public static func it(_ description: String, file: FileString = #file, line: UInt = #line, closure: @escaping ExampleClosure)Parameters
descriptionAn arbitrary string describing what the example is meant to specify.
closureA closure that can contain assertions.
fileThe absolute path to the file containing the example. A sensible default is provided.
lineThe line containing the example. A sensible default is provided.
-
itBehavesLike(_:Extension methodfile: line: ) Inserts the examples defined using a
sharedExamplesfunction into the current example group. The shared examples are executed at this location, as if they were written out manually.Declaration
Swift
public static func itBehavesLike(_ name: String, file: FileString = #file, line: UInt = #line)Parameters
nameThe name of the shared examples group to be executed. This must be identical to the name of a shared examples group defined using
sharedExamples. If there are no shared examples that match the name given, an exception is thrown and the test suite will crash.fileThe absolute path to the file containing the current example group. A sensible default is provided.
lineThe line containing the current example group. A sensible default is provided.
-
itBehavesLike(_:Extension methodfile: line: sharedExampleContext: ) Inserts the examples defined using a
sharedExamplesfunction into the current example group. The shared examples are executed at this location, as if they were written out manually. This function also passes those shared examples a context that can be evaluated to give the shared examples extra information on the subject of the example.Declaration
Swift
public static func itBehavesLike(_ name: String, file: FileString = #file, line: UInt = #line, sharedExampleContext: @escaping SharedExampleContext)Parameters
nameThe name of the shared examples group to be executed. This must be identical to the name of a shared examples group defined using
sharedExamples. If there are no shared examples that match the name given, an exception is thrown and the test suite will crash.sharedExampleContextA closure that, when evaluated, returns key-value pairs that provide the shared examples with extra information on the subject of the example.
fileThe absolute path to the file containing the current example group. A sensible default is provided.
lineThe line containing the current example group. A sensible default is provided.
-
itBehavesLike(_:Extension methodfile: line: context: ) Inserts the examples defined using a
Behaviorinto the current example group. The shared examples are executed at this location, as if they were written out manually. This function also passes a strongly-typed context that can be evaluated to give the shared examples extra information on the subject of the example.Declaration
Swift
public static func itBehavesLike<C>(_ behavior: Behavior<C>.Type, file: FileString = #file, line: UInt = #line, context: @escaping () -> C)Parameters
behaviorThe type of
Behaviorclass defining the example group to be executed.contextA closure that, when evaluated, returns an instance of
Behavior‘s context type to provide its example group with extra information on the subject of the example.fileThe absolute path to the file containing the current example group. A sensible default is provided.
lineThe line containing the current example group. A sensible default is provided.
-
pending(_:Extension methodfile: line: closure: ) Defines an example or example group that should not be executed. Use
pendingto temporarily disable examples or groups that should not be run yet.Declaration
Swift
public static func pending(_ description: String, file: FileString = #file, line: UInt = #line, closure: @escaping () throws -> Void)Parameters
descriptionAn arbitrary string describing the example or example group.
closureA closure that will not be evaluated.
-
xdescribe(_:Extension methodclosure: ) Use this to quickly mark a
describeclosure as pending. This disables all examples within the closure.Declaration
Swift
public static func xdescribe(_ description: String, closure: () -> Void) -
xcontext(_:Extension methodclosure: ) Use this to quickly mark a
contextclosure as pending. This disables all examples within the closure.Declaration
Swift
public static func xcontext(_ description: String, closure: () -> Void) -
xit(_:Extension methodfile: line: closure: ) Use this to quickly mark an
itclosure as pending. This disables the example and ensures the code within the closure is never run.Declaration
Swift
public static func xit(_ description: String, file: FileString = #file, line: UInt = #line, closure: @escaping ExampleClosure) -
xitBehavesLike(_:Extension methodfile: line: context: ) Use this to quickly mark an
itBehavesLikeclosure as pending. This disables the example group defined by this behavior and ensures the code within is never run.Declaration
Swift
public static func xitBehavesLike<C>(_ behavior: Behavior<C>.Type, file: FileString = #file, line: UInt = #line, context: @escaping () -> C) -
xitBehavesLike(_:Extension methodfile: line: ) Use this to quickly mark an
itBehavesLikeclosure as pending. This disables the example group defined by this behavior and ensures the code within is never run.Declaration
Swift
public static func xitBehavesLike(_ name: String, file: FileString = #file, line: UInt = #line) -
xitBehavesLike(_:Extension methodfile: line: sharedExampleContext: ) Use this to quickly mark an
itBehavesLikeclosure as pending. This disables the example group defined by this behavior and ensures the code within is never run.Declaration
Swift
public static func xitBehavesLike(_ name: String, file: FileString = #file, line: UInt = #line, sharedExampleContext: @escaping SharedExampleContext)
-
fdescribe(_:Extension methodclosure: ) Use this to quickly focus a
describeclosure, focusing the examples in the closure. If any examples in the test suite are focused, only those examples are executed. This trumps any explicitly focused or unfocused examples within the closure–they are all treated as focused.Declaration
Swift
public static func fdescribe(_ description: String, closure: () -> Void) -
fcontext(_:Extension methodclosure: ) Use this to quickly focus a
contextclosure. Equivalent tofdescribe.Declaration
Swift
public static func fcontext(_ description: String, closure: () -> Void) -
fit(_:Extension methodfile: line: closure: ) Use this to quickly focus an
itclosure, focusing the example. If any examples in the test suite are focused, only those examples are executed.Declaration
Swift
public static func fit(_ description: String, file: FileString = #file, line: UInt = #line, closure: @escaping ExampleClosure) -
fitBehavesLike(_:Extension methodfile: line: ) Use this to quickly focus an
itBehavesLikeclosure.Declaration
Swift
public static func fitBehavesLike(_ name: String, file: FileString = #file, line: UInt = #line) -
fitBehavesLike(_:Extension methodfile: line: sharedExampleContext: ) Use this to quickly focus an
itBehavesLikeclosure.Declaration
Swift
public static func fitBehavesLike(_ name: String, file: FileString = #file, line: UInt = #line, sharedExampleContext: @escaping SharedExampleContext) -
fitBehavesLike(_:Extension methodfile: line: context: ) Use this to quickly focus on
itBehavesLikeclosure.Declaration
Swift
public static func fitBehavesLike<C>(_ behavior: Behavior<C>.Type, file: FileString = #file, line: UInt = #line, context: @escaping () -> C)
View on GitHub