<commit_before>mocha-mongoose
==============

test helpers for using mongoose with mocha

## Installation

    $ npm install mocha-mongoose

## Example:

    require('mocha-mongoose');
    var mongoose = require('mongoose');
    var should = require('should');

    var Dummy = mongoose.model('Dummy', new mongoose.Schema({a:Number}));

    describe("before hook", function() {
      var id;

      it("auto-connects to the DB if necessary", function(done) {
        should.exist(mongoose.connection.db);

        var dummy = new Dummy({a: 1})
        dummy.save(function(err){
          if (err) return done(err);

          should.exist(dummy.id);

          Dummy.findById(dummy.id, function(err, doc){
            if (err) return done(err);
            should.exist(doc);
            done();
          });
        });
      });

      it("empties the DB between specs", function(done) {
        Dummy.find({}, function(err, docs){
          if (err) return done(err);
          docs.length.should.equal(0);
          done();
        });
      });
    });<commit_msg>Update docs with new usage.<commit_after>mocha-mongoose
==============

test helpers for using mongoose with mocha

## Installation

    $ npm install mocha-mongoose

## Example:

    var dbURI    = 'mongodb://localhost/mongodb-wiper'
      , cleaner  = require('mocha-mongoose')
      , should   = require('should')
      , mongoose = require('mongoose')
      , Dummy    = mongoose.model('Dummy', new mongoose.Schema({a:Number}))
    ;

    describe("mongodb cleaner", function() {
      describe("as a beforeEach handler", function() {
        beforeEach(function(done) {
          if (mongoose.connection.db) return done();
          mongoose.connect(dbURI, function(err){
            if (err) done(err);
            done();
          });
        });

        beforeEach(function(done) {
          cleaner(dbURI)(done);
        });

        it("allows normal db use", function(done) {
          new Dummy({a: 1}).save(function(err){
            if (err) return done(err);
            done();
          });
        });

        it("empties the db between specs", function(done) {
          Dummy.find({}, function(err, docs){
            if (err) return done(err);
            docs.length.should.equal(0);
            done();
          });
        });
      });

      describe("when called with a callback instead of a url", function() {
        it("throws an error", function(done) {
          var err;
          try {
            cleaner(done)
          } catch(e) {
            err = e;
          } finally {
            should.exist(err);
            err.message.should.match(/being called to clean/);
            err.message.should.match(/with a mongodb url/);
            done();
          }
        });
      });
    });
{'fraction_non_alphanumeric': 0.15066047840057123, 'fraction_numerical': 0.0014280614066404856, 'mean_word_length': 1.9036269430051813, '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': '3121126', 'n_tokens_mistral': 827, 'n_tokens_neox': 805, 'n_words': 184}