           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 passed the path to a buffer that is currently opened", ->
      it "returns a new edit session containing currently opened buffer", ->
        editor = null
        waitsForPromise ->
          atom.project.open(absolutePath).then (o) -> editor = o

        runs ->
          newBufferHandler.reset()
          expect(atom.project.openSync(absolutePath).buffer).toBe editor.buffer
          expect(atom.project.openSync('a').buffer).toBe editor.buffer
          expect(newBufferHandler).not.toHaveBeenCalled()

    describe "when not passed a path", ->
      it "returns a new edit session and emits 'buffer-created'", ->

          expect(resultHandler).not.toHaveBeenCalled()

      it "scans buffer contents if the buffer is modified", ->
        editor = null
        results = []

        waitsForPromise ->
          atom.project.open('a').then (o) ->
            editor = o
            editor.setText("Elephant")

        waitsForPromise ->
          atom.project.scan /a|Elephant/, (result) -> results.push result

