Sha256: 33370150af26de05766b05db24c0032334547f953d68c409f183015bbc6b5a3e

Contents?: true

Size: 1.2 KB

Versions: 28

Compression:

Stored size: 1.2 KB

Contents

/**
 * Module dependencies.
 */

var Suite = require('../suite')
  , Test = require('../test');

/**
 * TDD-style interface:
 *
 *     exports.Array = {
 *       '#indexOf()': {
 *         'should return -1 when the value is not present': function(){
 *
 *         },
 *
 *         'should return the correct index when the value is present': function(){
 *
 *         }
 *       }
 *     };
 *
 */

module.exports = function(suite){
  var suites = [suite];

  suite.on('require', visit);

  function visit(obj) {
    var suite;
    for (var key in obj) {
      if ('function' == typeof obj[key]) {
        var fn = obj[key];
        switch (key) {
          case 'before':
            suites[0].beforeAll(fn);
            break;
          case 'after':
            suites[0].afterAll(fn);
            break;
          case 'beforeEach':
            suites[0].beforeEach(fn);
            break;
          case 'afterEach':
            suites[0].afterEach(fn);
            break;
          default:
            suites[0].addTest(new Test(key, fn));
        }
      } else {
        var suite = Suite.create(suites[0], key);
        suites.unshift(suite);
        visit(obj[key]);
        suites.shift();
      }
    }
  }
};

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
stylus-source-0.42.2 vendor/node_modules/mocha/lib/interfaces/exports.js
stylus-source-0.42.1 vendor/node_modules/mocha/lib/interfaces/exports.js
stylus-source-0.42.0 vendor/node_modules/mocha/lib/interfaces/exports.js
stylus-source-0.41.3 vendor/node_modules/mocha/lib/interfaces/exports.js
stylus-source-0.41.2 vendor/node_modules/mocha/lib/interfaces/exports.js
stylus-source-0.41.1 vendor/node_modules/mocha/lib/interfaces/exports.js
stylus-source-0.41.0 vendor/node_modules/mocha/lib/interfaces/exports.js
stylus-source-0.40.3 vendor/node_modules/mocha/lib/interfaces/exports.js
stylus-source-0.40.2 vendor/node_modules/mocha/lib/interfaces/exports.js
stylus-source-0.40.1 vendor/node_modules/mocha/lib/interfaces/exports.js
stylus-source-0.40.0 vendor/node_modules/mocha/lib/interfaces/exports.js
stylus-source-0.39.4 vendor/node_modules/mocha/lib/interfaces/exports.js
stylus-source-0.39.3 vendor/node_modules/mocha/lib/interfaces/exports.js
stylus-source-0.39.2 vendor/node_modules/mocha/lib/interfaces/exports.js
stylus-source-0.39.1 vendor/node_modules/mocha/lib/interfaces/exports.js
stylus-source-0.39.0 vendor/node_modules/mocha/lib/interfaces/exports.js
stylus-source-0.38.0 vendor/node_modules/mocha/lib/interfaces/exports.js
stylus-source-0.37.0 vendor/node_modules/mocha/lib/interfaces/exports.js
stylus-source-0.36.1 vendor/node_modules/mocha/lib/interfaces/exports.js
stylus-source-0.36.0 vendor/node_modules/mocha/lib/interfaces/exports.js