 Verifier = require '../src/verifier'
 
 describe 'Verifier', ->
+  beforeEach (done) ->
+    @meshblu = shmock done
+
   beforeEach ->
-    @meshblu = shmock 0xd00d
+    meshbluConfig = server: 'localhost', port: @meshblu.address().port
+    @sut = new Verifier {meshbluConfig}
 
   afterEach (done) ->
-    @meshblu.close => done()
+    @meshblu.close done
 
   describe '-> verify', ->
     context 'when everything works', ->
-      beforeEach ->
-        meshbluConfig = server: 'localhost', port: 0xd00d
-        @sut = new Verifier {meshbluConfig}
-
       beforeEach (done) ->
         @registerHandler = @meshblu.post('/devices')
           .send(type: 'meshblu:verifier')

        expect(@whoamiHandler.isDone).to.be.true

    context 'when unregister fails', ->
      beforeEach ->
        meshbluConfig = server: 'localhost', port: 0xd00d
        @sut = new Verifier {meshbluConfig}

      beforeEach (done) ->
        @registerHandler = @meshblu.post('/devices')
          .send(type: 'meshblu:verifier')

        expect(@registerHandler.isDone).to.be.true

    context 'when whoami fails', ->
      beforeEach (done) ->
        @registerHandler = @meshblu.post('/devices')
          .send(type: 'meshblu:verifier')
