     return options
 
 describe('test the order of Mocha hooks', () ->
-    before( () ->
+    before( (done) ->
         console.log('Setting up server')
         # Connecting mongoose to our mongo database
 
-        mongoose.connect 'mongodb://127.0.0.1:27017/homeagain_test'
-
-        # Loading fixtures in test database
-        fixtures = require '../../fixtures'
-        fixtures.launchFixtures( () ->
-            console.log("Fixtures loaded")
-            require '../../express/index'
+        mongoose.connect('mongodb://127.0.0.1:27017/homeagain_test', (error) ->
+            # Loading fixtures in test database
+            fixtures = require '../../fixtures'
+            fixtures.launchFixtures( () ->
+                require '../../express/index'
+                done()
+            )
         )
 
     )
+
     it('should be listening at localhost:4000', (done) ->
         headers = defaultQueryOptions('/', 'GET')
         http.get(headers, (res) ->

          done()
        )
    )
    it('should authenticate a user', (done) ->
        qstring = JSON.stringify({
            username: 'test',
            password: 'test'
        })
        options = defaultQueryOptions('/login', 'POST')
        req = http.request(options)
        req.on('response', (res) ->
            res.on('data', (data) ->
                body = data.toString('utf8')
                console.log(body)
            )
            # body = JSON.parse(d.toString('utf8'))
            # console.log(body)

should = chai.should()

port = 4000
user_id = null
api_key = null

defaultQueryOptions = (path, method) ->
    options = {
