Swiftpack.co - BinaryBirds/spec as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by BinaryBirds.
BinaryBirds/spec 1.2.2
Unit testing Vapor 4 applications through declarative specifications.
⭐️ 30
🕓 38 weeks ago
.package(url: "https://github.com/BinaryBirds/spec.git", from: "1.2.2")


Unit testing Vapor 4 applications through declarative specifications.


Add the repository as a dependency:

.package(url: "https://github.com/binarybirds/spec.git", from: "1.2.0"),

Add Spec to the target dependencies:

.product(name: "Spec", package: "spec"),

Update the packages and you are ready.

Usage example


@testable import App
import Spec

final class BlogApiTests: XCTestCase {
    func testLogin(_ app: Application) throws {

        struct UserLoginRequest: Content {
            let email: String
            let password: String
        struct UserTokenResponse: Content {
            let id: String
            let value: String

        let userBody = UserLoginRequest(email: "foo@bar.com", password: "foo")
        var token: String?

        try app
            .describe("Login request should return ok")     // describe spec
            .post("/api/user/login")                        // post to endpoint
            .header("accept", "application/json")           // add header
            .body(userBody)                                 // add content body
            .expect(.ok)                                    // status code
            .expect(.json)                                  // media type
            .expect("content-length", ["81"])               // expect header
            .expect(UserTokenResponse.self) { content in    // expect content
                token = content.value                       // retrieve content
            .test(.inMemory)                                // test in memory

        _ = try XCTUnwrap(token)



Stars: 30
Last commit: 2 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.


Release Notes

Optional cookies
38 weeks ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics