<commit_before>/**
 * Module dependencies
 */
var Sails = require('../../lib/app');
var util = require('sails-util');

/**
 * Manage an instance of Sails
 * 
 * @type {Object}
 */
var helper = {

	/**
	 * Set up before() and after() mocha hooks.
	 * 
	 * @param  {Object} options [for Sails load]
	 */
	bindLifecycle: function (options) {
		before(helper.new(options));
		after(helper.teardown(options));
	},
	
	new: function (options) {
		return function (done) {
			var self = this;
			self.sails = new Sails();
			self.sails.load(options, function (err) {
				done(err, self.sails);
			});
		};
	},

	teardown: function () {
		return function (done) {
			this.sails.lower(done);
		};
	},

	/**
	 * Send a mock request to the instance of Sails
	 * in the test context.
	 *
	 * @param {String} url		[relative URL]
	 * @param {Object} options
	 */
	request: function ( url, options ) {
		return function (done) {
			this.sails.emit('router:request', _req(), _res(), function (err, response) {
				console.log('YAAAAAAAOW CALLBACK');
				if (err) return done(err);
				this.response = response;
				done();
			});
		};
	}
};

module.exports = helper;



/**
 * Ensure that request object has a minimum set of reasonable defaults.
 * Used primarily as a test fixture.
 *
 * @api private
 */

function _req ( req ) {
	return util.defaults(req || {}, {
		params: {},
		url: '/',
		param: function(paramName) {
			return req.params[paramName];
		},
		wantsJSON: true,
		method: 'get'
	});
}


/**
 * Ensure that response object has a minimum set of reasonable defaults
 * Used primarily as a test fixture.
 *
 * @api private
 */

function _res (res) {
	return util.defaults(res || {}, {
		send: function(body, statusCode) {
			res._cb(null, body, statusCode);
		},
		json: function(body, statusCode) {
			
			// Tolerate bad JSON
			var json = util.stringify(body);
			if ( !json ) {
				var failedStringify = new Error(
					'Failed to stringify specified JSON response body :: ' + body
				);
				return res.send(failedStringify.stack, 500);
			}

			return res.send(json,statusCode);
		}
	});
}

<commit_msg>First pass at style for router tests works<commit_after>/**
 * Module dependencies
 */
var Sails = require('../../lib/app');
var util = require('sails-util');

/**
 * Manage an instance of Sails
 * 
 * @type {Object}
 */
var helper = {

	/**
	 * Set up before() and after() mocha hooks.
	 * 
	 * @param  {Object} options [for Sails load]
	 */
	bindLifecycle: function (options) {
		before(helper.new(options));
		after(helper.teardown(options));
	},
	
	new: function (options) {
		return function (done) {
			var self = this;
			self.sails = new Sails();
			self.sails.load(options, function (err) {
				done(err, self.sails);
			});
		};
	},

	teardown: function () {
		return function (done) {
			this.sails.lower(done);
		};
	},


	/**
	 * Send a mock request to the instance of Sails
	 * in the test context.
	 *
	 * @param {String} url		[relative URL]
	 * @param {Object} options
	 */
	request: function ( url, options ) {
		return function (done) {

			var _fakeClient = function (err, response) {
				if (err) return done(err);
				this.response = response;
				done();
			};

			this.sails.emit('router:request', _req(), _res(), _fakeClient);
		};
	}
};

module.exports = helper;



/**
 * Ensure that request object has a minimum set of reasonable defaults.
 * Used primarily as a test fixture.
 *
 * @api private
 */

function _req ( req ) {
	return util.defaults(req || {}, {
		params: {},
		url: '/',
		param: function(paramName) {
			return req.params[paramName];
		},
		wantsJSON: true,
		method: 'get'
	});
}


/**
 * Test fixture to send requests and receive responses from Sails.
 *
 * @api private
 */

function _res (res) {

	var _enhancedRes = util.defaults(res || {}, {
		send: function(body, statusCode) {
			_enhancedRes._cb(null, {
				body: body,
				headers: {},
				status: statusCode || 200
			});
		},
		json: function(body, statusCode) {
			
			// Tolerate bad JSON
			var json = util.stringify(body);
			if ( !json ) {
				var failedStringify = new Error(
					'Failed to stringify specified JSON response body :: ' + body
				);
				return _enhancedRes.send(failedStringify.stack, 500);
			}

			return _enhancedRes.send(json,statusCode);
		}
	});

	return _enhancedRes;
}


{'fraction_non_alphanumeric': 0.15329313543599257, 'fraction_numerical': 0.0020871985157699443, 'mean_word_length': 2.964154411764706, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, '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': '6502734', 'n_tokens_mistral': 1639, 'n_tokens_neox': 1410, 'n_words': 400}