Тестирование чаш Грааля taglib

Grails 1.1. Мой пользовательский тег:

class MyTagLib {
  static namespace 'ct'
  def textField = {attrs ->
    def bean = attrs.remove('bean')
    def field = attrs.remove('field')
    attrs.name = field
    out << render(template:"/templates/textField", model:[
        required: !bean.constraints[field].nullable,
        display : bean["${bean.trainingExperience.type}"][field],
        theTag : g.textField(name : field, value : bean[field]),
        value : bean[field]
    ])
}

Примерно все taglib модульные тесты я вижу просто

AssertEquals "Some String", taglib.out.toString()

Действительно ли возможно протестировать тот корректный шаблон, представляется с правильными значениями в модели?

MyTagLibTests

public class CareertracTagLibTests extends TagLibUnitTestCase{
  protected void setUp() {
    super.setUp()
    mockTagLib(FormTagLib)
    mockTagLib(RenderTagLib) 
    def g = new FormTagLib() // interpret "g" namespace as instances of FormTagLib
    tagLib.metaClass.g = g
    String.metaClass.encodeAsHTML = {org.codehaus.groovy.grails.plugins.codecs.HTMLCodec.encode(it)}
  }
  void TestTextField() {
    tagLib.textField([bean : mockBean, field : 'viewField'])
    def x = new RenderTagLib().render(template:"/templates/textField", 
      model:[required:false, 
              display:"view",
              // Snip 
            ])
    assertEquals tagLib.out, x.out // Or something like this
  }
} 

}

7
задан 11 June 2009 в 15:28
поделиться