Skip to content

Instantly share code, notes, and snippets.

@OlegYch
Forked from igstan/LearningSpecs2.scala
Created August 1, 2012 11:59
Show Gist options
  • Save OlegYch/3226212 to your computer and use it in GitHub Desktop.
Save OlegYch/3226212 to your computer and use it in GitHub Desktop.
Partial verification of arguments passed to a mocked method in specs2.
import org.specs2.mock.Mockito
import org.specs2.mutable.SpecificationWithJUnit
import org.specs2.mock.mockito.MockitoFunctions
class LearningTest extends SpecificationWithJUnit {
trait Logger {
def error(a: String, e: Throwable)
}
class mocks extends Mockito with MockitoFunctions {
val mockedLogger = mock[Logger]
}
"mocking" should {
"be able to verify arguments passed to mocks" in {
val m = new mocks
import m._
val exception = new RuntimeException
mockedLogger.error("message", exception)
got {
one(mockedLogger).error("message1", exception)
}
}
"be able to *partially* verify arguments passed to mocks" in {
val m = new mocks
import m._
val exception = new IllegalArgumentException
mockedLogger.error("message", exception)
got {
one(mockedLogger).error(any[String], ===(exception))
}
}
}
}
@OlegYch
Copy link
Author

OlegYch commented Aug 1, 2012

[INFO] +- junit:junit:jar:4.8.1:test
[INFO] +- org.specs2:specs2_2.9.2:jar:1.9:test
[INFO] | - org.specs2:specs2-scalaz-core_2.9.2:jar:6.0.1:runtime (scope managed from test)
[INFO] +- org.hamcrest:hamcrest-all:jar:1.1:test
[INFO] - org.mockito:mockito-all:jar:1.9.0:test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment