by Eric Torreborre :: Rate this Message:
Reply (Restricted by the Administrator) | Reply to Author | View Threaded | Show Only this Message
object mockExample extends Specification with ButtonAndLightMock { val mock = mock(classOf[Light]) val button = Button(mock) "A button and light mock example" should { "not fail if the mock receives the expected messages" in { expect { one(mock).on one(mock).off } button.push button.push // if the button is pressed twice, then the light will go on and off } }}
val f = new PartialFunction[Int, String] { def isDefinedAt(i: Int) = i % 2 == 0 def apply(i: Int) = (i*2).toString } "provide a beDefinedAt matcher checking if a PartialFunction is defined at specific values" in { f must beDefinedAt(2, 4, 6) } "provide a beDefinedBy matcher checking if a PartialFunction is defined at specific values" + "and returns appropriate results" in { f must beDefinedBy(2 -> "4", 4 -> "8") }