【发布时间】:2012-07-18 21:15:05
【问题描述】:
我正在尝试创建一个 specs2 匹配器,它断言 File 扩展的有效性(通过重用现有的 endWith 匹配器)。但是我得到一个类型错误。我怎么能绕过它?
import java.io.File
import org.specs2.mutable.Specification
import org.specs2.matcher.{ Expectable, Matcher }
class SampleSpec extends Specification {
def hasExtension(extension: => String) = new Matcher[File] {
def apply[S <: File](actual: Expectable[S]) = {
actual.value.getPath must endWith(extension)
}
}
}
这是编译器错误:
<console>:13: error: type mismatch;
found : org.specs2.matcher.MatchResult[java.lang.String]
required: org.specs2.matcher.MatchResult[S]
actual.value.getPath must endWith(extension)
【问题讨论】: