def testTurtle {
val t = mock[Turtle]
t.expects.penDown()
t.expects.turn(90.0)
t.expects.forward(10.0)
t.expects.getPosition returning (0.0, 10.0)
drawLine(t)
}
def testFoldLeft() {
val f = mockFunction[String, Int, String]
f expects ("initial", 0) returning "intermediate one"
f expects ("intermediate one", 1) returning "intermediate two"
f expects ("intermediate two", 2) returning "intermediate three"
f expects ("intermediate three", 3) returning "final"
expect("final") { Seq(0, 1, 2, 3).foldLeft("initial")(f) }
}
As well as traits (interfaces) and functions, ScalaMock can also mock:
Download from Sonatype.
To use ScalaMock in sbt 0.11 with ScalaTest add the following to your project file:
resolvers += "Sonatype OSS Releases" at "http://oss.sonatype.org/content/repositories/releases/" libraryDependencies += "org.scalamock" %% "scalamock-scalatest-support" % "latest.integration"
The source is hosted on GitHub.
If you're migrating from Borachio, read this.