Skip to content

Commit

Permalink
Pre-Release 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
winterbe committed Feb 25, 2016
1 parent 24dd82a commit b9754fc
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 22 deletions.
45 changes: 32 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<dependency>
<groupId>com.winterbe</groupId>
<artifactId>expekt</artifactId>
<version>0.1.0</version>
<scope>test</scope>
</dependency>
```

##### 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.
Expand Down Expand Up @@ -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
<dependency>
<groupId>com.winterbe</groupId>
<artifactId>expekt</artifactId>
<version>0.1-SNAPSHOT</version>
<scope>test</scope>
</dependency>
```

### API Doc

Work in progress...
Expand Down
99 changes: 91 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.winterbe</groupId>
<artifactId>expekt</artifactId>
<version>0.1-SNAPSHOT</version>
<version>0.1.0</version>
<name>Expekt</name>
<description>BDD assertion library for Kotlin</description>
<url>https://github.com/winterbe/expekt</url>
<licenses>
<license>
<name>MIT License</name>
<url>http://www.opensource.org/licenses/mit-license.php</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<name>Benjamin Winterberg</name>
Expand All @@ -29,13 +36,16 @@
<system>TravisCI</system>
<url>https://travis-ci.org/winterbe/expekt</url>
</ciManagement>
<licenses>
<license>
<name>MIT License</name>
<url>http://www.opensource.org/licenses/mit-license.php</url>
<distribution>repo</distribution>
</license>
</licenses>
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
<properties>
<kotlin.version>1.0.0</kotlin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -87,6 +97,79 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.6</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>release</id>
<build>
<resources>
<resource>
<directory>src/main/kotlin</directory>
<includes>
<include>**/*.kt</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>package</phase>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>empty-javadoc-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>javadoc</classifier>
<classesDirectory>${basedir}/javadoc</classesDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
8 changes: 7 additions & 1 deletion src/main/kotlin/com/winterbe/expekt/ExpectDouble.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.winterbe.expekt

import java.math.BigDecimal

/**
* @author Benjamin Winterberg
*/
Expand All @@ -8,7 +10,11 @@ class ExpectDouble(subject: Double?, flavor: Flavor) : ExpectComparable<Double>(
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
}

Expand Down
8 changes: 8 additions & 0 deletions src/main/kotlin/com/winterbe/expekt/Functions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ val <T: Comparable<T>> T?.should: ExpectComparable<T> get() {
return ExpectComparable(this, Flavor.SHOULD)
}

val Double?.should: ExpectDouble get() {
return ExpectDouble(this, Flavor.SHOULD)
}

val <T> Collection<T>?.should: ExpectCollection<T> get() {
return ExpectCollection(this, Flavor.SHOULD)
}
Expand All @@ -37,6 +41,10 @@ fun <T: Comparable<T>> expect(subject: T?): ExpectComparable<T> {
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)
}
Expand Down
12 changes: 12 additions & 0 deletions src/test/kotlin/com/winterbe/expekt/ExpectDoubleTest.kt
Original file line number Diff line number Diff line change
@@ -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) }
}

}

0 comments on commit b9754fc

Please sign in to comment.