这是一个重现该问题的简单规范:
package ro.igstan.learning
import org.specs2.matcher.ThrownExpectations
import org.specs2.mock.Mockito
import org.specs2.mutable.Specification
import org.specs2.specification.Scope
class LearningSpecs2 extends Specification {
trait Logger {
def error(a: String, b: String)
}
trait mocks extends Mockito with Scope with ThrownExpectations {
val mockedLogger = mock[Logger]
}
"mocking" should {
// passes
"be able to verify arguments passed to mocks" in new mocks {
mockedLogger.error("message", "foo")
got {
one(mockedLogger).error("message", "foo")
}
}
// fails
"be able to *partially* verify arguments passed to mocks" in new mocks {
mockedLogger.error("message", "foo")
got {
one(mockedLogger).error(any, ===("foo"))
}
}
}
}
这是输出:
[info] mocking should
[info] + be able to verify arguments passed to mocks
[error] ! Fragment evaluation error
[error] ThrowableException: org/hamcrest/TypeSafeMatcher (FutureTask.java:303)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2.argThat(LearningSpecs2.scala:27)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2$$anonfun$2.apply$mcV$sp(LearningSpecs2.scala:31)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2$$anonfun$2.apply(LearningSpecs2.scala:31)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2$$anonfun$2.apply(LearningSpecs2.scala:31)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2.got(LearningSpecs2.scala:27)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2.<init>(LearningSpecs2.scala:30)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3.apply(LearningSpecs2.scala:27)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3.apply(LearningSpecs2.scala:27)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2.argThat(LearningSpecs2.scala:27)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2$$anonfun$2.apply$mcV$sp(LearningSpecs2.scala:31)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2$$anonfun$2.apply(LearningSpecs2.scala:31)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2$$anonfun$2.apply(LearningSpecs2.scala:31)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2.got(LearningSpecs2.scala:27)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2.<init>(LearningSpecs2.scala:30)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3.apply(LearningSpecs2.scala:27)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3.apply(LearningSpecs2.scala:27)
[error] org/hamcrest/TypeSafeMatcher
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2.argThat(LearningSpecs2.scala:27)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2$$anonfun$2.apply$mcV$sp(LearningSpecs2.scala:31)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2$$anonfun$2.apply(LearningSpecs2.scala:31)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2$$anonfun$2.apply(LearningSpecs2.scala:31)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2.got(LearningSpecs2.scala:27)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2.<init>(LearningSpecs2.scala:30)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3.apply(LearningSpecs2.scala:27)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3.apply(LearningSpecs2.scala:27)
[error] org.hamcrest.TypeSafeMatcher
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2.argThat(LearningSpecs2.scala:27)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2$$anonfun$2.apply$mcV$sp(LearningSpecs2.scala:31)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2$$anonfun$2.apply(LearningSpecs2.scala:31)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2$$anonfun$2.apply(LearningSpecs2.scala:31)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2.got(LearningSpecs2.scala:27)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3$$anon$2.<init>(LearningSpecs2.scala:30)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3.apply(LearningSpecs2.scala:27)
[error] ro.igstan.learning.LearningSpecs2$$anonfun$3$$anonfun$apply$3.apply(LearningSpecs2.scala:27)
以下是 SBT 依赖图插件报告的库版本:
[info] default:learning_2.9.1:1.0.0
[info] +-junit:junit:4.7
[info] +-org.mockito:mockito-all:1.9.0
[info] +-org.scala-lang:scala-library:2.9.1
[info] +-org.specs2:specs2_2.9.1:1.11
[info] +-org.specs2:specs2-scalaz-core_2.9.1:6.0.1
[info] +-org.scala-lang:scala-library:2.9.1
知道发生了什么吗?