vendor/assets/javascripts/chai-changes.js in konacha-chai-matchers-0.0.17 vs vendor/assets/javascripts/chai-changes.js in konacha-chai-matchers-0.0.18

- old
+ new

@@ -1,6 +1,6 @@ -// Generated by CoffeeScript 1.3.3 +// Generated by CoffeeScript 1.4.0 (function() { (function(chaiChanges) { if (typeof require === "function" && typeof exports === "object" && typeof module === "object") { return module.exports = chaiChanges; @@ -10,19 +10,13 @@ }); } else { return chai.use(chaiChanges); } })(function(chai, utils) { - var changeBy, changeByAssert, changeFrom, changeFromAssert, changeFromBeginAssert, changeTo, changeToAssert, changeToBeginAssert, flag, formatFunction, inspect, noChangeAssert; + var byAtLeast, byAtMost, changeBy, changeByAssert, changeFrom, changeFromAssert, changeFromBeginAssert, changeTo, changeToAssert, changeToBeginAssert, flag, formatFunction, inspect, noChangeAssert; inspect = utils.inspect; flag = utils.flag; - /* - # - # Changes Matchers - # - */ - chai.Assertion.addMethod('when', function(val, options) { var action, definedActions, done, isPromise, newPromise, object, promiseCallback, result, _i, _j, _len, _len1, _this = this; if (options == null) { options = {}; @@ -52,12 +46,12 @@ action.after(_this); } } return done(); } catch (error) { - done(new Error(error)); - throw new Error(error); + done(error); + throw error; } }; newPromise = result.then(promiseCallback, promiseCallback); return newPromise; } else { @@ -65,13 +59,11 @@ action = definedActions[_j]; if (typeof action.after === "function") { action.after(this); } } - flag(this, 'object', result); } - flag(this, 'negate', false); return this; }); noChangeAssert = function(context) { var endValue, negate, object, relevant, result, startValue; relevant = flag(context, 'no-change'); @@ -157,9 +149,115 @@ return flag(context, 'changeStart', startValue); }, after: noChangeAssert }); return flag(this, 'whenActions', definedActions); + }); + chai.Assertion.addProperty('increase', function() { + var definedActions; + definedActions = flag(this, 'whenActions') || []; + definedActions.push({ + negate: flag(this, 'negate'), + before: function(context) { + var startValue; + startValue = flag(context, 'whenObject')(); + return flag(context, 'increaseStart', startValue); + }, + after: function(context) { + var endValue, negate, object, startValue; + object = flag(context, 'whenObject'); + endValue = object(); + startValue = flag(context, 'increaseStart'); + negate = flag(context, 'negate'); + flag(context, 'negate', this.negate); + if (!negate) { + context.assert(startValue !== endValue, "expected `" + (formatFunction(object)) + "` to increase, but it did not change", "not supported"); + } + context.assert(startValue < endValue, "expected `" + (formatFunction(object)) + "` to increase, but it decreased by " + (startValue - endValue), "expected `" + (formatFunction(object)) + "` not to increase, but it increased by " + (endValue - startValue)); + return flag(context, 'negate', negate); + } + }); + return flag(this, 'whenActions', definedActions); + }); + chai.Assertion.addProperty('decrease', function() { + var definedActions; + definedActions = flag(this, 'whenActions') || []; + definedActions.push({ + negate: flag(this, 'negate'), + before: function(context) { + var startValue; + startValue = flag(context, 'whenObject')(); + return flag(context, 'decreaseStart', startValue); + }, + after: function(context) { + var endValue, negate, object, startValue; + object = flag(context, 'whenObject'); + endValue = object(); + startValue = flag(context, 'decreaseStart'); + negate = flag(context, 'negate'); + flag(context, 'negate', this.negate); + if (!negate) { + context.assert(startValue !== endValue, "expected `" + (formatFunction(object)) + "` to decrease, but it did not change", "not supported"); + } + context.assert(startValue > endValue, "expected `" + (formatFunction(object)) + "` to decrease, but it increased by " + (endValue - startValue), "expected `" + (formatFunction(object)) + "` not to decrease, but it decreased by " + (startValue - endValue)); + return flag(context, 'negate', negate); + } + }); + return flag(this, 'whenActions', definedActions); + }); + byAtLeast = function(amount) { + var definedActions; + definedActions = flag(this, 'whenActions') || []; + definedActions.push({ + negate: flag(this, 'negate'), + before: function(context) { + var startValue; + startValue = flag(context, 'whenObject')(); + return flag(context, 'atLeastStart', startValue); + }, + after: function(context) { + var difference, endValue, negate, object, startValue; + object = flag(context, 'whenObject'); + endValue = object(); + startValue = flag(context, 'atLeastStart'); + negate = flag(context, 'negate'); + flag(context, 'negate', this.negate); + difference = Math.abs(endValue - startValue); + context.assert(difference >= amount, "expected `" + (formatFunction(object)) + "` to change by at least " + amount + ", but changed by " + difference, "not supported"); + return flag(context, 'negate', negate); + } + }); + return flag(this, 'whenActions', definedActions); + }; + chai.Assertion.addChainableMethod('atLeast', byAtLeast, function() { + return this; + }); + byAtMost = function(amount) { + var definedActions; + definedActions = flag(this, 'whenActions') || []; + definedActions.push({ + negate: flag(this, 'negate'), + before: function(context) { + var startValue; + startValue = flag(context, 'whenObject')(); + return flag(context, 'atMostStart', startValue); + }, + after: function(context) { + var difference, endValue, negate, object, startValue; + object = flag(context, 'whenObject'); + endValue = object(); + startValue = flag(context, 'atMostStart'); + negate = flag(context, 'negate'); + flag(context, 'negate', this.negate); + difference = Math.abs(endValue - startValue); + context.assert(difference <= amount, "expected `" + (formatFunction(object)) + "` to change by at most " + amount + ", but changed by " + difference, "not supported"); + return flag(context, 'negate', negate); + } + }); + return flag(this, 'whenActions', definedActions); + }; + chai.Assertion.addChainableMethod('atMost', byAtMost, function() { + return this; }); formatFunction = function(func) { return func.toString().replace(/^\s*function \(\) {\s*/, '').replace(/\s+}$/, '').replace(/\s*return\s*/, ''); }; changeBy = function(delta) {