Skip to content

Instantly share code, notes, and snippets.

View ddelponte's full-sized avatar

Dean Del Ponte ddelponte

  • Milwaukee, WI, USA
View GitHub Profile
@ddelponte
ddelponte / EmptyListInfo.groovy
Created June 6, 2014 15:45
When to use Collections.emptyList()
Collections.emptyList()
// Use Collections.emptyList() when you do not wish to modify the returned list, otherwise []
// That's what you use if you want to pass a default parameter that will not be modified by the called funciton
// http://stackoverflow.com/questions/5552258/collections-emptylist-vs-new-instance
@ddelponte
ddelponte / GroovyPagesGoodness.groovy
Created June 11, 2014 15:07
Unit testing tricks - groovyPages
// Templates rendered by TagLib may be verified as follows
class SomeAwesomeSpec extends Specification {
public static final String BLAH = "BLAH"
void "test something"() {
given:
groovyPages.put("/path/to/_blah.gsp", BLAH)
when:
@ddelponte
ddelponte / JobSpec.groovy
Last active August 29, 2015 14:03
How to Gain access to applicaiton data
@TestFor(MyQuartzJob)
@TestMixin(ControllerUnitTestMixin) // This allows access to grailsApplication
class MyQuartzJobSpec extends Specification {
def job
def setup() {
grailsApplication.config.some.config.stuff = true
job = new MyQuartzJob()
}
}
@ddelponte
ddelponte / Config.groovy
Created July 23, 2014 00:59
Log SQL statements and values
log4j = {
...
debug 'org.hibernate.SQL'
trace 'org.hibernate.type.descriptor.sql.BasicBinder'
}
@ddelponte
ddelponte / UrlMappingsSpec.groovy
Created September 17, 2014 16:33
How to test REST UrlMappings
import grails.test.mixin.Mock
import grails.test.mixin.TestFor
import spock.lang.IgnoreRest
import spock.lang.Specification
import spock.lang.Unroll
@Unroll
@TestFor(UrlMappings)
@Mock([MockYourController])
class UrlMappingsSpec extends Specification {
@ddelponte
ddelponte / build.sbt
Created September 19, 2014 02:42
Scala test dependencies
libraryDependencies += "org.scalatest" % "scalatest 2.10" % "2.1.0" % "test"
@ddelponte
ddelponte / TagLibRenderVerification
Created July 19, 2016 14:36
Mock out the render method on a tagLib so that it's easy to verify the template and model utilized by the tagLib when rendering
// Setup
private mockTagLibRender() {
tagLib.metaClass.render = { Map attrs ->
render = attrs
}
}
// Utilization
given:
mockTagLibRender()