diff --git a/.project b/.project new file mode 100644 index 0000000..45d6f3a --- /dev/null +++ b/.project @@ -0,0 +1,11 @@ + + + Jack + + + + + + + + diff --git a/docs/todo.txt b/docs/todo.txt index c38e9ad..e5967a6 100644 --- a/docs/todo.txt +++ b/docs/todo.txt @@ -15,9 +15,15 @@ REFACTORING: FEATURES: +* Implement a new jack.verify() syntax that can be called *after* execution instead of jack.expect() that needs to be called *before* + - For objects created with jack.create(); + - For existsing, global objects + +* (Details) + - Rename "expectations" to "preparations" + * Adapt Jack to be useable with env.js - http://ejohn.org/projects/bringing-the-browser-to-the-server * Integrate Jack with Screw.Unit - http://github.com/nkallen/screw-unit/tree/master -* Implement a new jack.verify() syntax that can be called *after* execution instead of jack.expect() that needs to be called *before* * Find out how to handle calling of original functions * Text reports for argument constraints: - isType() diff --git a/src/jack.js b/src/jack.js index 90e62e3..8957c3c 100644 --- a/src/jack.js +++ b/src/jack.js @@ -11,6 +11,8 @@ function jack() {} // This needs to be here to make error reporting work correct (function (){ // START HIDING FROM GLOBAL SCOPE /** EXPORT JACK **/ window.jack = new Jack(); + window.jack.matchers = new Matchers(); + window.jack.FunctionInvocation = FunctionInvocation; return; @@ -32,6 +34,7 @@ function jack() {} // This needs to be here to make error reporting work correct api.create = create; api.inspect = inspect; api.expect = expect; + api.verify = verify; api.report = report; api.reportAll = reportAll; api.env = environment; @@ -172,6 +175,13 @@ function jack() {} // This needs to be here to make error reporting work correct currentExpectation = findGrab(name).expect().once(); return currentExpectation; } + function verify(name) { + if(findGrab(name) == null) { + grab(name); + } + currentExpectation = findGrab(name).expect().once(); + return currentExpectation; + } function report(name, expectation) { return findGrab(name).report(expectation, name); } @@ -573,6 +583,89 @@ function jack() {} // This needs to be here to make error reporting work correct } } } + + + /** + * + */ + function FunctionInvocation() { + var argumentConstraints = null; + + return api(); + + function api() { + var api = matchers(); + api.test = test; + return api; + } + function matchers() { + var m = {}; + m.withNoArguments = function() { argumentConstraints = []; } + m.withArguments = function() { argumentConstraints = arguments; } + m.whereArgument = function(argIndex) { + return {}; + } + return m; + } + function test() { + var result = true; + if(argumentConstraints != null) { + if(arguments.length != argumentConstraints.length) { + result = false; + } else { + for(var i=0; i - + + + + +