Permalink
Browse files

Completed the ExpectThat.Mocha NuGet package.

  • Loading branch information...
1 parent d9bd9ba commit 3508ee3763700348577291e7d91abbe23faa7437 @dmohl committed Jan 16, 2012
@@ -0,0 +1,230 @@
+var expectThatApi, root;
+root = typeof exports !== "undefined" && exports !== null ? exports : window;
+expectThatApi = (function(expectThatApi) {
+ return {
+ version: "0.2.2.2",
+ init: function(assertProvider) {
+ var _this;
+ _this = this;
+ Object.prototype.should = function(expected) {
+ return _this.evaluateAssertion(assertProvider, true, this, expected);
+ };
+ Object.prototype.shouldnt = function(expected) {
+ return _this.evaluateAssertion(assertProvider, false, this, expected);
+ };
+ return this;
+ },
+ executeThrowAssertion: function(assertionToEvaluate, expected, customAssertion) {
+ if (typeof customAssertion.expected !== "undefined") {
+ return assertionToEvaluate.throwsException(expected);
+ } else {
+ return assertionToEvaluate.throwsException();
+ }
+ },
+ executeEqualToAssertion: function(isShould, assertionToEvaluate, expected) {
+ if (isShould) {
+ return assertionToEvaluate.isEqualTo(expected);
+ } else {
+ return assertionToEvaluate.isNotEqualTo(expected);
+ }
+ },
+ executeBooleanAssertion: function(isShould, actual, expected, customAssertion, assertProvider) {
+ var assertionToEvaluate;
+ if (typeof customAssertion.expr !== "function") {
+ throw "The provided custom assertion expression for " + customAssertion.assertionType + " is invalid.\nCustom assertion expressions should be defined as:\n(actual, expected) -> <some function using actual and expression>.";
+ }
+ assertionToEvaluate = assertProvider.assert(customAssertion.expr(actual, expected));
+ if (isShould) {
+ return assertionToEvaluate.isTrue();
+ } else {
+ return assertionToEvaluate.isFalse();
+ }
+ },
+ executeAssertion: function(assertionToEvaluate, isShould, assertionType, actual, expected, customAssertion, assertProvider) {
+ if (assertionToEvaluate === null || typeof assertionToEvaluate === "undefined") {
+ return;
+ }
+ if (typeof assertionType !== "undefined") {
+ if (assertionType === "throw") {
+ return this.executeThrowAssertion(assertionToEvaluate, expected, customAssertion);
+ } else {
+ return this.executeBooleanAssertion(isShould, actual, expected, customAssertion, assertProvider);
+ }
+ } else {
+ return this.executeEqualToAssertion(isShould, assertionToEvaluate, expected);
+ }
+ },
+ evaluateAssertion: function(assertProvider, isShould, actual, expectedValueProvider) {
+ var assertionToEvaluate, assertionType, customAssertion, expected;
+ expected = expectedValueProvider;
+ customAssertion = expectedValueProvider;
+ if (typeof expectedValueProvider === "function") {
+ customAssertion = expectedValueProvider();
+ }
+ if (typeof customAssertion !== "undefined" && customAssertion !== null) {
+ assertionType = customAssertion.assertionType;
+ if (typeof customAssertion.expected !== "undefined") {
+ expected = customAssertion.expected;
+ }
+ }
+ assertionToEvaluate = assertProvider.assert(actual);
+ return this.executeAssertion(assertionToEvaluate, isShould, assertionType, actual, expected, customAssertion, assertProvider);
+ }
+ };
+})(expectThatApi || (expectThatApi = {}));
+(function(expectThatApi) {
+ expectThatApi.util = {
+ extend: function(destination, source) {
+ var name;
+ for (name in source) {
+ if (source.hasOwnProperty(name) && destination) {
+ destination[name] = source[name];
+ }
+ }
+ return destination;
+ }
+ };
+ return this;
+})(expectThatApi || (expectThatApi = {}));
+(function(expectThatApi) {
+ expectThatApi.api = {
+ be: function(expected) {
+ return expected;
+ },
+ to: function(expected) {
+ return expected;
+ },
+ equal: function(expected) {
+ return expected;
+ },
+ throwException: function(expected) {
+ return {
+ "assertionType": "throw",
+ "expected": expected
+ };
+ },
+ extendApi: function(fn, assertProvder, desc) {
+ var description;
+ if (!Object.prototype.should) {
+ expectThatApi.init(assertProvder);
+ }
+ if (typeof desc === "function" && typeof fn !== "function") {
+ fn = desc;
+ description = fn.toString().match(/^[^\{]*\{((.*\s*)*)\}/m)[1];
+ description = description.replace(/\);/g, "").replace(/[(\^(?)]/g, " ").replace(/.should/g, " should").replace(/return/g, " ").replace(/shouldnt/g, "shouldn't").replace(/void 0/g, "null").replace(/!= null/g, "").replace(/typeof null !== "undefined" && null !== null/g, "undefined").replace(/^\s\s*/, '').replace(/\s\s*$/, '');
+ } else {
+ description = desc;
+ }
+ return [fn, description];
+ }
+ };
+ return expectThatApi.util.extend(expectThatApi, expectThatApi.api);
+})(expectThatApi || (expectThatApi = {}));
+(function(expectThatApi) {
+ expectThatApi.api.extendedMatchers = {
+ greaterThan: function(expected) {
+ return {
+ "assertionType": "greaterThan",
+ "expected": expected,
+ "expr": function(actual, expected) {
+ return actual > expected;
+ }
+ };
+ },
+ lessThan: function(expected) {
+ return {
+ "assertionType": "lessThan",
+ "expected": expected,
+ "expr": function(actual, expected) {
+ return actual < expected;
+ }
+ };
+ },
+ greaterThanOrEqual: function(expected) {
+ return {
+ "assertionType": "greaterThanOrEqual",
+ "expected": expected,
+ "expr": function(actual, expected) {
+ return actual >= expected;
+ }
+ };
+ },
+ lessThanOrEqual: function(expected) {
+ return {
+ "assertionType": "lessThanOrEqual",
+ "expected": expected,
+ "expr": function(actual, expected) {
+ return actual <= expected;
+ }
+ };
+ },
+ strictlyEqual: function(expected) {
+ return {
+ "assertionType": "strictlyEqual",
+ "expected": expected,
+ "expr": function(actual, expected) {
+ return actual === expected;
+ }
+ };
+ }
+ };
+ return expectThatApi.util.extend(expectThatApi, expectThatApi.api.extendedMatchers);
+})(expectThatApi || (expectThatApi = {}));
+(function(expectThatApi, exports) {
+ expectThatApi.api.Mocha = {};
+ expectThatApi.assertionProvider = {};
+ expectThatApi.assertionProvider = {
+ assert: function(actual) {
+ this.actual = actual;
+ return this;
+ },
+ assertThat: function(expr, msg) {
+ if (!expr) {
+ throw new Error(msg || 'failed');
+ }
+ },
+ isEqualTo: function(expected) {
+ return this.assertThat(this.actual == expected, "The expected value was: '" + expected + "' and the actual value was: '" + this.actual + "'.");
+ },
+ isNotEqualTo: function(expected) {
+ return this.assertThat(this.actual != expected, "The expected value was: '" + expected + "' and the actual value was: '" + this.actual + "'.");
+ },
+ isTrue: function() {
+ return this.assertThat(this.actual, "The expected value was: '{expected}' and the actual value was: '" + this.actual + "'.");
+ },
+ isFalse: function() {
+ return this.assertThat(!this.actual, "The expected value was: '{expected}' and the actual value was: '" + this.actual + "'.");
+ },
+ throwsException: function(message) {
+ try {
+ this.actual();
+ return this.assertThat(false, "The function did not throw an exception");
+ } catch (ex) {
+ if (typeof message !== "undefined" && message !== null) {
+ return this.assertThat(ex === message, "The function threw an exception, however, the error message did not match the provided\nexpected error message. The expected error message was '" + message + "' and the actual error message was\n'" + ex + "'.");
+ } else {
+ return this.assertThat(true, "The actual error message was '" + ex + "'.");
+ }
+ }
+ }
+ };
+ expectThatApi.util.extend(expectThatApi.api.mocha, expectThatApi.assertionProvider);
+ expectThatApi.api.mocha = {
+ expectThat: function(desc, fn) {
+ var newFn, result, testDescription;
+ result = expectThatApi.api.extendApi(fn, expectThatApi.assertionProvider, desc);
+ newFn = result[0];
+ testDescription = result[1];
+ return it(testDescription, newFn);
+ }
+ };
+ expectThatApi.util.extend(expectThatApi, expectThatApi.api.mocha);
+ exports.equal = expectThatApi.api.equal;
+ exports.be = expectThatApi.api.be;
+ exports.to = expectThatApi.api.to;
+ exports.throwException = expectThatApi.api.throwException;
+ exports.expectThat = expectThatApi.expectThat;
+ exports.expectThatApi = expectThatApi;
+ expectThatApi.util.extend(exports, expectThatApi.api.extendedMatchers);
+ return this;
+})(expectThatApi || (expectThatApi = {}), root);
@@ -0,0 +1 @@
+var expectThatApi,root;root=typeof exports!="undefined"&&exports!==null?exports:window,expectThatApi=function(a){return{version:"0.2.2.2",init:function(a){var b;return b=this,Object.prototype.should=function(c){return b.evaluateAssertion(a,!0,this,c)},Object.prototype.shouldnt=function(c){return b.evaluateAssertion(a,!1,this,c)},this},executeThrowAssertion:function(a,b,c){return typeof c.expected!="undefined"?a.throwsException(b):a.throwsException()},executeEqualToAssertion:function(a,b,c){return a?b.isEqualTo(c):b.isNotEqualTo(c)},executeBooleanAssertion:function(a,b,c,d,e){var f;if(typeof d.expr!="function")throw"The provided custom assertion expression for "+d.assertionType+" is invalid.\nCustom assertion expressions should be defined as:\n(actual, expected) -> <some function using actual and expression>.";return f=e.assert(d.expr(b,c)),a?f.isTrue():f.isFalse()},executeAssertion:function(a,b,c,d,e,f,g){if(a===null||typeof a=="undefined")return;return typeof c!="undefined"?c==="throw"?this.executeThrowAssertion(a,e,f):this.executeBooleanAssertion(b,d,e,f,g):this.executeEqualToAssertion(b,a,e)},evaluateAssertion:function(a,b,c,d){var e,f,g,h;return h=d,g=d,typeof d=="function"&&(g=d()),typeof g!="undefined"&&g!==null&&(f=g.assertionType,typeof g.expected!="undefined"&&(h=g.expected)),e=a.assert(c),this.executeAssertion(e,b,f,c,h,g,a)}}}(expectThatApi||(expectThatApi={})),function(a){return a.util={extend:function(a,b){var c;for(c in b)b.hasOwnProperty(c)&&a&&(a[c]=b[c]);return a}},this}(expectThatApi||(expectThatApi={})),function(a){return a.api={be:function(a){return a},to:function(a){return a},equal:function(a){return a},throwException:function(a){return{assertionType:"throw",expected:a}},extendApi:function(b,c,d){var e;return Object.prototype.should||a.init(c),typeof d=="function"&&typeof b!="function"?(b=d,e=b.toString().match(/^[^\{]*\{((.*\s*)*)\}/m)[1],e=e.replace(/\);/g,"").replace(/[(\^(?)]/g," ").replace(/.should/g," should").replace(/return/g," ").replace(/shouldnt/g,"shouldn't").replace(/void 0/g,"null").replace(/!= null/g,"").replace(/typeof null !== "undefined" && null !== null/g,"undefined").replace(/^\s\s*/,"").replace(/\s\s*$/,"")):e=d,[b,e]}},a.util.extend(a,a.api)}(expectThatApi||(expectThatApi={})),function(a){return a.api.extendedMatchers={greaterThan:function(a){return{assertionType:"greaterThan",expected:a,expr:function(a,b){return a>b}}},lessThan:function(a){return{assertionType:"lessThan",expected:a,expr:function(a,b){return a<b}}},greaterThanOrEqual:function(a){return{assertionType:"greaterThanOrEqual",expected:a,expr:function(a,b){return a>=b}}},lessThanOrEqual:function(a){return{assertionType:"lessThanOrEqual",expected:a,expr:function(a,b){return a<=b}}},strictlyEqual:function(a){return{assertionType:"strictlyEqual",expected:a,expr:function(a,b){return a===b}}}},a.util.extend(a,a.api.extendedMatchers)}(expectThatApi||(expectThatApi={})),function(a,b){return a.api.Mocha={},a.assertionProvider={},a.assertionProvider={assert:function(a){return this.actual=a,this},assertThat:function(a,b){if(!a)throw new Error(b||"failed")},isEqualTo:function(a){return this.assertThat(this.actual==a,"The expected value was: '"+a+"' and the actual value was: '"+this.actual+"'.")},isNotEqualTo:function(a){return this.assertThat(this.actual!=a,"The expected value was: '"+a+"' and the actual value was: '"+this.actual+"'.")},isTrue:function(){return this.assertThat(this.actual,"The expected value was: '{expected}' and the actual value was: '"+this.actual+"'.")},isFalse:function(){return this.assertThat(!this.actual,"The expected value was: '{expected}' and the actual value was: '"+this.actual+"'.")},throwsException:function(a){try{return this.actual(),this.assertThat(!1,"The function did not throw an exception")}catch(b){return typeof a!="undefined"&&a!==null?this.assertThat(b===a,"The function threw an exception, however, the error message did not match the provided\nexpected error message. The expected error message was '"+a+"' and the actual error message was\n'"+b+"'."):this.assertThat(!0,"The actual error message was '"+b+"'.")}}},a.util.extend(a.api.mocha,a.assertionProvider),a.api.mocha={expectThat:function(b,c){var d,e,f;return e=a.api.extendApi(c,a.assertionProvider,b),d=e[0],f=e[1],it(f,d)}},a.util.extend(a,a.api.mocha),b.equal=a.api.equal,b.be=a.api.be,b.to=a.api.to,b.throwException=a.api.throwException,b.expectThat=a.expectThat,b.expectThatApi=a,a.util.extend(b,a.api.extendedMatchers),this}(expectThatApi||(expectThatApi={}),root)
@@ -5,9 +5,9 @@
<link rel="stylesheet" href="https://raw.github.com/visionmedia/mocha/master/mocha.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="https://raw.github.com/visionmedia/mocha/master/mocha.js"></script>
- <script type="text/javascript" src="../../lib/expectThat.mocha.js"></script>
+ <script type="text/javascript" src="expectThat.mocha.js"></script>
<script>mocha.setup('bdd')</script>
- <script src="./min/example.spec.js"></script>
+ <script src="example.spec.js"></script>
<script>
$(function () {
mocha
Binary file not shown.

0 comments on commit 3508ee3

Please sign in to comment.