2013-02-20 25 views
7

मान लीजिए मैं एक specs2 विनिर्देश "इकाई" शैली में परिभाषित के रूप में निम्नानुसार है:मैं 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) 
    } 
    } 
} 

वहाँ एक आसान तरीका छोड़/अक्षम/निशान के भीतर उदाहरण के सभी लंबित myMethod के लिए/टुकड़ा ब्लॉक चाहिए?

स्पष्ट रूप से मैं pendingUntilFixed पर कॉल कर सकता हूं या ब्लॉक में प्रत्येक व्यक्तिगत उदाहरण से pending वापस कर सकता हूं, लेकिन यह कई विनिर्देशों के साथ एक ब्लॉक के लिए कठिन होगा।

ऐसा लगता है कि MyClass.myMethod को लागू करना मुश्किल है और पेंट हो जाता है। क्या एक और तरीका है कि यह आमतौर पर specs2 में किया जाता है?

उत्तर

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 

यह here प्रलेखित है आपके विनिर्देशन चलाते हैं।

तुम भी बनाने के लिए एक अंतर्निहित संदर्भ का उपयोग कर सकते लगता है कि 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) 
    } 
} 
+0

ज़रूर, यह सही रहेगा। धन्यवाद! – Kevinoid

+0

मुझे नहीं लगता कि उत्पादन में लंबित के रूप में टुकड़े दिखाने के लिए एक तरीका है? जब उन्हें बाहर रखा जाता है, तो वे ठीक करने के लिए याद रखना थोड़ा मुश्किल हो जाते हैं (कम से कम, मेरे लिए)। – Kevinoid

+0

मैंने आपके उत्तर के बाद उत्तर अपडेट किया है। – Eric