Skip to content

Instantly share code, notes, and snippets.

@julienba
Forked from teamon/specs.scala
Created July 22, 2012 18:16
Show Gist options
  • Save julienba/3160564 to your computer and use it in GitHub Desktop.
Save julienba/3160564 to your computer and use it in GitHub Desktop.
Scala specs cheatsheet
// === Basics
a must beMatching(bar)
a must be matching(bar)
a must not be matching(bar) // negation
// === Any object
a must_== b
a must_!= b
a must beNull
a must beOneOf(1, 2, 3)
// === Strings
a must include(string)
a must startWith(string)
a must endWith(string)
// === Numerical
a must be_>(b)
a must be_>=(b)
a must be_<(b)
a must be_<=(b)
a must be closeTo(b +/- delta)
// === Iterables
a must be empty
a must haveSize(3)
a must contain(value)
a must containAll(someIterable)
a must containInOrder(val1, val2, val3)
a must exists(f) // f: T => Boolean
a must haveTheSameElementsAs(someIterable)
// === Maps
map must haveKey(k)
map must haveValue(k)
map must havePair(p)
map must havePairs(pairs)
// === Options
opt must beNone
opt must beSome[Type]
opt must beSomething
opt must beSome(value)
opt must beSome[String].which(_.startWith("foo"))
// === Exceptions
a must throwA[SomeException]
// === Paths (as Strings)
a must beAnExistingPath
a must beAReadablePath
a must beAWritablePath
a must beAnAbsolutePath
a must beACanonicalPath
a must beAFilePath
a must beADirectoryPath
// === Files
file must exist
file must beReadable
file must beWritable
file must beAbsolute
file must beFile
file must beDirectory
// === Other
fail("Reason for explicit fail")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment