{"id":17690171,"url":"https://github.com/onmyway133/spek","last_synced_at":"2025-07-20T16:35:34.510Z","repository":{"id":63919498,"uuid":"232985753","full_name":"onmyway133/Spek","owner":"onmyway133","description":"🎏 Function builder BDD testing framework in Swift","archived":false,"fork":false,"pushed_at":"2020-03-28T20:58:51.000Z","size":2658,"stargazers_count":122,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T20:17:18.411Z","etag":null,"topics":["bdd","builder","describe","function","swift","test"],"latest_commit_sha":null,"homepage":"https://onmyway133.com/apps/","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/onmyway133.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"onmyway133","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2020-01-10T06:57:46.000Z","updated_at":"2025-02-11T05:52:28.000Z","dependencies_parsed_at":"2023-01-14T14:00:31.195Z","dependency_job_id":null,"html_url":"https://github.com/onmyway133/Spek","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onmyway133%2FSpek","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onmyway133%2FSpek/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onmyway133%2FSpek/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onmyway133%2FSpek/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/onmyway133","download_url":"https://codeload.github.com/onmyway133/Spek/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249105476,"owners_count":21213537,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bdd","builder","describe","function","swift","test"],"created_at":"2024-10-24T11:50:01.052Z","updated_at":"2025-04-15T16:21:41.552Z","avatar_url":"https://github.com/onmyway133.png","language":"Swift","funding_links":["https://github.com/sponsors/onmyway133"],"categories":[],"sub_categories":[],"readme":"# Spek\n\n❤️ Support my app ❤️ \n\n- [Push Hero - pure Swift native macOS application to test push notifications](https://www.producthunt.com/posts/push-hero-2)\n- [PastePal - Pasteboard, note and shortcut manager](https://www.producthunt.com/posts/pastepal)\n- [Frame recorder - Recorder gif and video with frame](https://www.producthunt.com/posts/frame-recorder)\n- [Other apps](https://onmyway133.github.io/projects/)\n\n❤️❤️😇😍🤘❤️❤️\n\n![](Screenshots/logo.png)\n\nSpek is a lightweight function builder style Behavior Driven Development framework, designed to be used with XCTest\n\n## Usage\n\n⚠️Before using any test frameworks, you need to ensure there is `XCTest` framework in your test target.\n\n```swift\nimport XCTest\n@testable import Spek\n\nfinal class SpekTests: XCTestCase {\n    func testExample() {\n        var left = 1\n        var right = 1\n\n        spec {\n            Describe(\"math\") {\n                BeforeEach {\n                    left = 2\n                }\n\n                Describe(\"basic\") {\n                    BeforeEach {\n                        right = 3\n                    }\n\n                    AfterEach {\n\n                    }\n\n                    It(\"adds correctly\") {\n                        XCTAssertEqual(left + right, 5)\n                    }\n\n                    It(\"multiplies correctly\") {\n                        XCTAssertEqual(left * right, 6)\n                    }\n                }\n            }\n        }\n    }\n}\n```\n\n## Features\n\n- Support common BDD parts: Describe, Context, BeforeAll, AfterAll, BeforeEach, AfterEach, It\n- To disable a part, prefix it with `X`, for example `XDescribe`, `XIt`, ...\n- All blocks are throwing function, so are encouraged to `do try catch`\n- `BeforeAll` and `AfterAll` are run before and after all enclosing `Describe` and `It`\n- `BeforeEach` and `AfterEach` are run before and after all enclosing `It`\n- `Context` behaves the same as `Describe`\n\n## How to\n\n### Disable a block\n\nWhen you have an imcomplete block, instead of commenting it out, you can prefix it with `X` so it won't be executed\n\n```swift\nDescribe(\"math\") {\n    It(\"will be run\") {\n\n    }\n\n    XIt(\"won't be run\") {\n\n    }\n}\n```\n\n### Declare local variables\n\nSpek uses Swift 5.1 function builder so you can only declare block and nested block. To declare local variables in a subspec, you need to use `Sub` and return `Describe` explicitly\n\n```swift\nDescribe(\"math\") {\n    Describe(\"advanced\") {\n\n    }\n\n    Sub {\n        let abc = 1\n        let def = 2\n        return Describe(\"extra\") {\n            It(\"should add\") {\n                XCTAssertEqual(abc + def, 2)\n            }\n        }\n    }\n}\n```\n\n### Generate XCTestCase\n\nBy default, `spec` method runs the test directly, to generate test cases, you need to override `makeDescribe`.\n\nSubclass `SpekTestCase` and override `makeDescribe` method, Spek will convert your `Describe` descriptions and generate `XCTestCase` methods. It generates test methods for nested `Describe` and `Sub` too.\n\n\n![](Screenshots/s1.png)\n\nFor example the below test will generate `test_math_should_work` and `test_math_advanced_should_calculate` methods\n\n```swift\nimport XCTest\nimport Spek\n\nclass GenerateTestCaseTests: SpekTestCase {\n    override class func describe() -\u003e Describe {\n        Describe(\"math\") {\n            It(\"should work\") {\n                XCTAssertTrue(1 + 1 == 2)\n            }\n\n            Describe(\"advanced\") {\n                It(\"should calculate\") {\n                    XCTAssertEqual(2 * 5, 10)\n                }\n            }\n        }\n    }\n}\n```\n\n## Install\n\nSpek is distributed using the Swift Package Manager. To install it into a project, add it as a dependency within your Package.swift manifest:\n\n```swift\nlet package = Package(\n    ...\n    dependencies: [\n        .package(url: \"https://github.com/onmyway133/Spek.git\", from: \"0.5.0\")\n    ],\n    ...\n)\n```\n\nThen import Spek in your XCTest\n\n`import Spek`\n\n## Author\n\nKhoa Pham, onmyway133@gmail.com\n\n## Credit\n\n- [Quick](https://github.com/Quick/Quick) for testInvocations reference\n\n## License\n\n**Spek** is available under the MIT license. See the [LICENSE](https://github.com/onmyway133/Spek/blob/master/LICENSE.md) file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonmyway133%2Fspek","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fonmyway133%2Fspek","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonmyway133%2Fspek/lists"}