         done()
 
   describe "modified status", ->
-    [filePath] = []
+    [filePath, modifiedHandler, doneFunc] = []
 
     beforeEach (done) ->
       filePath = join(temp.dir, 'atom-tmp-file')


    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()


      describe "when the serialized buffer had unsaved changes", ->
        describe "when the disk contents were changed since serialization", ->
          it "loads the disk contents instead of the previous unsaved state", (done) ->
            buffer.setText("BUFFER CHANGE")
            fs.writeFileSync(filePath, "DISK CHANGE")

            buffer2 = buffer.testSerialization({load: false})
            buffer2.load().then ->
              expect(buffer2.getPath()).toBe(buffer.getPath())
              expect(buffer2.getText()).toBe("DISK CHANGE")
              expect(buffer2.isModified()).toBeFalsy()
              done()

        describe "when the disk contents are the same since serialization", ->
          [previousText] = []
