Swiftpack.co - Package - BinaryBirds/spec

Spec

Unit testing Vapor 4 applications through declarative specifications.

Install

Add the repository as a dependency:

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

Add Spec to the target dependencies:

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

Update the packages and you are ready.

Usage example

Api

@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)

    }
}

License

WTFPL - Do what the fuck you want to.

Github

link
Stars: 22

Dependencies

Releases

Project updates - 2020-10-02 10:42:32

  • Swift 5.3 support
  • Dependency updates
  • Removed unnecessary test files
  • Makefile

- 2020-05-08 15:26:33

  • first release