Comparing version 0.0.27 to 0.0.28
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.9.1 | ||
// Generated by CoffeeScript 1.9.2 | ||
(function() { | ||
@@ -269,6 +269,6 @@ var I, Q, Result, _, assert, buildDescription, crossCombineResults, describeScenario, getCounts, interpolate, lastResult, makeResult, resolveResultArray, resolveResultObject, uuid, | ||
describeScenario = function(spec, arg) { | ||
var DONE, GIVEN, THEN, WHEN, bdd, counts, getGiven, getTap, getThen, getWhen, getter, only, promiseBuilderFactory; | ||
var DONE, GIVEN, THEN, WHEN, bdd, buildContext, buildPromiseChain, counts, getGiven, getTap, getThen, getWhen, handlers, only, promiseBuilderFactory, stepRunnerFactory; | ||
only = arg.only, counts = arg.counts; | ||
GIVEN = spec.GIVEN, WHEN = spec.WHEN, THEN = spec.THEN, DONE = spec.DONE; | ||
getter = function(name, collection) { | ||
stepRunnerFactory = function(name, collection) { | ||
return function(description) { | ||
@@ -300,6 +300,111 @@ var fn; | ||
}; | ||
getGiven = getter('GIVEN', GIVEN); | ||
getWhen = getter('WHEN', WHEN); | ||
getThen = getter('THEN', THEN); | ||
getTap = getter('TAP'); | ||
getGiven = stepRunnerFactory('GIVEN', GIVEN); | ||
getWhen = stepRunnerFactory('WHEN', WHEN); | ||
getThen = stepRunnerFactory('THEN', THEN); | ||
getTap = stepRunnerFactory('TAP'); | ||
buildContext = function() { | ||
var currentContext, updateContext; | ||
currentContext = null; | ||
updateContext = function() { | ||
return currentContext = this; | ||
}; | ||
return { | ||
getContext: (function() { | ||
return currentContext; | ||
}), | ||
updateContext: updateContext | ||
}; | ||
}; | ||
handlers = function(done) { | ||
return { | ||
finish: function() { | ||
return typeof done === "function" ? done() : void 0; | ||
}, | ||
fail: function(err) { | ||
if (done) { | ||
return done(err); | ||
} | ||
throw err; | ||
} | ||
}; | ||
}; | ||
buildPromiseChain = function(arg1) { | ||
var bddIt, chain, chains, currentChain, descriptionBuilder, multipleIt, promise, ref; | ||
descriptionBuilder = arg1.descriptionBuilder, promise = arg1.promise, chain = arg1.chain, multipleIt = arg1.multipleIt, bddIt = arg1.bddIt; | ||
if (bddIt) { | ||
if (multipleIt) { | ||
ref = chain.reduce(function(arg2, arg3) { | ||
var chains, currentChain, description, previousDescription, thenFn; | ||
chains = arg2[0], currentChain = arg2[1], previousDescription = arg2[2]; | ||
thenFn = arg3.thenFn, description = arg3.description; | ||
assert.equal(typeof thenFn, 'function'); | ||
if (description && previousDescription) { | ||
chains = chains.concat([currentChain]); | ||
currentChain = []; | ||
} | ||
currentChain = currentChain.concat([ | ||
{ | ||
thenFn: thenFn, | ||
description: description | ||
} | ||
]); | ||
return [chains, currentChain, previousDescription || description]; | ||
}, [[], []]), chains = ref[0], currentChain = ref[1]; | ||
if (currentChain.length) { | ||
chains = chains.concat([currentChain]); | ||
} | ||
chains[chains.length - 1].push({ | ||
thenFn: function() { | ||
return typeof spec.done === "function" ? spec.done() : void 0; | ||
} | ||
}); | ||
return chains.forEach(function(chain, chainsIndex) { | ||
return bddIt("" + chain[0].description, function(done) { | ||
chain.forEach(function(arg2) { | ||
var thenFn; | ||
thenFn = arg2.thenFn; | ||
return promise = promise.then(thenFn); | ||
}); | ||
return promise.then(function() { | ||
return done(); | ||
}).fail(done); | ||
}); | ||
}); | ||
} else { | ||
assert(descriptionBuilder); | ||
return bddIt(descriptionBuilder.get(), function(done) { | ||
var fail, finish, ref1; | ||
chain.forEach(function(arg2) { | ||
var thenFn; | ||
thenFn = arg2.thenFn; | ||
return promise = promise.then(thenFn); | ||
}); | ||
ref1 = handlers(done), finish = ref1.finish, fail = ref1.fail; | ||
return promise.then(function() { | ||
return typeof spec.done === "function" ? spec.done() : void 0; | ||
}).then(finish).fail(function(err) { | ||
if (typeof spec.done === "function") { | ||
spec.done(); | ||
} | ||
return fail(err); | ||
}).fail(fail); | ||
}); | ||
} | ||
} else { | ||
chain.forEach(function(arg2) { | ||
var thenFn; | ||
thenFn = arg2.thenFn; | ||
return promise = promise.then(thenFn); | ||
}); | ||
promise = promise.then(function() { | ||
return typeof spec.done === "function" ? spec.done() : void 0; | ||
}).fail(function(err) { | ||
if (typeof spec.done === "function") { | ||
spec.done(); | ||
} | ||
throw err; | ||
}); | ||
return promise; | ||
} | ||
}; | ||
promiseBuilderFactory = function(arg1) { | ||
@@ -311,17 +416,45 @@ var chain; | ||
return { | ||
then: function(fn) { | ||
then: function(arg2) { | ||
var description, thenFn; | ||
thenFn = arg2.thenFn, description = arg2.description; | ||
return promiseBuilderFactory({ | ||
chain: chain.push(fn) | ||
chain: chain.push({ | ||
thenFn: thenFn, | ||
description: description | ||
}) | ||
}); | ||
}, | ||
resolve: function() { | ||
var args, deferred, promise; | ||
args = 1 <= arguments.length ? slice.call(arguments, 0) : []; | ||
deferred = Q.defer(); | ||
deferred.resolve.apply(deferred, args); | ||
promise = deferred.promise; | ||
chain.forEach(function(thenFn) { | ||
return promise = promise.then(thenFn); | ||
chain: chain, | ||
combine: function(arg2) { | ||
var descriptionBuilder, rightPromiseBuilder, thenFn; | ||
descriptionBuilder = arg2.descriptionBuilder, rightPromiseBuilder = arg2.promiseBuilder; | ||
thenFn = function(context) { | ||
var newContext; | ||
newContext = buildContext(); | ||
crossCombineResults.setInContext(newContext, crossCombineResults.getFromContext(context)); | ||
return newContext; | ||
}; | ||
return promiseBuilderFactory({ | ||
chain: chain.push({ | ||
thenFn: thenFn | ||
}).concat(rightPromiseBuilder.chain) | ||
}); | ||
return promise; | ||
}, | ||
resolve: function(arg2, context) { | ||
var bddIt, bodyFn, descriptionBuilder, multipleIt; | ||
descriptionBuilder = arg2.descriptionBuilder, bddIt = arg2.bddIt, multipleIt = arg2.multipleIt; | ||
bodyFn = function() { | ||
var deferred; | ||
assert(descriptionBuilder); | ||
deferred = Q.defer(); | ||
deferred.resolve(context); | ||
return buildPromiseChain({ | ||
promise: deferred.promise, | ||
chain: chain, | ||
descriptionBuilder: descriptionBuilder, | ||
bddIt: bddIt, | ||
multipleIt: multipleIt | ||
}); | ||
}; | ||
return bodyFn(); | ||
} | ||
@@ -333,26 +466,22 @@ }; | ||
assert(promiseBuilder, 'bdd required promiseBuilder'); | ||
run = function(done) { | ||
var currentContext, fail, finish, updateContext; | ||
finish = function() { | ||
if (typeof spec.done === "function") { | ||
spec.done(); | ||
} | ||
return typeof done === "function" ? done() : void 0; | ||
run = function(options, done) { | ||
var bddIt, fail, finish, multipleIt, ref, ref1, testBodyFn; | ||
ref = options != null ? options : {}, bddIt = ref.bddIt, multipleIt = ref.multipleIt; | ||
testBodyFn = function() { | ||
return promiseBuilder.resolve({ | ||
descriptionBuilder: descriptionBuilder, | ||
bddIt: bddIt, | ||
multipleIt: multipleIt | ||
}, buildContext()); | ||
}; | ||
fail = function(err) { | ||
if (done) { | ||
return done(err); | ||
} | ||
throw err; | ||
}; | ||
currentContext = null; | ||
updateContext = function() { | ||
return currentContext = this; | ||
}; | ||
return promiseBuilder.resolve({ | ||
getContext: (function() { | ||
return currentContext; | ||
}), | ||
updateContext: updateContext | ||
}).then(finish).fail(fail); | ||
if (bddIt) { | ||
assert(descriptionBuilder, '`bddIt` requires descriptionBuilder'); | ||
assert(!done, 'Done cannot be provided for `bddIt`'); | ||
testBodyFn(); | ||
} else { | ||
ref1 = handlers(done), finish = ref1.finish, fail = ref1.fail; | ||
return testBodyFn().then(finish).then(function() { | ||
return typeof spec.done === "function" ? spec.done() : void 0; | ||
}).fail(fail); | ||
} | ||
}; | ||
@@ -362,20 +491,25 @@ return { | ||
descriptionBuilder: descriptionBuilder, | ||
run: run, | ||
run: function(cb) { | ||
return run({}, cb); | ||
}, | ||
resultTo: function(result) { | ||
return bdd(descriptionBuilder, promiseBuilder.then(function(context) { | ||
var lastResultValue, r, ref, results, rkey; | ||
results = (ref = crossCombineResults.getFromContext(context)) != null ? ref : {}; | ||
lastResultValue = lastResult.getFromContext(context); | ||
if (result instanceof Result) { | ||
assert(result instanceof Result, 'Result must be created with bdd.result()'); | ||
result.setInContext(results, lastResultValue); | ||
} else { | ||
for (rkey in result) { | ||
r = result[rkey]; | ||
assert(r instanceof Result, 'Subresult isnt bdd.result()'); | ||
r.setInContext(results, lastResultValue[rkey]); | ||
return bdd(descriptionBuilder, promiseBuilder.then({ | ||
description: '', | ||
thenFn: function(context) { | ||
var lastResultValue, r, ref, results, rkey; | ||
results = (ref = crossCombineResults.getFromContext(context)) != null ? ref : {}; | ||
lastResultValue = lastResult.getFromContext(context); | ||
if (result instanceof Result) { | ||
assert(result instanceof Result, 'Result must be created with bdd.result()'); | ||
result.setInContext(results, lastResultValue); | ||
} else { | ||
for (rkey in result) { | ||
r = result[rkey]; | ||
assert(r instanceof Result, 'Subresult isnt bdd.result()'); | ||
r.setInContext(results, lastResultValue[rkey]); | ||
} | ||
} | ||
crossCombineResults.setInContext(context, results); | ||
return context; | ||
} | ||
crossCombineResults.setInContext(context, results); | ||
return context; | ||
})); | ||
@@ -387,6 +521,9 @@ }, | ||
expandedDescription = interpolate(description, args); | ||
return bdd(descriptionBuilder.given(description, args), promiseBuilder.then(function(context) { | ||
return getGiven(description)(context, { | ||
description: expandedDescription | ||
}, args); | ||
return bdd(descriptionBuilder.given(description, args), promiseBuilder.then({ | ||
description: "Given " + expandedDescription, | ||
thenFn: function(context) { | ||
return getGiven(description)(context, { | ||
description: expandedDescription | ||
}, args); | ||
} | ||
})); | ||
@@ -398,6 +535,9 @@ }, | ||
expandedDescription = interpolate(description, args); | ||
return bdd(descriptionBuilder.when(description, args), promiseBuilder.then(function(context) { | ||
return getWhen(description)(context, { | ||
description: expandedDescription | ||
}, args); | ||
return bdd(descriptionBuilder.when(description, args), promiseBuilder.then({ | ||
description: "when " + expandedDescription, | ||
thenFn: function(context) { | ||
return getWhen(description)(context, { | ||
description: expandedDescription | ||
}, args); | ||
} | ||
})); | ||
@@ -409,6 +549,9 @@ }, | ||
expandedDescription = interpolate(description, args); | ||
return bdd(descriptionBuilder.then(description, args), promiseBuilder.then(function(context) { | ||
return getThen(description)(context, { | ||
description: expandedDescription | ||
}, args); | ||
return bdd(descriptionBuilder.then(description, args), promiseBuilder.then({ | ||
description: "then " + expandedDescription, | ||
thenFn: function(context) { | ||
return getThen(description)(context, { | ||
description: expandedDescription | ||
}, args); | ||
} | ||
})); | ||
@@ -419,29 +562,21 @@ }, | ||
fn = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : []; | ||
return bdd(descriptionBuilder, promiseBuilder.then(function(context) { | ||
return getTap(fn)(context, {}, args); | ||
return bdd(descriptionBuilder, promiseBuilder.then({ | ||
description: '', | ||
thenFn: function(context) { | ||
return getTap(fn)(context, {}, args); | ||
} | ||
})); | ||
}, | ||
combine: function(rightBdd) { | ||
var nextPromiseBuilder; | ||
var newDescriptionBuilder; | ||
assert(rightBdd, 'right bdd not defined'); | ||
nextPromiseBuilder = promiseBuilder.then(function(context) { | ||
var currentContext, newContext, updateContext; | ||
currentContext = null; | ||
updateContext = function() { | ||
return currentContext = this; | ||
}; | ||
newContext = { | ||
getContext: (function() { | ||
return currentContext; | ||
}), | ||
updateContext: updateContext | ||
}; | ||
crossCombineResults.setInContext(newContext, crossCombineResults.getFromContext(context)); | ||
return rightBdd.promiseBuilder.resolve(newContext); | ||
}); | ||
return bdd(descriptionBuilder.combine(rightBdd.descriptionBuilder), nextPromiseBuilder); | ||
newDescriptionBuilder = descriptionBuilder.combine(rightBdd.descriptionBuilder); | ||
return bdd(newDescriptionBuilder, promiseBuilder.combine({ | ||
descriptionBuilder: newDescriptionBuilder, | ||
promiseBuilder: rightBdd.promiseBuilder | ||
})); | ||
}, | ||
done: function(arg1) { | ||
var bddIt; | ||
bddIt = (arg1 != null ? arg1 : {}).it; | ||
var bddIt, multipleIt, ref; | ||
ref = arg1 != null ? arg1 : {}, multipleIt = ref.multipleIt, bddIt = ref.it; | ||
if (bddIt == null) { | ||
@@ -451,3 +586,7 @@ bddIt = global.it; | ||
bddIt = only ? bddIt.only.bind(bddIt) : bddIt; | ||
return bddIt(descriptionBuilder.get(), run); | ||
return run({ | ||
descriptionBuilder: descriptionBuilder, | ||
bddIt: bddIt, | ||
multipleIt: multipleIt | ||
}); | ||
} | ||
@@ -454,0 +593,0 @@ }; |
{ | ||
"name": "gwt", | ||
"version": "0.0.27", | ||
"version": "0.0.28", | ||
"description": "Given, when, then", | ||
@@ -25,3 +25,5 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"coffee-errors": "^0.8.6", | ||
"coffee-script": "^1.9.1", | ||
"jsquickcheck": "0.0.2", | ||
"mocha": "^2.2.1", | ||
@@ -28,0 +30,0 @@ "sinon": "^1.14.0" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31953
573
5