(function () {
    /*globals describe:false, it:false*/
    'use strict';

    var expect = require('chai').expect;

    var factory = require('../../lib/drivers/factory');
    var idriver = require('../../lib/utils/idriver');
    var DriverError = require('../../lib/utils/drivererror');

    describe('Driver factory', function () {
        describe('#existing-drivers', function () {
            [
                'redis:', 'memcached://', 'etcd:', 'etcds://', 'redis:///ß∞',
                ['redis://', 'redis://']
            ].forEach(function (urls) {

                it(urls, function () {
                    var u = urls;
                    if (urls instanceof Array) {
                        u = urls[0];
                    }
                    var t = u.match(/^([a-z]+)/).pop();
                    if (t !== 'redis') {
                        t = t.replace(/s$/, '');
                    }
                    var driverClass = require('../../lib/drivers/' + t);

                    var driverInstance = factory.getDriver(urls);
                    // Don't leak the drivers - so, destroy whenever they reach error or ready
                    driverInstance.once('error', driverInstance.destructor);
                    driverInstance.once('ready', driverInstance.destructor);

                    expect(driverInstance).to.be.an.instanceof(driverClass);
                    expect(driverInstance).to.be.an.instanceof(idriver);
                });
            });
        });

        describe('#erroring-on-bogus-urls', function () {
            it('"nopassaran://" (unregistered) should emit error', function (done) {
                factory.once('error', function (e) {
                    expect(e.name).to.eql('DriverError');
                    expect(e.category).to.eql(DriverError.MISSING_DRIVER);
                    done();
                });
                factory.getDriver('nopassaran://');
            });

            it('"bogus" (no scheme) should emit error', function (done) {
                factory.once('error', function (e) {
                    expect(e.name).to.eql('DriverError');
                    expect(e.category).to.eql(DriverError.BOGUS_URL);
                    done();
                });
                factory.getDriver('bogus');
            });

            it('drivertpl:// (which is broken) should emit error', function (done) {
                factory.once('error', function (e) {
                    expect(e.name).to.eql('DriverError');
                    expect(e.category).to.eql(DriverError.BROKEN_DRIVER);
                    done();
                });
                factory.getDriver('drivertpl://');
            });
        });

    });
})();

@@ -414,16 +414,17 @@
     
+%5B
 'redis:'
 , 'm
@@ -419,18 +419,20 @@
 'redis:'
+%5D
 , 
+%5B
 'memcach
@@ -441,19 +441,23 @@
 ://'
+%5D
 , 
+%5B
 'etcd:'
+%5D
 , 
+%5B
 'etc
@@ -458,26 +458,28 @@
  %5B'etcds://'
+%5D
 , 
+%5B
 'redis:///%C3%9F%E2%88%9E
@@ -479,16 +479,17 @@
 s:///%C3%9F%E2%88%9E'
+%5D
 ,%0A      
@@ -1722,39 +1722,43 @@
     expect(e
-.name).to.eql('
+).to.be.instanceof(
 DriverError'
@@ -1748,33 +1748,32 @@
 ceof(DriverError
-'
 );%0A             
@@ -1916,16 +1916,17 @@
 tDriver(
+%5B
 'nopassa
@@ -1928,24 +1928,25 @@
 passaran://'
+%5D
 );%0A         
@@ -2104,39 +2104,43 @@
     expect(e
-.name).to.eql('
+).to.be.instanceof(
 DriverError'
@@ -2130,33 +2130,32 @@
 ceof(DriverError
-'
 );%0A             
@@ -2297,15 +2297,17 @@
 ver(
+%5B
 'bogus'
+%5D
 );%0A 
@@ -2492,23 +2492,27 @@
 ct(e
-.name).to.eql('
+).to.be.instanceof(
 Driv
@@ -2518,17 +2518,16 @@
 verError
-'
 );%0A     
@@ -2677,16 +2677,17 @@
 tDriver(
+%5B
 'drivert
@@ -2692,16 +2692,17 @@
 rtpl://'
+%5D
 );%0A     

Fix factory tests now that array is the only supported argument