       [backupFilePath, saveAsBuffer] = []
 
       beforeEach ->
-        filePath = join(temp.dir, 'temp.txt')
+        tempDir = temp.mkdirSync()
+        filePath = join(tempDir, 'temp.txt')
         saveAsBuffer = new TextBuffer()
         saveAsBuffer.setText 'Buffer contents'
         backupFilePath = filePath + '~'

        done()

  describe "::saveAs(path, {backup})", ->
    [filePath, saveAsBuffer] = []

    afterEach ->
      saveAsBuffer?.destroy()

    it "saves the contents of the buffer to the path", ->
      filePath = join(temp.dir, 'temp.txt')
      fs.removeSync(filePath)

      saveAsBuffer = new TextBuffer()

    [filePath, modifiedHandler, doneFunc] = []

    beforeEach (done) ->
      tempDir = temp.mkdirSync()
      filePath = join(tempDir, 'atom-tmp-file')
      fs.writeFileSync(filePath, '')
      buffer = new TextBuffer({filePath, load: false})
      buffer.load().then ->
