 
       expect(eventHandler).toHaveBeenCalledWith(filePath)
 
-    xit "stops listening to events on previous path and begins listening to events on new path", ->
-      changeHandler = null
-      originalPath = join(temp.dir, 'original.txt')
-      newPath = join(temp.dir, 'new.txt')
-      fs.writeFileSync(originalPath, "")
-
-      saveAsBuffer = new TextBuffer({filePath: originalPath, load: true})
-
-      waitsFor ->
-        saveAsBuffer.loaded
-
-      runs ->
-        changeHandler = jasmine.createSpy('changeHandler')
+    describe "when the path is changed", ->
+      [changeHandler, originalPath, newPath, saveAsBuffer, doneFunc] = []
+      beforeEach (done) ->
+        changeHandler = null
+        originalPath = join(temp.dir, 'original.txt')
+        newPath = join(temp.dir, 'new.txt')
+        fs.writeFileSync(originalPath, "")
+
+        saveAsBuffer = new TextBuffer({filePath: originalPath, load: false})
+        saveAsBuffer.load().then ->
+          done()
+
+      beforeEach (done) ->
+        doneFunc = ->
+          # No-op
+
+        changeHandler = jasmine.createSpy('changeHandler').and.callFake ->
+          doneFunc()
         saveAsBuffer.onDidChange changeHandler
         saveAsBuffer.saveAs(newPath)
         expect(changeHandler).not.toHaveBeenCalled()
 
         fs.writeFileSync(originalPath, "should not trigger buffer event")
-
-      waits 20
-
-      runs ->
-        expect(changeHandler).not.toHaveBeenCalled()
+        setTimeout(->
+          expect(changeHandler).not.toHaveBeenCalled()
+          done()
+        , 20)
+
+      it "stops listening to events on previous path and begins listening to events on new path", (done) ->
+        doneFunc = ->
+          expect(changeHandler).toHaveBeenCalled()
+          done()
         fs.writeFileSync(newPath, "should trigger buffer event")
-
-      waitsFor ->
-        changeHandler.calls.count() > 0
 
     describe "if the 'backup' option is true", ->
       [backupFilePath, saveAsBuffer] = []


    afterEach ->
      buffer?.destroy()

    xit "reports the modified status changing to true or false after the user changes buffer", ->
      modifiedHandler = jasmine.createSpy("modifiedHandler")
      buffer.onDidChangeModified modifiedHandler

      expect(buffer.isModified()).toBeFalsy()
      buffer.insert([0,0], "hi")
      expect(buffer.isModified()).toBe true

      waitsFor ->
        modifiedHandler.calls.count() is 1

      runs ->
        expect(modifiedHandler).toHaveBeenCalledWith(true)

        modifiedHandler.reset()
        buffer.insert([0,2], "ho")

      waits buffer.stoppedChangingDelay * 2

      runs ->
        expect(modifiedHandler).not.toHaveBeenCalled()

        modifiedHandler.reset()
        buffer.undo()
        buffer.undo()

      waitsFor ->
        modifiedHandler.calls.count() is 1

      runs ->
        expect(modifiedHandler).toHaveBeenCalledWith(false)

    xit "reports the modified status changing to false after a modified buffer is saved", ->
      modifiedHandler = jasmine.createSpy("modifiedHandler")
      buffer.onDidChangeModified modifiedHandler
      buffer.insert([0,0], "hi")

      waitsFor ->
        modifiedHandler.calls.count() is 1

      runs ->
        expect(buffer.isModified()).toBe true

        modifiedHandler.reset()
        buffer.save()

        expect(modifiedHandler).toHaveBeenCalledWith(false)
        expect(buffer.isModified()).toBe false
        modifiedHandler.reset()

        buffer.insert([0, 0], 'x')

      waitsFor ->
        modifiedHandler.calls.count() is 1

      runs ->
        expect(modifiedHandler).toHaveBeenCalledWith(true)
        expect(buffer.isModified()).toBe true

    xit "reports the modified status changing to false after a modified buffer is reloaded", ->
      modifiedHandler = jasmine.createSpy("modifiedHandler")
      buffer.onDidChangeModified modifiedHandler
      buffer.insert([0,0], "hi")

      waitsFor ->
        modifiedHandler.calls.count() is 1

      runs ->
        expect(buffer.isModified()).toBe true

        modifiedHandler.reset()
        buffer.reload()

        expect(modifiedHandler).toHaveBeenCalledWith(false)
        expect(buffer.isModified()).toBe false

        modifiedHandler.reset()
        buffer.insert([0, 0], 'x')

      waitsFor ->
        modifiedHandler.calls.count() is 1

      runs ->
        expect(modifiedHandler).toHaveBeenCalledWith(true)
        expect(buffer.isModified()).toBe true

    xit "reports the modified status changing to false after a buffer to a non-existent file is saved", ->
      buffer.destroy()
      fs.removeSync(filePath)
      expect(fs.existsSync(filePath)).toBeFalsy()

      buffer = new TextBuffer({filePath, load: false})
      modifiedHandler = jasmine.createSpy("modifiedHandler")
      buffer.load().then ->
        done()

      runs ->
        buffer.onDidChangeModified modifiedHandler
        buffer.insert([0,0], "hi")

      waitsFor ->
        modifiedHandler.calls.count() is 1

      runs ->
        expect(buffer.isModified()).toBe true

        modifiedHandler.reset()
        buffer.save()

        expect(fs.existsSync(filePath)).toBeTruthy()
        expect(modifiedHandler).toHaveBeenCalledWith(false)
        expect(buffer.isModified()).toBe false

        modifiedHandler.reset()
        buffer.insert([0, 0], 'x')

      waitsFor ->
        modifiedHandler.calls.count() is 1

      runs ->
        expect(modifiedHandler).toHaveBeenCalledWith(true)
        expect(buffer.isModified()).toBe true

    it "returns false for an empty buffer with no path", ->
      buffer.destroy()

        done()

  describe "modified status", ->
    [filePath, modifiedHandler, doneFunc] = []

    beforeEach (done) ->
      filePath = join(temp.dir, 'atom-tmp-file')
