Created
January 10, 2013 03:40
-
-
Save johnrengelman/4499229 to your computer and use it in GitHub Desktop.
Mocking file operations in Groovy during tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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