aboutsummaryrefslogtreecommitdiffstats
path: root/lib/jasmine-jstd-adapter/JasmineAdapter.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/jasmine-jstd-adapter/JasmineAdapter.js')
-rw-r--r--lib/jasmine-jstd-adapter/JasmineAdapter.js181
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();
})();