<commit_before>describe('Backbone.Validator', function() {
  'use strict';

  var Validator = Backbone.Validator,
    fn, model, view, spy;

  var create = function(base, classOpts, instanceOpts) {
    var Model = base.extend(classOpts || {});
    return new Model(instanceOpts || {});
  };

  Validator.apply();

  describe('#validators', function() {
    var pp = function(value) {
      var str = jasmine.pp(value);
      return str.length > 100 ? str.substr(0, 100) + '...' : str;
    };

    var expectToFail = function(validatorName, value, expectation, errorMessage) {
      var validations = { attr: {} };
      validations.attr[validatorName] = expectation;

      it('fails with ' + pp(value) + ' and returns ' + pp(errorMessage), function() {
        expect(Validator.validate({attr: value}, validations).attr[0]).toBeDefined();
      });
    };

    var expectToPass = function(validatorName, value, expectation) {
      it('passes with ' + pp(value), function() {
        var validations = { attr: {} };
        validations.attr[validatorName] = expectation;
        expect(Validator.validate({attr: value}, validations)).toEqual(null);
      });
    };

    describe('add', function() {
      beforeEach(function() {
        spy = jasmine.createSpy('validator');
        Validator.addValidator('custom', spy);
      });

      it('passes expected value', function() {
        model = create(Backbone.Model, {
          validation: {
            field_1: {
              custom: 10<commit_msg>Add view specs<commit_after>describe('Backbone.Validator', function() {
  'use strict';

  var Validator = Backbone.Validator,
    fn, model, view, spy;

  var create = function(base, classOpts, instanceOpts) {
    var Model = base.extend(classOpts || {});
    return new Model(instanceOpts || {});
  };

  Validator.apply();

  describe('#validators', function() {
    var expectToFail = function(validatorName, value, expectation, errorMessage) {
      var validations = { attr: {} };
      validations.attr[validatorName] = expectation;

      it('fails with ' + jasmine.pp(value) + ' and returns ' + jasmine.pp(errorMessage), function() {
        expect(Validator.validate({attr: value}, validations).attr[0]).toBeDefined();
      });
    };

    var expectToPass = function(validatorName, value, expectation) {
      it('passes with ' + jasmine.pp(value), function() {
        var validations = { attr: {} };
        validations.attr[validatorName] = expectation;
        expect(Validator.validate({attr: value}, validations)).toEqual(null);
      });
    };

    describe('add', function() {
      beforeEach(function() {
        spy = jasmine.createSpy('validator');
        Validator.addValidator('custom', spy);
      });

      it('passes expected value', function() {
        model = create(Backbone.Model, {
          validation: {
            field_1: {
              custom: 10
{'fraction_non_alphanumeric': 0.1508457024508112, 'fraction_numerical': 0.0051777701070072485, 'mean_word_length': 2.959016393442623, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '102703', 'n_tokens_mistral': 844, 'n_tokens_neox': 825, 'n_words': 173}