Permalink
Browse files

* DRYing up the code

  • Loading branch information...
cpojer committed Jul 21, 2010
1 parent 1526dee commit c7987e663317b4355dfbaff16d1b962892c7284b
Showing with 14 additions and 34 deletions.
  1. +14 −34 src/JasmineAdapter.js
View
@@ -4,11 +4,9 @@
* @author misko@hevery.com (Misko Hevery)
*/
-(function() {
+(function(describe, it, beforeEach, afterEach, addResult){
- var currentFrame = frame(null, null);
-
- function frame(parent, name){
+ var frame = function(parent, name){
var caseName = '';
if (parent && parent.caseName) caseName = parent.caseName + ' ';
if (name) caseName += name;
@@ -34,20 +32,16 @@
};
};
- jasmine.Env.prototype.describe = (function(describe){
-
- return function(description, context){
- currentFrame = frame(currentFrame, description);
- var result = describe.call(this, description, context);
- currentFrame = currentFrame.parent;
- return result;
- };
+ var currentFrame = frame(null, null);
- })(jasmine.Env.prototype.describe);
+ jasmine.Env.prototype.describe = function(description, context){
+ currentFrame = frame(currentFrame, description);
+ var result = describe.call(this, description, context);
+ currentFrame = currentFrame.parent;
+ return result;
+ };
- jasmine.Env.prototype.it = (function(it){
-
- return function(description, closure){
+ jasmine.Env.prototype.it = function(description, closure){
var result = it.call(this, description, closure);
var currentSpec = this.currentSpec;
@@ -68,40 +62,26 @@
return result;
};
- })(jasmine.Env.prototype.it);
-
- jasmine.Env.prototype.beforeEach = (function(beforeEach){
-
- return function(closure) {
+ jasmine.Env.prototype.beforeEach = function(closure) {
beforeEach.call(this, closure);
currentFrame.before.push(closure);
};
- })(jasmine.Env.prototype.beforeEach);
-
- jasmine.Env.prototype.afterEach = (function(afterEach){
-
- return function(closure) {
+ jasmine.Env.prototype.afterEach = function(closure) {
afterEach.call(this, closure);
currentFrame.after.push(closure);
};
- })(jasmine.Env.prototype.afterEach);
-
- jasmine.NestedResults.prototype.addResult = (function(addResult){
-
- return function(result) {
+ jasmine.NestedResults.prototype.addResult = 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();
-})();
+})(jasmine.Env.prototype.describe, jasmine.Env.prototype.it, jasmine.Env.prototype.beforeEach, jasmine.Env.prototype.afterEach, jasmine.NestedResults.prototype.addResult);

0 comments on commit c7987e6

Please sign in to comment.