         beforeEach ->
           editor.buffer.setText("it \"does something\", :meta => true")
           editor.setSelectedBufferRange([[0, 3],[0,19]])
-          editorView.trigger "bracket-matcher:remove-brackets-from-selection"
+          atom.commands.dispatch(editorElement, "bracket-matcher:remove-brackets-from-selection")
 
         it "removes the brackets", ->
           expect(editor.buffer.getText()).toBe "it does something, :meta => true"

    describe "when the cursor is on the right side of a starting pair, the ending pair on the same line", ->
      it "removes both pairs", ->
        editor.setCursorBufferPosition([11,14])
        editorView.trigger "bracket-matcher:remove-matching-brackets"
        expect(editor.lineForBufferRow(11)).toEqual('  return sortArray.apply(this, arguments);')
        expect(editor.getCursorBufferPosition()).toEqual([11,13])

    describe "when the cursor is on the right side of an ending pair, the starting pair on the same line", ->
      it "removes both pairs", ->
        editor.setCursorBufferPosition([11,43])
        editorView.trigger "bracket-matcher:remove-matching-brackets"
        expect(editor.lineForBufferRow(11)).toEqual('  return sortArray.apply(this, arguments);')
        expect(editor.getCursorBufferPosition()).toEqual([11,41])

    describe "when a starting pair is selected", ->
      it "removes both pairs", ->
        editor.setSelectedBufferRange([[11,13], [11,14]])
        editorView.trigger "bracket-matcher:remove-matching-brackets"
        expect(editor.lineForBufferRow(11)).toEqual('  return sortArray.apply(this, arguments);')
        expect(editor.getCursorBufferPosition()).toEqual([11,13])

    describe "when an ending pair is selected", ->
      it "removes both pairs", ->
        editor.setSelectedBufferRange([[11,42], [11,43]])
        editorView.trigger "bracket-matcher:remove-matching-brackets"
        expect(editor.lineForBufferRow(11)).toEqual('  return sortArray.apply(this, arguments);')
        expect(editor.getCursorBufferPosition()).toEqual([11,41])


      it "moves the cursor to after the ending pair", ->
        editor.moveToEndOfLine()
        editor.moveLeft()
        atom.commands.dispatch(editorElement, "bracket-matcher:go-to-matching-bracket")
        expect(editor.getCursorBufferPosition()).toEqual [12, 1]

    describe "when the cursor is after the starting pair", ->
      it "moves the cursor to before the ending pair", ->
        editor.moveToEndOfLine()
        atom.commands.dispatch(editorElement, "bracket-matcher:go-to-matching-bracket")
        expect(editor.getCursorBufferPosition()).toEqual [12, 0]

    describe "when the cursor is before the ending pair", ->
      it "moves the cursor to after the starting pair", ->
        editor.setCursorBufferPosition([12, 0])
        atom.commands.dispatch(editorElement, "bracket-matcher:go-to-matching-bracket")
        expect(editor.getCursorBufferPosition()).toEqual [0, 29]

    describe "when the cursor is after the ending pair", ->
      it "moves the cursor to before the starting pair", ->
        editor.setCursorBufferPosition([12, 1])
        atom.commands.dispatch(editorElement, "bracket-matcher:go-to-matching-bracket")
        expect(editor.getCursorBufferPosition()).toEqual [0, 28]

    describe "when the cursor is not adjacent to a pair", ->
      describe "when within a `{}` pair", ->
        it "moves the cursor to before the enclosing brace", ->
          editor.setCursorBufferPosition([11, 2])
          atom.commands.dispatch(editorElement, "bracket-matcher:go-to-matching-bracket")
          expect(editor.getCursorBufferPosition()).toEqual [0, 28]

      describe "when within a `()` pair", ->
        it "moves the cursor to before the enclosing brace", ->
          editor.setCursorBufferPosition([2, 14])
          atom.commands.dispatch(editorElement, "bracket-matcher:go-to-matching-bracket")
          expect(editor.getCursorBufferPosition()).toEqual [2, 7]

      describe 'in HTML/XML files', ->
