Blame view

framework/thirdparty/jasmine-jstd-adapter/src/JasmineAdapter.js 2.54 KB
0084d336   Administrator   Importers CRUD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
  /**
   * @fileoverview Jasmine JsTestDriver Adapter.
   * @author ibolmo@gmail.com (Olmo Maldonado)
   * @author misko@hevery.com (Misko Hevery)
   */
  
  (function(describe, it, beforeEach, afterEach, addResult){
  
  var frame = function(parent, name){
  	var caseName = '';
  	if (parent && parent.caseName) caseName = parent.caseName + ' ';
  	if (name) caseName += name;
  
  	var before = [],
  		after = [];
  
  	return {
  		name: name,
  		caseName: caseName,
  		parent: parent,
  		testCase: TestCase(caseName),
  		before: before,
  		after: after,
  		runBefore: function(){
  			if (parent) parent.runBefore.apply(this);
  			for (var i = 0, l = before.length; i < l; i++) before[i].apply(this);
  		},
  		runAfter: function(){
  			for (var i = 0, l = after.length; i < l; i++) after[i].apply(this);
  			if (parent) parent.runAfter.apply(this);
  		}
  	};
  };
  
  var currentFrame = frame(null, null);
  
  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(description, closure){
  	var result = it.call(this, description, closure),
  		currentSpec = this.currentSpec,
  		frame = this.jstdFrame = currentFrame,
  		name = 'test that it ' + description;
  
  	if (this.jstdFrame.testCase.prototype[name])
  		throw "Spec with name '" + description + "' already exists.";
  	
  	this.jstdFrame.testCase.prototype[name] = function(){
  		jasmine.getEnv().currentSpec = currentSpec;
  		frame.runBefore.apply(currentSpec);
  		try {
  			currentSpec.queue.start();
  		} finally {
  		  frame.runAfter.apply(currentSpec);
  		}
  	};
  	return result;
  };
  
  jasmine.Env.prototype.beforeEach = function(closure) {
  	beforeEach.call(this, closure);
  	currentFrame.before.push(closure);
  };
  
  jasmine.Env.prototype.afterEach = function(closure) {
  	afterEach.call(this, closure);
  	currentFrame.after.push(closure);
  };
  
  jasmine.NestedResults.prototype.addResult = function(result) {
  	addResult.call(this, result);
  	if (result.type != 'MessageResult' && !result.passed()) fail(result.message);
  };
  
  // @reesd - Disable the catch on exceptions when using JSTD, we want them to make it up to JSTD
  jasmine.Block.prototype.execute = function(onComplete) {
  	try {
  		this.func.apply(this.spec);
  	} finally {
  		onComplete();
  	}
  };
  
  // 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);