From b9754fc680aa038a575ce67b214529d0d5e442f7 Mon Sep 17 00:00:00 2001 From: Benjamin Winterberg Date: Thu, 25 Feb 2016 12:46:11 +0100 Subject: [PATCH] Pre-Release 0.1.0 --- README.md | 45 ++++++--- pom.xml | 99 +++++++++++++++++-- .../com/winterbe/expekt/ExpectDouble.kt | 8 +- .../kotlin/com/winterbe/expekt/Functions.kt | 8 ++ .../com/winterbe/expekt/ExpectDoubleTest.kt | 12 +++ 5 files changed, 150 insertions(+), 22 deletions(-) create mode 100644 src/test/kotlin/com/winterbe/expekt/ExpectDoubleTest.kt diff --git a/README.md b/README.md index dfb89ef..fbf775e 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,38 @@ Expekt is a (work in progress) BDD assertion library for [Kotlin](http://kotlinlang.org/), inspired by [Chai.js](http://chaijs.com/). It works with your favorite test runner such as [JUnit](http://junit.org/) and [Spek](http://jetbrains.github.io/spek/). +```kotlin +class ExpektTest { + @Test + fun helloExpekt() { + 23.should.equal(23) + "Kotlin".should.not.contain("Scala") + listOf(1, 2, 3).should.have.size.above(1) + } +} +``` + +### Getting started + +Expekt is available via [Maven Central](https://repo1.maven.org/maven2/com/winterbe/expekt/). Just add the dependency to your Maven POM or Gradle build config. + +##### Maven + +```xml + + com.winterbe + expekt + 0.1.0 + test + +``` + +##### Gradle + +```groovy +testCompile "com.winterbe:expekt:0.1.0" +``` + ### Examples Expekt enables you to formulate assertions in natural english language and fluent sentences. It comes in two flavors `should` and `expect`, both using the same API. @@ -38,19 +70,6 @@ expect(listOf(1, 2, 3)).to.have.all.elements(1, 2, 3) expect(mapOf("foo" to "bar", "bar" to "foo")).to.contain("foo" to "bar") ``` -### Getting started - -Expekt will be available via Maven Central soon. Currently you have to clone this repository and install it manually via `mvn install` into your local Maven repository. Afterwards you can add Expekt as Maven dependency to your project: - -```xml - - com.winterbe - expekt - 0.1-SNAPSHOT - test - -``` - ### API Doc Work in progress... diff --git a/pom.xml b/pom.xml index 05d9f7d..b43fb68 100644 --- a/pom.xml +++ b/pom.xml @@ -5,10 +5,17 @@ 4.0.0 com.winterbe expekt - 0.1-SNAPSHOT + 0.1.0 Expekt BDD assertion library for Kotlin https://github.com/winterbe/expekt + + + MIT License + http://www.opensource.org/licenses/mit-license.php + repo + + Benjamin Winterberg @@ -29,13 +36,16 @@ TravisCI https://travis-ci.org/winterbe/expekt - - - MIT License - http://www.opensource.org/licenses/mit-license.php - repo - - + + + ossrh + https://oss.sonatype.org/content/repositories/snapshots + + + ossrh + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + 1.0.0 UTF-8 @@ -87,6 +97,79 @@ + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.6 + true + + ossrh + https://oss.sonatype.org/ + true + + + + + release + + + + src/main/kotlin + + **/*.kt + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.6 + + + sign-artifacts + verify + + sign + + + + + + org.apache.maven.plugins + maven-source-plugin + 2.4 + + + package + attach-sources + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + empty-javadoc-jar + package + + jar + + + javadoc + ${basedir}/javadoc + + + + + + + + \ No newline at end of file diff --git a/src/main/kotlin/com/winterbe/expekt/ExpectDouble.kt b/src/main/kotlin/com/winterbe/expekt/ExpectDouble.kt index 40fd601..809e68b 100644 --- a/src/main/kotlin/com/winterbe/expekt/ExpectDouble.kt +++ b/src/main/kotlin/com/winterbe/expekt/ExpectDouble.kt @@ -1,5 +1,7 @@ package com.winterbe.expekt +import java.math.BigDecimal + /** * @author Benjamin Winterberg */ @@ -8,7 +10,11 @@ class ExpectDouble(subject: Double?, flavor: Flavor) : ExpectComparable( fun closeTo(other: Double): ExpectDouble { words.add("closeTo") words.add(other.toString()) - verify { false } // TODO + verify { + val decimalDigits = BigDecimal(other.toString()).scale() + // TODO round subject to decimalDigits and compare both + false + } return this } diff --git a/src/main/kotlin/com/winterbe/expekt/Functions.kt b/src/main/kotlin/com/winterbe/expekt/Functions.kt index dab1e23..73ee8cd 100644 --- a/src/main/kotlin/com/winterbe/expekt/Functions.kt +++ b/src/main/kotlin/com/winterbe/expekt/Functions.kt @@ -17,6 +17,10 @@ val > T?.should: ExpectComparable get() { return ExpectComparable(this, Flavor.SHOULD) } +val Double?.should: ExpectDouble get() { + return ExpectDouble(this, Flavor.SHOULD) +} + val Collection?.should: ExpectCollection get() { return ExpectCollection(this, Flavor.SHOULD) } @@ -37,6 +41,10 @@ fun > expect(subject: T?): ExpectComparable { return ExpectComparable(subject, Flavor.EXPECT) } +fun expect(subject: Double?): ExpectDouble { + return ExpectDouble(subject, Flavor.EXPECT) +} + fun expect(subject: String): ExpectString { return ExpectString(subject, Flavor.EXPECT) } diff --git a/src/test/kotlin/com/winterbe/expekt/ExpectDoubleTest.kt b/src/test/kotlin/com/winterbe/expekt/ExpectDoubleTest.kt new file mode 100644 index 0000000..950f7b0 --- /dev/null +++ b/src/test/kotlin/com/winterbe/expekt/ExpectDoubleTest.kt @@ -0,0 +1,12 @@ +package com.winterbe.expekt + +import org.junit.Test + +class ExpectDoubleTest { + + @Test + fun closeTo() { +// passes { 3.4.should.be.closeTo(3.4) } + } + +} \ No newline at end of file