           expect(results[0].filePath).toBe commentFilePath
 
       it "does NOT save when modified", ->
-        editor = atom.project.openSync('sample.js')
-        editor.buffer.setTextInRange([[0,0],[0,0]], 'omg')
-        expect(editor.isModified()).toBeTruthy()
-
-        results = []
+        editor = null
+        results = []
+
+        waitsForPromise ->
+          atom.project.open('sample.js').then (o) -> editor = o
+
+        runs ->
+          editor.buffer.setTextInRange([[0,0],[0,0]], 'omg')
+          expect(editor.isModified()).toBeTruthy()
+
         waitsForPromise ->
           atom.project.replace /items/gi, 'okthen', [filePath], (result) ->
             results.push(result)


    describe "when a buffer is already open", ->
      it "replaces properly and saves when not modified", ->
        editor = atom.project.openSync('sample.js')
        expect(editor.isModified()).toBeFalsy()

        results = []
        waitsForPromise ->
          atom.project.replace /items/gi, 'items', [filePath], (result) ->
            results.push(result)

      deserializedProject?.destroy()

    it "does not include unretained buffers in the serialized state", ->
      waitsForPromise ->
        atom.project.bufferForPath('a')

      runs ->
        expect(atom.project.getBuffers().length).toBe 1
        deserializedProject = atom.project.testSerialization()
        expect(deserializedProject.getBuffers().length).toBe 0

    it "listens for destroyed events on deserialized buffers and removes them when they are destroyed", ->
      waitsForPromise ->
        atom.project.open('a')

      runs ->
        expect(atom.project.getBuffers().length).toBe 1
        deserializedProject = atom.project.testSerialization()

        expect(deserializedProject.getBuffers().length).toBe 1
        deserializedProject.getBuffers()[0].destroy()
        expect(deserializedProject.getBuffers().length).toBe 0

  describe "when an editor is saved and the project has no path", ->
    it "sets the project's path to the saved file's parent directory", ->
      tempFile = temp.openSync().path
      atom.project.setPath(undefined)
      expect(atom.project.getPath()).toBeUndefined()
      editor = null

      waitsForPromise ->
        atom.project.open().then (o) -> editor = o

      runs ->
        editor.saveAs(tempFile)
        expect(atom.project.getPath()).toBe path.dirname(tempFile)

  describe ".open(path)", ->
    [absolutePath, newBufferHandler] = []

    beforeEach ->
      absolutePath = require.resolve('./fixtures/dir/a')
      newBufferHandler = jasmine.createSpy('newBufferHandler')
      atom.project.on 'buffer-created', newBufferHandler

    describe "when given an absolute path that isn't currently open", ->
      it "returns a new edit session for the given path and emits 'buffer-created'", ->
        editor = null
