Last active
December 30, 2015 04:59
-
-
Save piotrga/7779478 to your computer and use it in GitHub Desktop.
Naming test data for better error messages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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