 
 describe "Snippets extension", ->
   [buffer, editorView, editor, snippets] = []
+
   beforeEach ->
+    atom.workspaceView = new WorkspaceView
+    atom.workspaceView.openSync('sample.js')
+    spyOn(Snippets, 'loadAll')
+
     waitsForPromise ->
       atom.packages.activatePackage('language-javascript')
 
+    waitsForPromise ->
+      atom.packages.activatePackage("snippets").then ({mainModule}) ->
+        snippets = mainModule
+
     runs ->
-      atom.workspaceView = new WorkspaceView
-      atom.workspaceView.openSync('sample.js')
-      packageWithSnippets = atom.packages.loadPackage(path.join(__dirname, 'fixtures', 'package-with-snippets'))
-      spyOn(Snippets, 'loadAll')
-
-    waitsForPromise ->
-      atom.packages.activatePackage("snippets")
-
-    runs ->
-      snippets = atom.packages.getActivePackage("snippets").mainModule
-
       editorView = atom.workspaceView.getActiveView()
       editor = atom.workspaceView.getActivePaneItem()
       buffer = editor.getBuffer()

    it "reloads the snippets", ->
      jasmine.unspy(window, "setTimeout")
      jasmine.unspy(snippets, 'loadAll')
      spyOn(atom.packages, 'getLoadedPackages').andReturn []
      configDirPath = temp.mkdirSync('atom-config-dir-')
      spyOn(atom, 'getConfigDirPath').andReturn configDirPath
      snippetsPath = path.join(configDirPath, 'snippets.cson')

      jasmine.unspy(snippets, 'loadAll')
      spyOn(atom.packages, 'getLoadedPackages').andReturn [packageWithSnippets, packageWithBrokenSnippets]
      spyOn(atom, 'getConfigDirPath').andReturn configDirPath

    afterEach ->
      # Unspy here so other afterEach blocks don't run with this spy active
      jasmine.unspy(atom.packages, 'getLoadedPackages')

    it "loads non-hidden snippet files from all atom packages with snippets directories, logging a warning if a file can't be parsed", ->
      spyOn(console, 'warn')
