2014-03-28 30 views
0

我在我的Grails集成規範中創建了一些燈具。我想要做的是以某種方式檢索所述夾具,而不必將其綁定到對象上的「findBy」方法和一些屬性。讓我解釋一下,我的夾具是這樣列出的。訪問Grails Fixture

fixture { 
    superBiscuitMaker(BiscuitMaker, 
      firstName: "ButterMe" 
      lastName: "Biscuits" 
    ) 
} 

然後在我的集成測試中,當我想訪問「superBiscuitMaker」時,我會這樣做。

def maker = BiscuitMaker.findByFirstName("ButterMe") 

這似乎有點多餘,因爲我已經在我的夾具中標記了BiscuitMaker(SuperBiscuitMaker)。我已經閱讀過文檔,但它很薄,它指的是版本1.0.2,我使用的是1.2。

任何幫助,非常感謝。

回答

0

我的問題的解決方案是通過夾具固定器來保持返回物體。

class SomeControllerIntegrationSpec extends IntegrationSpec { 
    ... 
    def fixtures 
    def setup() { 
     String[] fixturesList = ["biscuits/BiscuitMakers","something/Else"] 
     fixtures = fixtureLoader.load(fixturesList) 
    } 

    void "Update biscuit maker"(){ 
     when: 
     def bMaker = fixtures.superBiscuitMaker 
    }