   describe 'with no error status code', ->
 
     before ->
-        send = sinon.spy()
-        status = sinon.stub().returns { send: send }
-
-        err = {}
-        req = {}
-        res = { status: status }
-        next = sinon.spy()
-        error err, req, res, next
+      send = sinon.spy()
+      status = sinon.stub().returns { send: send }
+
+      err = {}
+      req =
+        app:
+          get: ->
+            'production'
+        connectParams: {}
+      res = { status: status }
+      next = sinon.spy()
+      error err, req, res, next
 
     it 'should respond 500', ->
       res.status.should.have.been.calledWith 500

  describe 'with 400 status code', ->

    before ->
        err =
          error:              'error_code'
          error_description:  'description'
          statusCode:         400

        req = {}

        json = sinon.spy()
        status = sinon.stub().returns { json: json }


        res =
          status: status
          set: sinon.spy (headers) -> res.headers = headers
          render: sinon.spy()
          redirect: sinon.spy()
        res.status.json = sinon.spy()

        next = sinon.spy()

        error err, req, res, next

    it 'should respond 400', ->
      res.status.should.have.been.calledWith 400

  describe 'with 401 status code', ->

    before ->
      err =
        realm:              'realm'
        error:              'error_code'
        error_description:  'description'
        statusCode:         401

      req =
        app:
          get: ->
            'production'
        connectParams: {}

      send = sinon.spy()
      status = sinon.stub().returns { send: send }

      res =
        status: status
        set: sinon.spy (headers) -> res.headers = headers
        render: sinon.spy()
        redirect: sinon.spy()

      next = sinon.spy()

      error err, req, res, next

    it 'should respond 401', ->
      res.status.should.have.been.calledWith 401

    it 'should respond "Unauthorized"', ->
      send.should.have.been.calledWith 'Unauthorized<br><br>description'

    it 'should challenge to authenticate', ->
      res.headers['WWW-Authenticate'].should.be.defined
