Skip to content

Instantly share code, notes, and snippets.

@ishults
Last active December 16, 2015 20:00
Show Gist options
  • Save ishults/b045500e37d50d31c4bd to your computer and use it in GitHub Desktop.
Save ishults/b045500e37d50d31c4bd to your computer and use it in GitHub Desktop.
package com.igor
import grails.test.mixin.*
import org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagException
import spock.lang.Specification
import spock.lang.Unroll
@TestFor(GormTagLib)
class GormTagLibSpec extends Specification {
void "limit() should throw an exception if attributes are missing or wrong"() {
when:
tagLib.limit(clazz: className, field: fieldName)
then:
thrown(GrailsTagException)
where:
className | fieldName
null | 'username'
GormTagLibUser.canonicalName | null
'NoSuchClass' | 'username'
GormTagLibUser.simpleName | 'username' // Needs package name
GormTagLibUser.canonicalName | 'NoSuchField'
}
@Unroll
void "limit() should return the max size of a field if it is present, or otherwise null"() {
when:
String value = tagLib.limit(clazz: GormTagLibUser.canonicalName, field: fieldName)
then:
expectedValue.toString() == value
where:
fieldName | expectedValue
'username' | 50
'firstName' | 25
'middleName' | ''
'lastName' | 20
'age' | ''
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment