<commit_before>var proxyquire = require('proxyquire').noCallThru(),
  stub = require('sinon').stub,
  spy = require('sinon').spy;

describe('CacheClient', function () {
  var noop, CacheClient, util, unit, deco, c;

  beforeEach(function () {
    var redis;
    function noop() {}

    deco = {};
    util = {
      createRedisClient: stub(),
      createNamespace: stub(),
      ensureKeyspaceNotifications: stub()
    };

    CacheClient = proxyquire('../lib/CacheClient', {
      './Cache': function () {},
      './util': util,
      'require-directory': function () {
        return deco;
      }
    });

    deco.OnlySetChangedDecorator = spy();
    deco.MarshallDecorator = spy();
  });

  it('should create a preconfigured client', function () {
    unit = new CacheClient({isPreconfigured: true});
    util.ensureKeyspaceNotifications.called.should.not.be.ok;
  });

  describe('create', function () {
    beforeEach(function () {
      unit = new CacheClient();
    });

    it('should create default cache', function () {
      c = unit.create('n');
      c.should.be.type('object');
      deco.OnlySetChangedDecorator.calledOnce.should.be.ok;
    });

    it('should create a small-value optimized cache', function () {
      c = unit.create('n', {optimizeForSmallValues: true});
      c.should.be.type('object');
    });

    it('should use the expire deco on expiresIn', function () {
      deco.ExpiresDecorator = spy();

      c = unit.create('n', {expiresIn: 200});
      c.should.be.type('object');

      deco.OnlySetChangedDecorator.calledOnce.should.be.ok;
      deco.ExpiresDecorator.calledOnce.should.be.ok;
    });

    it('should use the expire deco on staleIn', function () {
      deco.ExpiresDecorator = spy();

      c = unit.create('n', {staleIn: 200});
      c.should.be.type('object');

      deco.OnlySetChangedDecorator.calledOnce.should.be.ok;
      deco.ExpiresDecorator.calledOnce.should.be.ok;
    });

    it('should use the populate deco on populate', function () {
      deco.PopulateDecorator = spy();

      c = unit.create('n', {populate: function () {}});
      c.should.be.type('object');

      deco.OnlySetChangedDecorator.calledOnce.should.be.ok;
      deco.PopulateDecorator.calledOnce.should.be.ok;
    });

    it('should use the populateIn deco on populateIn & populate', function () {
      deco.PopulateDecorator = spy();
      deco.PopulateInDecorator = spy();

      c = unit.create('n', {populateIn: 200, populate: function () {}});
      c.should.be.type('object');

      deco.OnlySetChangedDecorator.calledOnce.should.be.ok;
      deco.PopulateDecorator.calledOnce.should.be.ok;
      deco.PopulateInDecorator.calledOnce.should.be.ok;
    });

    it('should not use populateIn without populate', function () {
      deco.PopulateInDecorator = spy();

      c = unit.create('n', {populateIn: 200});
      c.should.be.type('object');

      deco.OnlySetChangedDecorator.calledOnce.should.be.ok;
      deco.PopulateInDecorator.calledOnce.should.not.be.ok;
    });
  });
});<commit_msg>test/CacheClient: refactor decorator proto handling<commit_after>var proxyquire = require('proxyquire').noCallThru(),
  spy = require('sinon').spy;

describe('CacheClient', function () {
  var noop, CacheClient, util, unit, deco, c;

  beforeEach(function () {
    var redis;
    function noop() {}

    function Cache() {}
    Cache.prototype = {};

    util = {
      createRedisClient: spy(),
      createNamespace: spy(),
      ensureKeyspaceNotifications: spy()
    };

    deco = {};
    deco.OnlySetChangedDecorator = spy(Cache);
    deco.MarshallDecorator = spy(Cache);
    deco.ExpiresDecorator = spy(Cache);
    deco.PopulateDecorator = spy(Cache);
    deco.PopulateInDecorator = spy(Cache);

    CacheClient = proxyquire('../lib/CacheClient', {
      './Cache': Cache,
      './util': util,
      'require-directory': function () {
        return deco;
      }
    });
  });

  it('should create a preconfigured client', function () {
    unit = new CacheClient({isPreconfigured: true});
    util.ensureKeyspaceNotifications.called.should.not.be.ok;
  });

  describe('create', function () {
    beforeEach(function () {
      unit = new CacheClient();
    });

    it('should create default cache', function () {
      c = unit.create('n');
      c.should.be.type('object');
      deco.OnlySetChangedDecorator.calledOnce.should.be.ok;
    });

    it('should create a small-value optimized cache', function () {
      c = unit.create('n', {optimizeForSmallValues: true});
      c.should.be.type('object');
    });

    it('should use the expire deco on expiresIn', function () {
      c = unit.create('n', {expiresIn: 200});
      c.should.be.type('object');

      deco.OnlySetChangedDecorator.calledOnce.should.be.ok;
      deco.ExpiresDecorator.calledOnce.should.be.ok;
    });

    it('should use the expire deco on staleIn', function () {
      c = unit.create('n', {staleIn: 200});
      c.should.be.type('object');

      deco.OnlySetChangedDecorator.calledOnce.should.be.ok;
      deco.ExpiresDecorator.calledOnce.should.be.ok;
    });

    it('should use the populate deco on populate', function () {
      c = unit.create('n', {populate: function () {}});
      c.should.be.type('object');

      deco.OnlySetChangedDecorator.calledOnce.should.be.ok;
      deco.PopulateDecorator.calledOnce.should.be.ok;
    });

    it('should use the populateIn deco on populateIn & populate', function () {
      c = unit.create('n', {populateIn: 200, populate: function () {}});
      c.should.be.type('object');

      deco.OnlySetChangedDecorator.calledOnce.should.be.ok;
      deco.PopulateDecorator.calledOnce.should.be.ok;
      deco.PopulateInDecorator.calledOnce.should.be.ok;
    });

    it('should not use populateIn without populate', function () {
      c = unit.create('n', {populateIn: 200});
      c.should.be.type('object');

      deco.OnlySetChangedDecorator.calledOnce.should.be.ok;
      deco.PopulateInDecorator.calledOnce.should.not.be.ok;
    });
  });
});
{'fraction_non_alphanumeric': 0.15661252900232017, 'fraction_numerical': 0.003977461054027179, 'mean_word_length': 3.0476190476190474, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1275218', 'n_tokens_mistral': 2022, 'n_tokens_neox': 1923, 'n_words': 341}