我有一个测试,其中gsp使用Asset Pipeline标签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')
}
}
最佳答案
原来我需要模拟某些类:
@Mock([AssetsTagLib, AssetMethodTagLib, AssetProcessorService])
为了使类得以解决,我需要在build.gradle中添加一个testCompile依赖项。
testCompile "com.bertramlabs.plugins:asset-pipeline-grails:2.9.4"
关于grails - 测试 View 时如何模拟Asset-Pipeline taglib,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38597805/