Skip to content

Instantly share code, notes, and snippets.

@johnrengelman
Created January 10, 2013 03:40
Show Gist options
  • Save johnrengelman/4499229 to your computer and use it in GitHub Desktop.
Save johnrengelman/4499229 to your computer and use it in GitHub Desktop.
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)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment