 
         expect(editor.renderedLines.find('.line').length).toBe 8
 
+    describe ".spliceLineElements(startRow, rowCount, lineElements)", ->
+      elements = null
+
+      beforeEach ->
+        editor.attachToDom()
+        elements = $$ ->
+          @div "A", class: 'line'
+          @div "B", class: 'line'
+
+      describe "when the start row is 0", ->
+        describe "when the row count is 0", ->
+          it "inserts the given elements before the first row", ->
+            editor.spliceLineElements 0, 0, elements
+
+            expect(editor.renderedLines.find('.line:eq(0)').text()).toBe 'A'
+            expect(editor.renderedLines.find('.line:eq(1)').text()).toBe 'B'
+            expect(editor.renderedLines.find('.line:eq(2)').text()).toBe 'var quicksort = function () {'
+
+        describe "when the row count is > 0", ->
+          it "replaces the initial rows with the given elements", ->
+            editor.spliceLineElements 0, 2, elements
+
+            expect(editor.renderedLines.find('.line:eq(0)').text()).toBe 'A'
+            expect(editor.renderedLines.find('.line:eq(1)').text()).toBe 'B'
+            expect(editor.renderedLines.find('.line:eq(2)').text()).toBe '    if (items.length <= 1) return items;'
+
+      describe "when the start row is less than the last row", ->
+        describe "when the row count is 0", ->
+          it "inserts the elements at the specified location", ->
+            editor.spliceLineElements 2, 0, elements
+
+            expect(editor.renderedLines.find('.line:eq(2)').text()).toBe 'A'
+            expect(editor.renderedLines.find('.line:eq(3)').text()).toBe 'B'
+            expect(editor.renderedLines.find('.line:eq(4)').text()).toBe '    if (items.length <= 1) return items;'
+
+        describe "when the row count is > 0", ->
+          it "replaces the elements at the specified location", ->
+            editor.spliceLineElements 2, 2, elements
+
+            expect(editor.renderedLines.find('.line:eq(2)').text()).toBe 'A'
+            expect(editor.renderedLines.find('.line:eq(3)').text()).toBe 'B'
+            expect(editor.renderedLines.find('.line:eq(4)').text()).toBe '    while(items.length > 0) {'
+
+      describe "when the start row is the last row", ->
+        it "appends the elements to the end of the lines", ->
+          editor.spliceLineElements 13, 0, elements
+
+          expect(editor.renderedLines.find('.line:eq(12)').text()).toBe '};'
+          expect(editor.renderedLines.find('.line:eq(13)').text()).toBe 'A'
+          expect(editor.renderedLines.find('.line:eq(14)').text()).toBe 'B'
+          expect(editor.renderedLines.find('.line:eq(15)')).not.toExist()
+
   describe "gutter rendering", ->
     beforeEach ->
       editor.attachToDom(heightInLines: 5.5)

      expect(buffer.subscriptionCount()).toBe 1
      expect(otherBuffer.subscriptionCount()).toBe 1

  describe ".setBuffer(buffer)", ->
    otherBuffer = null


        editor.loadPreviousEditSession()
        expect(editor.activeEditSession).toBe session2

  describe ".save()", ->
    describe "when the current buffer has a path", ->
      tempFilePath = null

      beforeEach ->
        tempFilePath = '/tmp/atom-temp.txt'
        editor.setBuffer new Buffer(tempFilePath)
        expect(editor.buffer.getPath()).toBe tempFilePath

      afterEach ->
        expect(fs.remove(tempFilePath))

      it "saves the current buffer to disk", ->
        editor.buffer.setText 'Edited!'
        expect(fs.exists(tempFilePath)).toBeFalsy()

        editor.save()

        expect(fs.exists(tempFilePath)).toBeTruthy()
        expect(fs.read(tempFilePath)).toBe 'Edited!'

    describe "when the current buffer has no path", ->
      selectedFilePath = null
      beforeEach ->
        editor.setBuffer new Buffer()
        expect(editor.buffer.getPath()).toBeUndefined()
        editor.buffer.setText 'Save me to a new path'
        spyOn($native, 'saveDialog').andCallFake -> selectedFilePath

      it "presents a 'save as' dialog", ->
        editor.save()
        expect($native.saveDialog).toHaveBeenCalled()

      describe "when a path is chosen", ->
        it "saves the buffer to the chosen path", ->
          selectedFilePath = '/tmp/temp.txt'

          editor.save()

          expect(fs.exists(selectedFilePath)).toBeTruthy()
          expect(fs.read(selectedFilePath)).toBe 'Save me to a new path'

      describe "when dialog is cancelled", ->
        it "does not save the buffer", ->
          selectedFilePath = null
          editor.save()
          expect(fs.exists(selectedFilePath)).toBeFalsy()

  describe ".scrollTop(n)", ->
    beforeEach ->
      editor.attachToDom(heightInLines: 5)
