4

After メソッドと Around メソッドを使用して変更可能な specs2 テストを実行しようとしています。私は次のものを持っています:

import org.specs2.mutable.{Specification, Around, After}
import org.specs2.specification.Scope
import org.specs2.execute.{Result, AsResult}

trait Foo extends After with Around {

  override def apply[T: AsResult](a: => T): Result = {
    lazy val result = super[Around].apply(a)
    super[After].apply(result)
  }

  override def after: Any = {
    println("after-method\n")
  }

  override def around[T: AsResult](t: => T) = {
    try {
      println("around-method\n")
      AsResult.effectively(t)
    } catch {
      case e: Throwable => {
        //preform some logic here
        throw e
      }
    }
  }
}

class Specs2Test extends Specification {
  "This test" should {
    "run with around and after" in new Context {
      true must_== true
    }
  }

  trait Context extends Scope with Foo

}

テストを実行すると、around メソッドのみが実行されます。私は何を間違っていますか?

4

1 に答える 1

4

AroundトレイトのdelayedInitメソッドが の同じメソッドをオーバーライドしていると思われAfterます。

AsResult.effectively(t)必要な効果のために、後ロジックを単に呼び出すことができることに注意してください。

def around[T : AsResult](t: =>T) {
  // before logic
  val result = AsResult.effectively(t)
  // after logic
  result
}
于 2013-09-14T10:55:43.757 に答える