如何在测试视图时模拟Asset-Pipeline标记库

时间:2016-07-26 18:55:06

标签: grails grails-3.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]]

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

1 个答案:

答案 0 :(得分:2)

原来我需要模拟某些类:

@Mock([AssetsTagLib, AssetMethodTagLib, AssetProcessorService])

要获得要解决的类,我需要将testCompile依赖项添加到build.gradle

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