 describe 'ColorBuffer', ->
   [editor, colorBuffer, pigments, project] = []
 
-  editBuffer = (text, options) ->
+  editBuffer = (text, options={}) ->
 
     if options.start?
       if options.end?

            expect(colorsUpdateSpy.argsForCall[0][0].destroyed.length).toEqual(2)
            expect(colorsUpdateSpy.argsForCall[0][0].created.length).toEqual(2)

    describe 'with a buffer with only colors', ->
      beforeEach ->
        waitsForPromise ->

        it 'removes the previous editor markers', ->
          expect(editor.findMarkers(type: 'pigments-color').length).toEqual(3)

      describe 'when a new color is added', ->
        [colorsUpdateSpy] = []

        beforeEach ->
          waitsForPromise -> colorBuffer.variablesAvailable()

          runs ->
            colorsUpdateSpy = jasmine.createSpy('did-update-color-markers')
            colorBuffer.onDidUpdateColorMarkers(colorsUpdateSpy)
            editor.moveToBottom()
            editBuffer '\n#336699'
            waitsFor -> colorsUpdateSpy.callCount > 0

        it 'adds a marker for the new color', ->
          markers = colorBuffer.getColorMarkers()
          marker = markers[markers.length-1]
          expect(markers.length).toEqual(4)
          expect(marker.color).toBeColor('#336699')
          expect(editor.findMarkers(type: 'pigments-color').length).toEqual(4)

        it 'dispatches the new marker in a did-update-color-markers event', ->
          expect(colorsUpdateSpy.argsForCall[0][0].destroyed.length).toEqual(0)
          expect(colorsUpdateSpy.argsForCall[0][0].created.length).toEqual(1)

  describe 'when the editor is destroyed', ->
    it 'destroys the color buffer at the same time', ->
      editor.destroy()
