Power assertions (as known from Groovy and Spock) for the Scala language.
Clone or download
Pull request Compare This branch is 18 commits ahead of pniederw:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
jvm/src/test/scala/org/expecty
project
shared/src
.gitignore
.travis.yml
LICENSE
NOTICE
README.md
build.sbt
publish.sbt

README.md

Expecty - Power Assertions for Scala

Expecty brings power assertions as known from Groovy and Spock to the Scala language. It is a micro library that aims to do one thing well.

License and Credits

Expecty was originally written by Peter Niederwieser, author of Spock.

Expecty is licensed under the Apache 2 license.

Setup

libraryDependencies += "com.eed3si9n.expecty" %% "expecty" % "0.11.0" % Test

Code Examples

import com.eed3si9n.expecty.Expecty.assert

case class Person(name: String = "Fred", age: Int = 42) {
  def say(words: String*) = words.mkString(" ")
}

val person = Person()

// Passing expectations

assert {
  person.name == "Fred"
  person.age * 2 == 84
  person.say("Hi", "from", "Expecty!") == "Hi from Expecty!"
}

// Failing expectation

val word1 = "ping"
val word2 = "pong"

assert {
  person.say(word1, word2) == "pong pong"
}

/*
Output:

java.lang.AssertionError:

person.say(word1, word2) == "pong pong"
|      |   |      |      |
|      |   ping   pong   false
|      ping pong
Person(Fred,42)
*/

// Continue despite failing predicate

val expect2 = new Expecty(failEarly = false)

expect2 {
  person.name == "Frog"
  person.age * 2 == 73
}

/*
Output:

java.lang.AssertionError:

person.name == "Frog"
|      |    |
|      Fred false
Person(Fred,42)


person.age * 2 == 73
|      |   |   |
|      42  84  false
Person(Fred,42)
*/

Further Examples

Have a look at ExpectySpec.scala and other specs in the same directory.