 
 describe 'apm command line interface', ->
   beforeEach ->
+    spyOn(console, 'log')
+    spyOn(console, 'error')
     spyOn(process.stdout, 'write')
     spyOn(process.stderr, 'write')
 
   describe 'when no arguments are present', ->
     it 'prints a usage message', ->
-      spyOn(console, 'log')
-      spyOn(console, 'error')
       apm.run([])
       expect(console.log).not.toHaveBeenCalled()
       expect(console.error).toHaveBeenCalled()

      atomHome = temp.mkdirSync('apm-home-dir-')
      process.env.ATOM_HOME = atomHome
      process.env.ATOM_NODE_URL = "http://localhost:3000/node"

      spyOn(console, 'log')
      spyOn(console, 'error')

    afterEach ->
      server.close()


  describe 'when the version flag is specified', ->
    it 'prints a usage message', ->
      apm.run(['-h'])
      expect(console.log).not.toHaveBeenCalled()
      expect(console.error).toHaveBeenCalled()
