Skip to content

Instantly share code, notes, and snippets.

@piotrga
Last active December 30, 2015 04:59
Show Gist options
  • Save piotrga/7779478 to your computer and use it in GitHub Desktop.
Save piotrga/7779478 to your computer and use it in GitHub Desktop.
Naming test data for better error messages
class DatesTest extends FreeSpec with Matchers{
import java.util.Date
import scala.concurrent.duration._
implicit class RichDate(d:Date){
def -(duration: Duration) = new Date(d.getTime - duration.toMillis)
def +(duration: Duration) = new Date(d.getTime + duration.toMillis)
def as(name: String) = new Date(d.getTime){
override def toString = s"[$name]"
}
}
val now = new Date() as "now"
val past = now - 1.day as "past"
val future = now + 1.day as "future"
"now should be > past" in (now should be < past)
"now should be < future" in (now should be > future)
}
This gives better error messages:
[now] was not greater than [future]
[now] was not less than [past]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment