var BufferedStream = require('bufferedstream');
var createMockCouchAdapter = require('./createMockCouchAdapter');
var http = require('http');
var mockCouch = require('mock-couch-alexjeffburke');
var url = require('url');

function generateCouchdbResponse(databases, req, res) {
    var responseObject = null;

    var couchdbHandler = createMockCouchAdapter();
    var couchdb = new mockCouch.MockCouch(couchdbHandler, {});

    Object.keys(databases).forEach(function (databaseName) {
        couchdb.addDB(databaseName, databases[databaseName].docs || []);
    });

    // run the handler
    couchdbHandler(req, res, function () {});
}

module.exports = {
    name: 'unexpected-couchdb',
    installInto: function (expect) {
        expect.installPlugin(require('unexpected-mitm'));

        expect.addAssertion('<any> with couchdb mocked out <object> <assertion>', function (expect, subject, couchdb) {
            expect.errorMode = 'nested';

            var nextAssertionArgs = this.args.slice(1);
            var args = [subject, 'with http mocked out', {
                response: generateCouchdbResponse.bind(null, couchdb)
            }].concat(nextAssertionArgs);

            return expect.apply(expect, args);
        });

    }
};

var BufferedStream = require('bufferedstream');
var createMockCouchAdapter = require('./createMockCouchAdapter');
var http = require('http');
var mockCouch = require('mock-couch-alexjeffburke');
var url = require('url');

function generateCouchdbResponse(databases, req, res) {
    var responseObject = null;

    var couchdbHandler = createMockCouchAdapter();
    var couchdb = new mockCouch.MockCouch(couchdbHandler, {});

    Object.keys(databases).forEach(function (databaseName) {
        couchdb.addDB(databaseName, databases[databaseName].docs || []);
    });

    // run the handler
    couchdbHandler(req, res, function () {});
}

module.exports = {
    name: 'unexpected-couchdb',
    installInto: function (expect) {
        expect.installPlugin(require('unexpected-mitm'));

        expect.addAssertion('with couchdb mocked out', function (expect, subject, couchdb) {
            this.errorMode = 'nested';

            var nextAssertionArgs = this.args.slice(1);
            var args = [subject, 'with http mocked out', {
                response: generateCouchdbResponse.bind(null, couchdb)
            }].concat(nextAssertionArgs);

            return expect.apply(expect, args);
        });
        
    }
};
--- 
+++ 
@@ -23,8 +23,8 @@
     installInto: function (expect) {
         expect.installPlugin(require('unexpected-mitm'));
 
-        expect.addAssertion('with couchdb mocked out', function (expect, subject, couchdb) {
-            this.errorMode = 'nested';
+        expect.addAssertion('<any> with couchdb mocked out <object> <assertion>', function (expect, subject, couchdb) {
+            expect.errorMode = 'nested';
 
             var nextAssertionArgs = this.args.slice(1);
             var args = [subject, 'with http mocked out', {
@@ -33,6 +33,6 @@
 
             return expect.apply(expect, args);
         });
-        
+
     }
 };
Use the Unexpected v10 addAssertion syntax.
