(function(){

	"use strict";

	var ds = require('./datastore.js');


	/**
	 * Checks status code
	 * @param int expected A HTTP status code
	 */
	exports.httpStatusIs = function( expected ){

		return function( response, body ){
			expectedStatus = ds.getValue( expected );

			var code = parseInt(response.statusCode, 10),
				result = code  === expected;

			if ( ! result ){
				/*jshint validthis:true */
				this.debug = {expected: expected, actual: code, data: body};
			}

			return result;
		};
	};


	exports.isJSON = function( response, body ){
		try{
			return ( typeof JSON.parse( body ) == 'object' );
		} catch(e){
			this.debug = {body: body};
			return false;
		}
	};


	/**
	 * Checks a given `key path` value against an expectation
	 * @param String path String representation of how you would acces the property
	 *	eg: myobject.property.sub_property
	 * @param Mixed expected
	 */
	exports.JsonEqual = function( path, expected  ){
			
		return function( response, body ){
			expected = ds.getValue( expected );

			var oBody = JSON.parse(body);
			var actual = ds.getStorableVar(oBody, path);

			var result = ( actual === expected );

			if( ! result ){
				this.debug = {expected: expected, actual: actual, data: oBody};
			}

			return result;
		};
	};


	/**
	 * Checks a given `key path` value is NOT equal to an (un)expectation
	 * @param String path String representation of how you would acces the property
	 *	eg: myobject.property.sub_property
	 * @param Mixed unexpected
	 */
	exports.JsonNotEqual = function( path, unexpected ){
		return function( response, body ){
			unexpected = ds.getValue( unexpected );
		
			var oBody = JSON.parse(body);
			var actual = ds.getStorableVar(oBody, path);

			var result = ( actual !== unexpected );

			if( ! result ){
				this.debug = {unexpected: unexpected, actual: actual, data: oBody};
			}

			return result;
		};
	};

	/**
	 * Checks if response JSON contains the given key path
	 * (even if the value is null or false)
	 * @param String path
	 */
	exports.JsonHas = function( path  ){

		return function( response, body ){

			var oBody = JSON.parse(body);
			var result = ds.getStorableVar(oBody, path);

			if( result === undefined ){
				this.debug = {expected: path, found: ds.getStorableVar(oBody, path), data: oBody};
				return false;
			}

			return true;
		};
	};



	/**
	 * Checks if given path is of expected type
	 * @param String path
	 * @param String type String reprensentation of the type
	 * @TODO Rename this assertion ?
	 */
	exports.JsonType = function( path, expected  ){

		return function( response, body ){
			expected = ds.getValue( expected );

			var oBody = JSON.parse(body);
			var value = ds.getStorableVar(oBody, path);

			var actual = typeof(value);
			var result = ( actual === expected );

			if( ! result ){
				this.debug = {expected: expected, actual: actual, data: oBody};
			}

			return result;
		};
	};


	/**
	 * Checks array length...
	 * @param Int length
	 * @param String path
	 * @TODO : Parameters order doesn't match others assertions
	 * @TODO Rename this assertion ?
	 */
	exports.ArrayLength = function( length, path ){

		return function( response, body ){
			var length = ds.getValue( length );
			var value = JSON.parse(body);

			if ( path ) {
				value = ds.getStorableVar(value, path);
			}

			if (value.length === length ) {
				return true;
			} else {
				this.debug = {expected: length, actual: value.length, data: value};
				return false;
			}
		};
	};

	/**
	 * Checks if an array at path contains execpted value
	 * @param String path
	 * @param Mixed value
	 * @TODO Rename this assertion ?
	 */
	exports.JsonContains = function( path, value ){
		return function( response, body ){
			var data = JSON.parse(body);
			var value = ds.getValue( value );

			data = ds.getStorableVar(data, path);

			for ( var key in data ){
				if ( data[key] == value ){
					return true;
				}
			}

			this.debug = {expected: value, actual: null, data: data};
			return false;
		};
	};

	/**
	 * Checks if an array at path does NOT contain (un)execpted value
	 * @param String path
	 * @param Mixed value
	 * @TODO Rename this assertion ?
	 */
	exports.JsonNotContains = function( path, value ){
		return function( response, body ){
			var data = JSON.parse(body);
			var value = ds.getValue( value );
			
			data = ds.getStorableVar(data, path);

			for ( var key in data ){
				if ( data[key] == value ){
					this.debug = {expected: value, actual: value, data: data};
					return false;
				}
			}
			return true;
		};
	};

}());
@@ -233,22 +233,16 @@
 expected
-Status
  = ds.ge
@@ -3182,47 +3182,8 @@
  )%7B%0A
-%09%09%09var length = ds.getValue( length );%0A
 %09%09%09v

Fix 2 assertions