 
     describe 'activating agda-mode', ->
 
+        textEditor_ = null
+
         beforeEach ->
             atom.packages.deactivatePackage('agda-mode')
             atom.packages.activatePackage('agda-mode')

                .then (textEditor) ->
                    element = atom.views.getView(textEditor)
                    atom.commands.dispatch(element, 'agda-mode:load')
                    return atom.packages.activatePackage('agda-mode')
                .then ->
                    getActivePackageNames().should.contain 'agda-mode'
                    done()

        it 'should be activated after triggering "agda-mode:load" in .lagda files', (done) ->

                .then (textEditor) ->
                    element = atom.views.getView(textEditor)
                    atom.commands.dispatch(element, 'agda-mode:load')
                    textEditor_ = textEditor
                    return atom.packages.activatePackage('agda-mode')
                .then ->
                    getActivePackageNames().should.contain 'agda-mode'
                    textEditor_.core.should.be.defined
                    done()

        it 'should be activated after triggering "agda-mode:input-symbol" in .agda files', (done) ->
            openFile agdaFD
                .then (textEditor) ->
                    element = atom.views.getView(textEditor)
                    atom.commands.dispatch(element, 'agda-mode:input-symbol')
                    textEditor_ = textEditor
                    return atom.packages.activatePackage('agda-mode')
                .then ->
                    getActivePackageNames().should.contain 'agda-mode'
                    textEditor_.core.should.be.defined
                    done()

        it 'should be activated after triggering "agda-mode:input-symbol" in .lagda files', (done) ->
            openFile lagdaFD
                .then (textEditor) ->
                    element = atom.views.getView(textEditor)
                    atom.commands.dispatch(element, 'agda-mode:input-symbol')
                    textEditor_ = textEditor
                    return atom.packages.activatePackage('agda-mode')
                .then ->
                    getActivePackageNames().should.contain 'agda-mode'
                    textEditor_.core.should.be.defined
                    done()
