How can I skip the "should" block / fragment in specs2?

Suppose my specs2 specification is defined in the "unit" style as follows:

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) } } } 

Is there an easy way to skip / disable / mark all examples in an if block / fragment for myMethod ?

Obviously, I can call pendingUntilFixed or return pending from each individual example in a block, but that would be quite tedious for a block with many specifications.

It seems like this would be common if MyClass.myMethod hard to implement and gets fined. Is there any other way that this is usually done in specs2?

+7
source share
1 answer

You can mix in the Tags property and define any section that you want:

 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") } 

Then you run your spec with exclude pending

 >test-only *MyClassSpec* -- exclude pending 

This is documented here .

You can also use an implicit context to make sure all of your examples in the should PendingUntilFixed block:

 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) } } 

Update for 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) } } 
+7
source

All Articles