diff options
| author | Misko Hevery | 2010-04-09 16:20:15 -0700 |
|---|---|---|
| committer | Misko Hevery | 2010-04-09 16:20:15 -0700 |
| commit | 843bd355d25ebf2369aec79f98cb6704d38497e9 (patch) | |
| tree | 3850d13b9ad8ab6c5dd975c20cf9d849c7429ed2 /lib/jasmine-jstd-adapter/JasmineAdapter.js | |
| parent | 41a5c408c242269bf31bc0b774c7304fdf7c2f1c (diff) | |
| download | angular.js-843bd355d25ebf2369aec79f98cb6704d38497e9.tar.bz2 | |
various bug fixes
Diffstat (limited to 'lib/jasmine-jstd-adapter/JasmineAdapter.js')
| -rw-r--r-- | lib/jasmine-jstd-adapter/JasmineAdapter.js | 181 |
1 files changed, 94 insertions, 87 deletions
diff --git a/lib/jasmine-jstd-adapter/JasmineAdapter.js b/lib/jasmine-jstd-adapter/JasmineAdapter.js index 83a1deed..ba54251a 100644 --- a/lib/jasmine-jstd-adapter/JasmineAdapter.js +++ b/lib/jasmine-jstd-adapter/JasmineAdapter.js @@ -1,96 +1,103 @@ /** * @fileoverview Jasmine JsTestDriver Adapter. * @author ibolmo@gmail.com (Olmo Maldonado) + * @author misko@hevery.com (Misko Hevery) */ (function() { -// Suite/TestCase before and after function stacks. -var before = []; -var after = []; - -jasmine.Env.prototype.describe = (function(describe){ - - // TODO(ibolmo): Support nested describes. - return function(description, specDefinitions){ - this.currentTestCase = TestCase(description); - return describe.call(this, description, specDefinitions); - }; - -})(jasmine.Env.prototype.describe); - - -jasmine.Env.prototype.it = (function(it){ - - return function(desc, func){ - var spec = it.call(this, desc, func); - this.currentTestCase.prototype['test that it ' + desc] = func; - return spec; - }; - -})(jasmine.Env.prototype.it); - - -jasmine.Env.prototype.beforeEach = (function(beforeEach){ - - // TODO(ibolmo): Support beforeEach TestCase. - return function(beforeEachFunction) { - beforeEach.call(this, beforeEachFunction); - if (this.currentTestCase) { - this.currentTestCase.prototype.setUp = beforeEachFunction; - } else { - before.push(beforeEachFunction); - } - }; - -})(jasmine.Env.prototype.beforeEach); - - -jasmine.Env.prototype.afterEach = (function(afterEach){ - - // TODO(ibolmo): Support afterEach TestCase. - return function(afterEachFunction) { - afterEach.call(this, afterEachFunction); - if (this.currentTestCase) { - this.currentTestCase.prototype.tearDown = afterEachFunction; - } else { - after.push(afterEachFunction); - } - }; - -})(jasmine.Env.prototype.afterEach); - - -jasmine.NestedResults.prototype.addResult = (function(addResult){ - - return function(result) { - addResult.call(this, result); - if (result.type != 'MessageResult' && !result.passed()) fail(result.message); - }; - -})(jasmine.NestedResults.prototype.addResult); - - -jstestdriver.plugins.TestRunnerPlugin.prototype.runTestConfiguration = (function(runTestConfiguration){ - - return function(testRunConfiguration, onTestDone, onTestRunConfigurationComplete){ - for (var i = 0, l = before.length; i < l; i++) before[i](); - onTestRunConfigurationComplete = (function(configurationComplete){ - - return function() { - for (var i = 0, l = after.length; i < l; i++) after[i](); - configurationComplete(); - }; - - })(onTestRunConfigurationComplete); - runTestConfiguration.call(this, testRunConfiguration, onTestDone, onTestRunConfigurationComplete); - }; - -})(jstestdriver.plugins.TestRunnerPlugin.prototype.runTestConfiguration); - - -// Reset environment with overriden methods. -jasmine.currentEnv_ = null; -jasmine.getEnv(); + function bind(_this, _function){ + return function(){ + return _function.call(_this); + } + } + + var currentFrame = frame(null, null); + + function frame(parent, name){ + var caseName = (parent && parent.caseName ? parent.caseName + " " : '') + (name ? name : ''); + var frame = { + name: name, + caseName: caseName, + parent: parent, + testCase: TestCase(caseName), + before: [], + after: [], + runBefore: function(){ + if (parent) parent.runBefore.apply(this); + for ( var i = 0; i < frame.before.length; i++) { + frame.before[i].apply(this); + } + }, + runAfter: function(){ + for ( var i = 0; i < frame.after.length; i++) { + frame.after[i].apply(this); + } + if (parent) parent.runAfter.apply(this); + } + }; + return frame; + }; + + jasmine.Env.prototype.describe = (function(describe){ + return function(description){ + currentFrame = frame(currentFrame, description); + var val = describe.apply(this, arguments); + currentFrame = currentFrame.parent; + return val; + }; + + })(jasmine.Env.prototype.describe); + + + jasmine.Env.prototype.it = (function(it){ + return function(desc, itFn){ + var self = this; + var spec = it.apply(this, arguments); + var currentSpec = this.currentSpec; + var frame = this.jstdFrame = currentFrame; + this.jstdFrame.testCase.prototype['test that it ' + desc] = function(){ + frame.runBefore.apply(currentSpec); + try { + itFn.apply(currentSpec); + } finally { + frame.runAfter.apply(currentSpec); + } + }; + return spec; + }; + + })(jasmine.Env.prototype.it); + + + jasmine.Env.prototype.beforeEach = (function(beforeEach){ + return function(beforeEachFunction) { + beforeEach.apply(this, arguments); + currentFrame.before.push(beforeEachFunction); + }; + + })(jasmine.Env.prototype.beforeEach); + + + jasmine.Env.prototype.afterEach = (function(afterEach){ + return function(afterEachFunction) { + afterEach.apply(this, arguments); + currentFrame.after.push(afterEachFunction); + }; + + })(jasmine.Env.prototype.afterEach); + + + jasmine.NestedResults.prototype.addResult = (function(addResult){ + return function(result) { + addResult.call(this, result); + if (result.type != 'MessageResult' && !result.passed()) fail(result.message); + }; + + })(jasmine.NestedResults.prototype.addResult); + + // Reset environment with overriden methods. + jasmine.currentEnv_ = null; + jasmine.getEnv(); })(); |
