{"id":14991374,"url":"https://github.com/odd-poet/kotlin-expect","last_synced_at":"2025-10-29T21:12:28.206Z","repository":{"id":57744832,"uuid":"96278254","full_name":"odd-poet/kotlin-expect","owner":"odd-poet","description":"assertion library for kotlin test. ","archived":false,"fork":false,"pushed_at":"2024-12-13T18:11:57.000Z","size":292,"stargazers_count":4,"open_issues_count":0,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T23:15:16.463Z","etag":null,"topics":["expect","kotlin","kotlin-library","rspec","test-framework"],"latest_commit_sha":null,"homepage":null,"language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/odd-poet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-05T04:58:47.000Z","updated_at":"2025-01-14T04:21:14.000Z","dependencies_parsed_at":"2022-08-30T11:30:19.843Z","dependency_job_id":null,"html_url":"https://github.com/odd-poet/kotlin-expect","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/odd-poet%2Fkotlin-expect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/odd-poet%2Fkotlin-expect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/odd-poet%2Fkotlin-expect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/odd-poet%2Fkotlin-expect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/odd-poet","download_url":"https://codeload.github.com/odd-poet/kotlin-expect/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248514221,"owners_count":21116899,"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":["expect","kotlin","kotlin-library","rspec","test-framework"],"created_at":"2024-09-24T14:27:35.264Z","updated_at":"2025-10-29T21:12:28.124Z","avatar_url":"https://github.com/odd-poet.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# kotlin-expect\n\n[![Build Status](https://travis-ci.org/odd-poet/kotlin-expect.svg?branch=master)](https://travis-ci.org/odd-poet/kotlin-expect)[![codecov](https://codecov.io/gh/odd-poet/kotlin-expect/branch/master/graph/badge.svg)](https://codecov.io/gh/odd-poet/kotlin-expect)\n\n`kotlin-expect` is a assertion library for kotlin test. it's inspried by [Rspec Expectation].\n\n## Setup\n\n```gradle\ndependencies {\n    testCompile(\"net.oddpoet:kotlin-expect:1.3.2\")\n}\n```\n\n## Basic Usage\n\n### `expect(s).to`\n\nYou can write an assertion for a subject in the form `expect(subject).to`.\n\n```kotlin\nval list = listOf(1, 2, 3)\nexpect(list).to.haveSizeOf(3)\nexpect(list).to.satisfy { size == 3 }\nexpect(list).to.not.contain(5)\nexpect(list).to.containAll { it \u003c 10 }\nexpect(list).to.not.beInstanceOf(Set::class)\n```\n\n### `should`\n\nAlternatively, you can write assertions in the form `subject.should` more simply.\n\n```kotlin\n\"hello\".should.startWith(\"h\")\n\"hello\".should.not.endWith(\"x\", ignoreCase = true)\n\"believe\".should.match(\"lie\")\n\"hello\".length.should.be(5)\n```\n\n### `expect(s) { ... }`\n\nYou can also create multiple assertions for a subject in the form `expect(s) {...}`\n\n```kotlin\nexpect(aList) {\n    it.should.haveSizeOf(10)\n    it.should.not.contain(\"hello\")\n    it.should.containAny { it.lenngth \u003c 2 }\n}\n```\n\n### `expect { }.throws()`\n\nAn assertion for an exception can be written in the form `expect { ... }.throws()`.\n\n```kotlin\nexpect {\n    throw IOExpection()\n}.throws()\n\nexpect {\n    throw NoSuchFileException(\"file.txt\")\n}.throws(IOExcpetion::class) {\n    it.message.should.be(\"file.txt\")\n}\n\n```\n\n## Write own your assertion\n\n`Kotlin-expect` has built-in assertions for java base types(`String`, `Collection`, `Map`, `Number` and so on).\nYou can define new assertions for your class.\nAn assertion for a class is defined as an extension of the `Expect` class.\n\n### example\n\n```kotlin\n// for your classes\nabstract class Person(\n    val name: String,\n    val birthdate: LocalDate\n)\n\nclass Employee(\n    name: String, birthdate: LocalDate,\n    val empNo: String?,\n    val dept: String?\n) : Person(name, birthdate)\n```\n\n```kotlin\n// you can write your own assertion\nfun \u003cT : Person\u003e Expect\u003cT\u003e.beUnderage() =\n    satisfyThat(\"be underage\") {\n        it.birthdate.plusYears(19) \u003e LocalDate.now()\n    }\n\nfun Expect\u003cEmployee\u003e.beValid() =\n    satisfyThat(\"be valid\") {\n        it.empNo != null \u0026\u0026 it.dept != null\n    }\n\nfun Expect\u003cEmployee\u003e.beAssignedTo(dept: String) =\n    satisfyThat(\"be assigned to $dept\") {\n        it.dept == dept\n    }\n```\n\n```kotlin\n// then you can use your assertion.\nval emp = Employee(\n    \"yunsang.choi\",\n    LocalDate.of(1976, 4, 2),\n    \"X00000\",\n    \"DevTeam\"\n)\nexpect(emp) {\n    it.should.beValid()\n    it.should.not.beUnderage()\n    it.should.not.beAssignedTo(\"DesignTeam\")\n}\n\n```\n\n[Rspec Expectation]:https://github.com/rspec/rspec-expectations\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fodd-poet%2Fkotlin-expect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fodd-poet%2Fkotlin-expect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fodd-poet%2Fkotlin-expect/lists"}