Beispiel #1
0
var spec = require('izan-spec');

spec.Describe('lib/ClientEnvelope', function (Module) {

    var Client;
    beforeEach(function () {
        Client = jasmine.createSpy();
    });

    it ('should create envelope with client', function () {
        var envelope = new Module.ClientEnvelope(Client, 3);
        expect(envelope.client).toBe(Client);
    });

    it ('should create envelope with index', function () {
        var envelope = new Module.ClientEnvelope(Client, 3);
        expect(envelope.index).toBe(3);
    });
});
Beispiel #2
0
spec.Describe('lib/GenericPool', function (Module) {

    describe('interface', function () {
        var Methods = ['acquire', 'release'];
        var Pool = new Module.GenericPool();

        Methods.forEach(function (method) {
            it ('should have '+method+' defined', function () {
                expect(Pool[method]).toBeDefined();
                expect(Pool[method]).not.toBeNull();
            });
        });
    });

    var ClientFactory, genericPool;
    beforeEach(function () {
        ClientFactory = jasmine.createSpyObj('ClientFactoryStub', [
            'create', 'destroy'
            ]);

        genericPool = new Module.GenericPool(ClientFactory, {});
    });

    describe('acquire', function () {
        it ('should return envelope with client created by clientFactory', function () {
            // given
            var client = jasmine.createSpy();

            ClientFactory.create.andCallFake(function (cb) {
                return cb(null, client);
            });

            // when
            var retClient;
            spec.Run(function (spy) {
                genericPool.acquire(function (err, res) {
                    retClient = res;
                    spy(null, res);
                });
            }).thenExpect(function (spy) {
                expect(retClient.client).toBe(client);
            });


        });

        it ('should return error on fatal', function () {
            // given
            var client = jasmine.createSpy();
            var err = new Error();
            ClientFactory.create.andCallFake(function (cb) {
                return cb(err);
            });

            // when
            spec.Run(function (spy) {
                genericPool.acquire(spy)
            }).thenExpect(function (spy) {
                expect(spy).toHaveBeenCalledWith(err);
            });


        });
    });

});