You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package demo
import grails.test.mixin.TestFor
import spock.lang.Specification
@TestFor(DemoTagLib)
class DemoTagLibSpec extends Specification {
void "use applyTemplate to test tag that puts something in pageScope"() {
when:
applyTemplate '<demo:putSomethingInPageScope foo="42"/>'
then:
tagLib.pageScope.someValue == '42'
}
void "use tag as method to test tag that puts something in pageScope"() {
when:
tagLib.putSomethingInPageScope(foo: '42')
then:
tagLib.pageScope.someValue == '42'
}
}
The applyTemplate approach does not work. I think multiple pageScope (TemplateVariableBinding) objects are being created and the one populated by the tag is not the same one retrieved in the test.
The text was updated successfully, but these errors were encountered:
@puneetbehl / @jeffbrown This is still a very frustrating problem. It's possible to write well-functional taglibs, but impossible to write a good test for them.
As far as I can tell, there are produced two page-bindings, one by org.grails.web.taglib.encoder.WebOutputContextLookup.WebOutputContext#createAndRegisterRootBinding and one by org.grails.gsp.GroovyPageWritable#doWriteTo (using the parent binding). It seems that the second created is the one used by the tag-lib, when accessing pageScope but for some reason, the applied template cannot find the variables written to it.
It looks like the method in org.grails.taglib.TemplateVariableBinding#getVariable is actually the one getting called by the tag-library, not org.grails.gsp.GroovyPageBinding#getVariable, but I have not been able to confirm this, and the reason.
By @jeffbrown from grails/grails-core#9576 where it was closed.
It still seems to be an issue
The applyTemplate approach does not work. I think multiple pageScope (TemplateVariableBinding) objects are being created and the one populated by the tag is not the same one retrieved in the test.
The text was updated successfully, but these errors were encountered: