Skip to content

Instantly share code, notes, and snippets.

@johnrengelman
johnrengelman / gist:3823684
Created October 2, 2012 22:19
Set a hasMany collection on a domain object using BuildTestsData
class Foo {
Bar bar
}
class Bar {
static belongsTo = Foo
static hasMany = [bazzes: Baz]
}
class Baz {
@johnrengelman
johnrengelman / filemock.groovy
Created January 10, 2013 03:40
Mocking file operations in Groovy during tests
def pipeInput = new PipedInputStream()
def outputStreamMock = new BufferedOutputStream(new PipedOutputStream(pipeInput))
writerMock = new StringWriter()
File.metaClass.withOutputStream = {Closure c ->
c.call(outputStreamMock)
}
File.metaClass.withWriter = {Closure c ->
c.call(writerMock)
}
@johnrengelman
johnrengelman / build-ivy.gradle
Last active May 3, 2018 11:24
Setting Gradle to publish to BinTray
repositories {
mavenCentral()
}
apply plugin: 'maven'
apply plugin: 'groovy'
apply plugin: 'idea'
group = 'org.gradle.plugins'
version = "${currentVersion}"
@johnrengelman
johnrengelman / FooSpec.groovy
Created April 10, 2013 14:46
Example Grails Filter Unit Test
@TestFor(FooController)
@Mock(FooFilters)
class FooSpec extends Specification {
FooService fooServiceMock
def "testing a filter"() {
given:
defineBeans {
fooService(MethodInvokingFactoryBean) {
@johnrengelman
johnrengelman / build.gradle
Last active December 16, 2015 07:39
Building Grails 2.2.1 with Gradle, with Spock testing and Codenarc and some extra tasks to mimic Java/Groovy projects in Gradle
import org.grails.gradle.plugin.GrailsTask
apply plugin: 'grails'
grails {
grailsVersion '2.2.1'
}
buildscript {
repositories {
@johnrengelman
johnrengelman / script
Created April 29, 2013 17:49
Find all files that match a pattern and rename them to a new naming convention.
find . -name "Service*.json" | awk '{orig=$1;mod=$1;sub(/Service/,"",mod);sub(/.json/,"Service.json");print("git mv "orig" "mod)}' | /bin/sh
@johnrengelman
johnrengelman / BuildConfig.groovy
Created May 10, 2013 16:53
Grails 2.3.0.M1 Maven Repo Credentials
grails.servlet.version = "3.0" // Change depending on target container compliance (2.5 or 3.0)
grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"
grails.project.work.dir = "target/work"
grails.project.target.level = 1.6
grails.project.source.level = 1.6
//grails.project.war.file = "target/${appName}-${appVersion}.war"
forkConfig = [maxMemory: 1024, minMemory: 64, debug: false, maxPerm: 256]
@johnrengelman
johnrengelman / Gruntfiles.js
Created June 20, 2013 17:04
Failing lesslint example
csslint: {
options: {
formatters: [
{id: 'lint-xml', dest: 'build/reports/csslint/csslint.xml'}
]
},
strict: {
options: {
// IDs until re-use needed. Re-factor scaredy cats!
ids: false,
@johnrengelman
johnrengelman / build.gradle
Last active December 19, 2015 12:28
Shadow Blog Post - part 1
apply plugin: 'groovy'
apply plugin: 'shadow'
buildscript {
repositories {
maven {
name 'Shadow'
url 'http://dl.bintray.com/content/johnrengelman/gradle-plugins'
}
}
@johnrengelman
johnrengelman / build.gradle
Created October 9, 2013 21:54
Deploying custom artifact with POM dependencies using Gradle 'maven-publish'
File pluginZip = project.file("grails-${project.name}-${version}.zip")
assemble.outputs.file pluginZip
project.components.add(new JavaLibrary(
new org.gradle.api.internal.artifacts.publish.DefaultPublishArtifact(
project.name,
'zip',
'zip',
'',
new Date(pluginZip.lastModified()),