       packageName = "CamelCaseIsForTheBirds"
       packagePath = path.join(path.dirname(packagePath), packageName)
       atom.workspaceView.trigger("package-generator:generate-package")
-      packageGeneratorView = atom.workspaceView.find(".package-generator").view()
-      packageGeneratorView.miniEditor.setText(packagePath)
-      apmExecute = spyOn(packageGeneratorView, 'runCommand')
-      packageGeneratorView.trigger "core:confirm"
-
-      expect(apmExecute).toHaveBeenCalled()
-      expect(apmExecute.mostRecentCall.args[0]).toBe atom.packages.getApmPath()
-      expect(apmExecute.mostRecentCall.args[1]).toEqual ['init', '--package', "#{path.join(path.dirname(packagePath), "camel-case-is-for-the-birds")}"]
+
+      waitsForPromise ->
+        activationPromise
+
+      runs ->
+        packageGeneratorView = atom.workspaceView.find(".package-generator").view()
+        packageGeneratorView.miniEditor.setText(packagePath)
+        apmExecute = spyOn(packageGeneratorView, 'runCommand')
+        packageGeneratorView.trigger "core:confirm"
+
+        expect(apmExecute).toHaveBeenCalled()
+        expect(apmExecute.mostRecentCall.args[0]).toBe atom.packages.getApmPath()
+        expect(apmExecute.mostRecentCall.args[1]).toEqual ['init', '--package', "#{path.join(path.dirname(packagePath), "camel-case-is-for-the-birds")}"]
 
     describe 'when creating a package', ->
-      beforeEach -> atom.workspaceView.trigger("package-generator:generate-package")
+      beforeEach ->
+        atom.workspaceView.trigger("package-generator:generate-package")
+
+        waitsForPromise ->
+          activationPromise
 
       describe "when the package is created outside of the packages directory", ->
         it "calls `apm init` and `apm link`", ->

            expect(enablePackage.mostRecentCall.args[0]).toBe packageName

    describe 'when creating a theme', ->
      beforeEach -> atom.workspaceView.trigger("package-generator:generate-syntax-theme")

      describe "when the theme is created outside of the packages directory", ->
        it "calls `apm init` and `apm link`", ->

{fs, WorkspaceView} = require 'atom'

describe 'Package Generator', ->
  [activationPromise] = []

  beforeEach ->
    atom.workspaceView = new WorkspaceView
    atom.workspaceView.openSync('sample.js')
    activationPromise = atom.packages.activatePackage("package-generator")

  describe "when package-generator:generate-package is triggered", ->
    it "displays a miniEditor", ->
      atom.workspaceView.trigger("package-generator:generate-package")

      waitsForPromise ->
        activationPromise

      runs ->
        packageGeneratorView = atom.workspaceView.find(".package-generator")
        expect(packageGeneratorView).toExist()

  describe "when core:cancel is triggered", ->
    it "detaches from the DOM and focuses the the previously focused element", ->
      atom.workspaceView.attachToDom()
      atom.workspaceView.trigger("package-generator:generate-package")

      waitsForPromise ->
        activationPromise

      runs ->
        packageGeneratorView = atom.workspaceView.find(".package-generator").view()
        expect(packageGeneratorView.miniEditor.isFocused).toBeTruthy()
        expect(atom.workspaceView.getActiveView().isFocused).toBeFalsy()

        packageGeneratorView.trigger("core:cancel")
        expect(packageGeneratorView.hasParent()).toBeFalsy()
        expect(atom.workspaceView.getActiveView().isFocused).toBeTruthy()

  describe "when a package is generated", ->
    [packageName, packagePath, packageRoot] = []
