2013-02-20 7 views
7

Supponiamo che io abbia una specifica specs2 definito nello stile "Unità" come segue:Come posso saltare un blocco/frammento "dovrebbe" in 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) 
    } 
    } 
} 

C'è un modo semplice per saltare/disabilitare/marchio in attesa di tutti gli esempi all'interno dovrebbe bloccare/frammento per myMethod?

Ovviamente posso chiamare pendingUntilFixed o restituire pending da ogni singolo esempio nel blocco, ma questo sarebbe piuttosto noioso per un blocco con molte specifiche.

Sembra che questo sarebbe un evento comune se MyClass.myMethod è difficile da implementare e viene punted. C'è un altro modo in cui questo è comunemente fatto in specs2?

risposta

7

Potete mescolare nel Tags tratto e definire qualsiasi section si desidera:

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

quindi si esegue la vostra specifica con exclude pending

>test-only *MyClassSpec* -- exclude pending 

Questo è documentato here.

È anche possibile utilizzare un contesto implicita per assicurarsi che tutti i tuoi esempi in blocco should sono 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) 
    } 
} 

Aggiornamento per 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) 
    } 
} 
+0

Certo, questo succederà. Grazie! – Kevinoid

+0

Non credo che ci sia un modo per far apparire i frammenti come in sospeso nell'output? Quando sono esclusi, diventano un po 'più difficili da ricordare da correggere (almeno per me). – Kevinoid

+0

Ho aggiornato la risposta con quello che probabilmente stai cercando. – Eric

Problemi correlati