     jasmine.attachToDOM(getWorkspaceView())
 
   describe "when tags can be generated for a file", ->
+    beforeEach ->
+      waitsForPromise ->
+        atom.workspace.open('sample.js')
+
     it "initially displays all JavaScript functions with line numbers", ->
-      waitsForPromise ->
-        atom.workspace.open('sample.js')
-
       runs ->
         atom.commands.dispatch(getEditorView(), "symbols-view:toggle-file-symbols")
 

        expect(symbolsView.error).not.toBeVisible()

    it "caches tags until the editor changes", ->
      waitsForPromise ->
        atom.workspace.open('sample.js')

      runs ->
        editor = atom.workspace.getActiveTextEditor()
        atom.commands.dispatch(getEditorView(), "symbols-view:toggle-file-symbols")

        expect(symbolsView.list.children('li').length).toBe 2
        expect(symbolsView.error).not.toBeVisible()

    it "moves the cursor to the selected function", ->
      runs ->
        expect(atom.workspace.getActiveTextEditor().getCursorBufferPosition()).toEqual [0,0]
        expect($(getWorkspaceView()).find('.symbols-view')).not.toExist()
        atom.commands.dispatch(getEditorView(), "symbols-view:toggle-file-symbols")

      waitsFor ->
        $(getWorkspaceView()).find('.symbols-view').find('li').length

      runs ->
        $(getWorkspaceView()).find('.symbols-view').find('li:eq(1)').mousedown().mouseup()
        expect(atom.workspace.getActiveTextEditor().getCursorBufferPosition()).toEqual [1,2]

  describe "when tags can't be generated for a file", ->
    beforeEach ->
      waitsForPromise ->
        atom.workspace.open('sample.txt')

    it "shows an error message when no matching tags are found", ->
      runs ->
        atom.commands.dispatch(getEditorView(), "symbols-view:toggle-file-symbols")

