diff --git a/README.md b/README.md index 605b25e..9d330af 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,27 @@ -# kotlin-expect +# kotlin-expect + [![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) `kotlin-expect` is a assertion library for kotlin test. it's inspried by [Rspec Expectation]. - -## Setup +## Setup ```gradle dependencies { - testCompile("net.oddpoet:kotlin-expect:1.3.1") + testCompile("net.oddpoet:kotlin-expect:1.3.2") } ``` -## Basic Usage +## Basic Usage ### `expect(s).to` -You can write an assertion for a subject in the form `expect(subject).to`. +You can write an assertion for a subject in the form `expect(subject).to`. ```kotlin val list = listOf(1, 2, 3) expect(list).to.haveSizeOf(3) -expect(list).to.satisfy { size == 3} +expect(list).to.satisfy { size == 3 } expect(list).to.not.contain(5) expect(list).to.containAll { it < 10 } expect(list).to.not.beInstanceOf(Set::class) @@ -49,6 +49,7 @@ expect(aList) { it.should.containAny { it.lenngth < 2 } } ``` + ### `expect { }.throws()` An assertion for an exception can be written in the form `expect { ... }.throws()`. @@ -67,7 +68,7 @@ expect { ``` ## Write own your assertion - + `Kotlin-expect` has built-in assertions for java base types(`String`, `Collection`, `Map`, `Number` and so on). You can define new assertions for your class. An assertion for a class is defined as an extension of the `Expect` class. @@ -77,39 +78,43 @@ An assertion for a class is defined as an extension of the `Expect` class. ```kotlin // for your classes abstract class Person( - val name: String, - val birthdate: LocalDate) + val name: String, + val birthdate: LocalDate +) class Employee( - name: String, birthdate: LocalDate, - val empNo: String?, - val dept: String?) : Person(name, birthdate) + name: String, birthdate: LocalDate, + val empNo: String?, + val dept: String? +) : Person(name, birthdate) ``` ```kotlin // you can write your own assertion fun Expect.beUnderage() = - satisfyThat("be underage") { - it.birthdate.plusYears(19) > LocalDate.now() - } + satisfyThat("be underage") { + it.birthdate.plusYears(19) > LocalDate.now() + } fun Expect.beValid() = - satisfyThat("be valid") { - it.empNo != null && it.dept != null - } + satisfyThat("be valid") { + it.empNo != null && it.dept != null + } fun Expect.beAssignedTo(dept: String) = - satisfyThat("be assigned to $dept") { - it.dept == dept - } + satisfyThat("be assigned to $dept") { + it.dept == dept + } ``` + ```kotlin // then you can use your assertion. val emp = Employee( - "yunsang.choi", - LocalDate.of(1976, 4, 2), - "X00000", - "DevTeam") + "yunsang.choi", + LocalDate.of(1976, 4, 2), + "X00000", + "DevTeam" +) expect(emp) { it.should.beValid() it.should.not.beUnderage()