7

次のように「ユニット」スタイルで定義された specs2 仕様があるとします。

import org.specs2.mutable

class MyClassSpec extends mutable.Specification {
  "myMethod" should {
    "return positive values" in {
      MyClass.myMethod must beGreaterThan(0)
    }

    "return values less than 100" in {
      MyClass.myMethod must beLessThan(100)
    }
  }
}

should block/fragment for 内のすべての例をスキップ/無効化/保留中としてマークする簡単な方法はありmyMethodますか?

明らかに、ブロック内の個々の例を呼び出しpendingUntilFixedたり返したりすることができますが、多くの仕様を持つブロックでは、これはかなり面倒です。pending

MyClass.myMethod実装が困難でパントされる場合、これはよくあることのようです。これがspecs2で一般的に行われる別の方法はありますか?

4

1 に答える 1

7

特性を混ぜて、必要Tagsなものを定義できsectionます。

import org.specs2.mutable._

class MyClassSpec extends Specification with Tags {

  section("pending")
  "myMethod" should {
    "return positive values" in {
      MyClass.myMethod must beGreaterThan(0)
    }

    "return values less than 100" in {
      MyClass.myMethod must beLessThan(100)
    }
  }
  section("pending")
}

次に、仕様を実行しますexclude pending

>test-only *MyClassSpec* -- exclude pending

これはここに文書化されています。

暗黙のコンテキストを使用して、shouldブロック内のすべての例が次のようになっていることを確認することもできますPendingUntilFixed

import org.specs2._
import execute._

class MyClassSpec extends mutable.Specification { 
  "this doesn't work for now" >> {
    implicit val puf = pendingContext("FIXME")
    "ex1" in ko
    "ex2" in ok
  }
  "but this works ok" >> {
    "ex3" in ko // maybe not here ;-)
    "ex4" in ok
  }

  def pendingContext(reason: String) = new mutable.Around {
    def around[T <% Result](t: =>T) = 
      t.pendingUntilFixed(reason)
  }
}

specs2 3.x のアップデート

import org.specs2._
import execute._

class TestMutableSpec extends mutable.Specification {
  "this doesn't work for now" >> {
    implicit def context[T] = pendingContext[T]("FIXME")

    "ex1" in ko
    "ex2" in ok
  }
  "but this works ok" >> {
    "ex3" in ko // maybe not here ;-)
    "ex4" in ok
  }

   def pendingContext[T](reason: String): AsResult[MatchResult[T]] =     
     new AsResult[MatchResult[T]] {
      def asResult(t: =>MatchResult[T]): Result =
        AsResult(t).pendingUntilFixed(reason)
     }
}
于 2013-02-20T22:56:24.443 に答える