2016-07-26 49 views
1

我在GSP使用資產管道標籤assetPath測試時,在Grails的2我沒有問題,但在Grails的3我發現了一個org.grails.taglib.GrailsTagException: [SOME_GSP.gsp:184] Error executing tag <g:form>: Error evaluating expression [assetPath(src: 'SOME_PDF.pdf')] on line [60]: No signature of method: SOME_GSP_gsp.assetPath() is applicable for argument types: (java.util.LinkedHashMap) values: [[src:SOME_PDF.pdf]]如何測試一個視圖

嘲笑資產管道的taglib的Grails 3.1.6

實施例的測試文件:

@TestMixin(GroovyPageUnitTestMixin) 
class SomeTests extends Specification { 

    void "ssn is not returned to the SOME_GSP page"() { 
     given: 
     def cmd = new commandObject(SOME_FIELD: 'data') 

     when: 
     def renderedView = render(view: 'SOME_GSP', model: [cmd: cmd]) 

     then: 
     assert !renderedView.contains('data') 
    } 
} 

回答

2

原來我需要嘲笑某些類:

@Mock([AssetsTagLib, AssetMethodTagLib, AssetProcessorService]) 

爲了獲得需要解決的類,我需要添加一個testCompile依賴項到我的build.gradle中

testCompile "com.bertramlabs.plugins:asset-pipeline-grails:2.9.4"