scalatestのit
キーワードの周りにラッパーを構築しようとしています。しかし、このソリューションは意図したとおりに動作していないようです。また、それもコンパイルされません。次のようにscalatestの "it"キーワードの周りにラッパーを構築する方法は?
trait MyFunSpec extends FunSpec {
private val _it: FunSpec.this.ItWord = it
protected def it(specText: String, testTags: org.scalatest.Tag*)
// ...do something extra here...
(testFun: => Any /* Assertion */)(implicit pos: Position): Unit = {
_it(specText, testTags: _*)(testFun)(pos)
// ...do something extra here...
}
}
を、私はこのコードをコンパイルした後、取得していますエラーメッセージは次のとおりです。
[error] MyFunSpec.scala: ambiguous reference to overloaded definition,
[error] both method it in trait MyFunSpec of type (specText: String, testTags:
org.scalatest.Tag*)(testFun: => Any)(implicit pos:
org.scalactic.source.Position)Unit
[error] and value it in trait FunSpecLike of type => FunSpecSpec.this.ItWord
[error] match argument types (String)
主な考え方は、メソッドの名前がit
残っていることであるので、名前の変更に注意してくださいそれはalternativeIt
のようなものにはここで満足な解決策ではありません。
私はここで間違っていますか?どんな解決策も高く評価されるでしょう!ありがとう!
、コンパイラが混乱します。次に、実際にそれを無効にするには、val it = new ItWord {...}をオーバーライドする必要があります。その匿名クラスの中で、SuperはFunSpecの古いItWord実装を参照します。 – HTNW