2013-04-29 50 views
1

有時我們需要在測試用例中混合使用某些特徵。然而下面不工作:在規範中創建夾具2

"abc" should { 
    "def" in new TraitA with TraitAB { 
    // ... 
    }  
} 

要使其工作,我們執行以下操作:

trait Fixture extends Before { 
    def before =() 
} 

"abc" should { 
    "def" in new Fixture with TraitA with TraitAB { 
    // ... 
    }  
} 

這種感覺有點哈克。有沒有更好的方法來做到這一點?

回答

2

這將工作,如果你還在org.specs2.specification.Scope標記性狀混合:

"abc" should { 
    "def" in test { 
    // ... 
    }  
} 

trait test extends TraitA with TraitAB with Scope