   beforeEach ->
     atom.workspaceView = new WorkspaceView
     atom.workspace = atom.workspaceView.model
-    atom.workspaceView.openSync('sample.js')
-    atom.workspaceView.simulateDomAttachment()
-    StatusBar.activate()
-    editorView = atom.workspaceView.getActiveView()
-    editor = editorView.getEditor()
-    statusBar = atom.workspaceView.find('.status-bar').view()
-    buffer = editor.getBuffer()
+
+    waitsForPromise ->
+      atom.workspace.open('sample.js')
+
+    runs ->
+      atom.workspaceView.simulateDomAttachment()
+      StatusBar.activate()
+      editorView = atom.workspaceView.getActiveView()
+      editor = editorView.getEditor()
+      statusBar = atom.workspaceView.find('.status-bar').view()
+      buffer = editor.getBuffer()
 
   describe "@initialize", ->
     it "appends only one status bar", ->


    it "displays the current branch for files in repositories", ->
      atom.project.setPath(atom.project.resolve('git/master.git'))
      atom.workspaceView.openSync('HEAD')
      expect(StatusBar.git.branchArea).toBeVisible()
      expect(StatusBar.git.branchLabel.text()).toBe 'master'

      atom.workspaceView.getActivePaneView().destroyItems()
      expect(StatusBar.git.branchArea).toBeVisible()
      expect(StatusBar.git.branchLabel.text()).toBe 'master'

      view = $$ -> @div id: 'view', tabindex: -1, 'View'
      atom.workspaceView.getActivePaneView().showItem(view)
      expect(StatusBar.git.branchArea).not.toBeVisible()

    it "doesn't display the current branch for a file not in a repository", ->
      atom.project.setPath(os.tmpdir())
      atom.workspaceView.openSync(path.join(os.tmpdir(), 'temp.txt'))
      expect(StatusBar.git.branchArea).toBeHidden()

    it "doesn't display the current branch for a file outside the current project", ->
      atom.workspaceView.openSync(path.join(os.tmpdir(), 'atom-specs', 'not-in-project.txt'))
      expect(StatusBar.git.branchArea).toBeHidden()

  describe "git status label", ->
    [repo, filePath, originalPathText, newPath, ignorePath, ignoredPath, projectPath] = []

    it "displays the modified icon for a changed file", ->
      fs.writeFileSync(filePath, "i've changed for the worse")
      atom.project.getRepo().getPathStatus(filePath)

      waitsForPromise ->
        atom.workspace.open(filePath)

      runs ->
        expect(StatusBar.git.gitStatusIcon).toHaveClass('icon-diff-modified')

    it "doesn't display the modified icon for an unchanged file", ->
      waitsForPromise ->
        atom.workspace.open(filePath)

      runs ->
        expect(StatusBar.git.gitStatusIcon).toHaveText('')

    it "displays the new icon for a new file", ->
      waitsForPromise ->
        atom.workspace.open(newPath)

      runs ->
        expect(StatusBar.git.gitStatusIcon).toHaveClass('icon-diff-added')

    it "displays the ignored icon for an ignored file", ->
      waitsForPromise ->
        atom.workspace.open(ignoredPath)

      runs ->
        expect(StatusBar.git.gitStatusIcon).toHaveClass('icon-diff-ignored')

    it "updates when a status-changed event occurs", ->
      fs.writeFileSync(filePath, "i've changed for the worse")
      atom.project.getRepo().getPathStatus(filePath)

      waitsForPromise ->
        atom.workspace.open(filePath)

      runs ->
        expect(StatusBar.git.gitStatusIcon).toHaveClass('icon-diff-modified')
        fs.writeFileSync(filePath, originalPathText)
        atom.project.getRepo().getPathStatus(filePath)
        expect(StatusBar.git.gitStatusIcon).not.toHaveClass('icon-diff-modified')

    it "displays the diff stat for modified files", ->
      fs.writeFileSync(filePath, "i've changed for the worse")
      atom.project.getRepo().getPathStatus(filePath)

      waitsForPromise ->
        atom.workspace.open(filePath)

      runs ->
        expect(StatusBar.git.gitStatusIcon).toHaveText('+1')

    it "displays the diff stat for new files", ->
      waitsForPromise ->
        atom.workspace.open(newPath)

      runs ->
        expect(StatusBar.git.gitStatusIcon).toHaveText('+1')

    it "does not display for files not in the current project", ->
      waitsForPromise ->
        atom.workspace.open('/tmp/atom-specs/not-in-project.txt')

      runs ->
        expect(StatusBar.git.gitStatusIcon).toBeHidden()

  describe "when the active item view does not implement getCursorBufferPosition()", ->
    it "hides the cursor position view", ->
      atom.workspaceView.attachToDom()
      view = $$ -> @div id: 'view', tabindex: -1, 'View'
      editorView.getPane().activateItem(view)
      expect(StatusBar.cursorPosition).toBeHidden()

  describe "when the active item implements getTitle() but not getPath()", ->
