newjs 1.5.1 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +11 -0
- data/Manifest.txt +162 -14
- data/{README.txt → README.rdoc} +1 -1
- data/Rakefile +25 -3
- data/app_generators/newjs_iphone/templates/Html/test/assets/jsunittest.js +41 -13
- data/app_generators/newjs_iphone/templates/Html/test/assets/unittest.css +4 -0
- data/features/development.feature +13 -0
- data/features/imported_files_for_generators.feature +19 -0
- data/features/steps/common.rb +205 -0
- data/features/steps/env.rb +6 -0
- data/javascript_test_generators/functional_test/functional_test_generator.rb +9 -1
- data/javascript_test_generators/functional_test/templates/test/assets/jshoulda.js +186 -0
- data/javascript_test_generators/functional_test/templates/test/test.html.erb +15 -1
- data/javascript_test_generators/unit_test/templates/test/assets/jshoulda.js +186 -0
- data/javascript_test_generators/unit_test/templates/test/test.html.erb +18 -20
- data/javascript_test_generators/unit_test/templates/test/test_jshoulda.html.erb +45 -0
- data/javascript_test_generators/unit_test/unit_test_generator.rb +11 -3
- data/lib/newjs.rb +3 -2
- data/newjs_iphone_generators/page/USAGE +5 -0
- data/newjs_iphone_generators/page/page_generator.rb +36 -0
- data/newjs_iphone_generators/page/templates/src/name.css.erb +0 -0
- data/newjs_iphone_generators/page/templates/src/name.html.erb +13 -0
- data/newjs_iphone_generators/page/templates/src/name.js.erb +4 -0
- data/newjs_iphone_generators/page/templates/test/fixtures/name.js.erb +5 -0
- data/newjs_iphone_generators/page/templates/test/unit/name_test.html.erb +61 -0
- data/rack_generators/javascript_test/USAGE +5 -0
- data/rack_generators/javascript_test/javascript_test_generator.rb +88 -0
- data/rack_generators/javascript_test/templates/assets/jshoulda.js +186 -0
- data/rack_generators/javascript_test/templates/assets/jsunittest.js +1004 -0
- data/rack_generators/javascript_test/templates/assets/unittest.css +54 -0
- data/rack_generators/javascript_test/templates/ext/jquery.js +3408 -0
- data/{app_generators/newjs_iphone/templates/Html/test/assets → rack_generators/javascript_test/templates/ext}/prototype.js +56 -122
- data/rack_generators/javascript_test/templates/library.js.erb +3 -0
- data/rack_generators/javascript_test/templates/test.html.erb +59 -0
- data/rack_generators/javascript_test/templates/test_jshoulda.html.erb +48 -0
- data/rails_generators/javascript_test/javascript_test_generator.rb +15 -3
- data/rails_generators/javascript_test/templates/assets/jshoulda.js +186 -0
- data/rails_generators/javascript_test/templates/test_jshoulda.html.erb +48 -0
- data/script/console +10 -0
- data/script/destroy +1 -1
- data/tasks/vendor/update/jshoulda.rake +18 -0
- data/tasks/vendor/update/jsunittest.rake +18 -0
- data/test/test_functional_test_generator.rb +13 -0
- data/test/test_generator_helper.rb +10 -1
- data/test/test_page_generator.rb +50 -0
- data/test/test_rack_javascript_test.rb +166 -0
- data/test/{test_javascript_test_generator.rb → test_rails_javascript_test_generator.rb} +15 -1
- data/test/test_unit_test_generator.rb +13 -0
- data/vendor/jshoulda/History.txt +108 -0
- data/vendor/jshoulda/License.txt +20 -0
- data/vendor/jshoulda/README.mdown +34 -0
- data/vendor/jshoulda/Rakefile +120 -0
- data/vendor/jshoulda/config/javascript_test_autotest.yml.sample +15 -0
- data/vendor/jshoulda/dist/jshoulda-0.0.1.js +62 -0
- data/vendor/jshoulda/dist/jshoulda-0.0.2.js +72 -0
- data/vendor/jshoulda/dist/jshoulda-0.0.3.js +72 -0
- data/vendor/jshoulda/dist/jshoulda-1.0.1.js +74 -0
- data/vendor/jshoulda/dist/jshoulda-1.0.js +72 -0
- data/vendor/jshoulda/dist/jshoulda-1.1.js +110 -0
- data/vendor/jshoulda/dist/jshoulda-1.2.1.js +186 -0
- data/vendor/jshoulda/dist/jshoulda-1.2.js +141 -0
- data/vendor/jshoulda/dist/jshoulda-1.2.x.js +142 -0
- data/vendor/jshoulda/dist/jshoulda.js +186 -0
- data/vendor/jshoulda/jshoulda/test/basic_test.html +42 -0
- data/vendor/jshoulda/lib/jstest.rb +382 -0
- data/vendor/jshoulda/lib/protodoc.rb +36 -0
- data/vendor/jshoulda/script/destroy +14 -0
- data/vendor/jshoulda/script/generate +14 -0
- data/vendor/jshoulda/script/js_autotest +1 -0
- data/vendor/jshoulda/script/rstakeout +97 -0
- data/vendor/jshoulda/site/asset_defaults.yaml +6 -0
- data/vendor/jshoulda/site/config.yaml +3 -0
- data/vendor/jshoulda/site/content/content.html +27 -0
- data/vendor/jshoulda/site/content/content.yaml +4 -0
- data/vendor/jshoulda/site/content/tutorial/tutorial.html +268 -0
- data/vendor/jshoulda/site/content/tutorial/tutorial.yaml +4 -0
- data/vendor/jshoulda/site/css/blackboard.css +88 -0
- data/vendor/jshoulda/site/css/jshoulda_site.css +33 -0
- data/vendor/jshoulda/site/css/unittest.css +42 -0
- data/vendor/jshoulda/site/example/minimal.html +55 -0
- data/vendor/jshoulda/site/js/editable.js +42 -0
- data/vendor/jshoulda/site/layouts/default/default.html +29 -0
- data/vendor/jshoulda/site/layouts/default/default.yaml +4 -0
- data/vendor/jshoulda/site/layouts/home_test/home_test.js +18 -0
- data/vendor/jshoulda/site/layouts/home_test/home_test.yaml +4 -0
- data/vendor/jshoulda/site/lib/analytics.rb +12 -0
- data/vendor/jshoulda/site/lib/default.rb +2 -0
- data/vendor/jshoulda/site/lib/example.rb +10 -0
- data/vendor/jshoulda/site/lib/hash.rb +11 -0
- data/vendor/jshoulda/site/lib/highlight.rb +17 -0
- data/vendor/jshoulda/site/page_defaults.yaml +10 -0
- data/vendor/jshoulda/site/templates/default/default.html +1 -0
- data/vendor/jshoulda/site/templates/default/default.yaml +4 -0
- data/vendor/jshoulda/src/HEADER +8 -0
- data/vendor/jshoulda/src/jshoulda.js +177 -0
- data/vendor/jshoulda/src/jshoulda.js.erb +3 -0
- data/vendor/jshoulda/tasks/bundle.rake +12 -0
- data/vendor/jshoulda/tasks/demo.rake +9 -0
- data/vendor/jshoulda/tasks/deploy.rake +29 -0
- data/{tasks → vendor/jshoulda/tasks}/environment.rake +0 -0
- data/vendor/jshoulda/tasks/javascript_test_autotest_tasks.rake +45 -0
- data/vendor/jshoulda/tasks/site.rake +74 -0
- data/vendor/jshoulda/test/assets/jsunittest.js +1004 -0
- data/vendor/jshoulda/test/assets/prototype.js +4324 -0
- data/{app_generators/newjs_iphone/templates/Html/test/assets/unittest.js → vendor/jshoulda/test/assets/prototype_unittest.js} +15 -9
- data/vendor/jshoulda/test/assets/unittest.css +50 -0
- data/vendor/jshoulda/test/unit/factory_test.html +82 -0
- data/vendor/jshoulda/test/unit/jshoulda2_test.html +85 -0
- data/vendor/jshoulda/test/unit/jshoulda_prototype_test.html +87 -0
- data/vendor/jshoulda/test/unit/jshoulda_test.html +86 -0
- data/vendor/jshoulda/test/unit/merge_methods_test.html +77 -0
- data/vendor/jshoulda/test/unit/names_and_count.html +68 -0
- data/vendor/jshoulda/test/unit/no_config_test.html +57 -0
- data/vendor/jshoulda/test/unit/styles_test.html +77 -0
- data/vendor/jshoulda/test/unit/unify_runners.html +69 -0
- data/vendor/jshoulda/test/unit/unnamed_context_test.html +67 -0
- data/vendor/jsunittest/Capfile +4 -0
- data/vendor/jsunittest/History.txt +37 -0
- data/{License.txt → vendor/jsunittest/License.txt} +0 -0
- data/vendor/jsunittest/README.txt +21 -0
- data/vendor/jsunittest/Rakefile +118 -0
- data/vendor/jsunittest/config/deploy.rb +20 -0
- data/vendor/jsunittest/config/website.yml.sample +2 -0
- data/vendor/jsunittest/dist/jsunittest-0.7.2.js +1004 -0
- data/vendor/jsunittest/dist/jsunittest.js +1004 -0
- data/vendor/jsunittest/dist/unittest.css +54 -0
- data/vendor/jsunittest/lib/jstest.rb +390 -0
- data/vendor/jsunittest/lib/protodoc.rb +36 -0
- data/vendor/jsunittest/script/destroy +14 -0
- data/vendor/jsunittest/script/generate +14 -0
- data/vendor/jsunittest/script/js_autotest +1 -0
- data/vendor/jsunittest/script/rstakeout +97 -0
- data/vendor/jsunittest/script/txt2html +75 -0
- data/vendor/jsunittest/src/HEADER +8 -0
- data/vendor/jsunittest/src/ajax.js +121 -0
- data/vendor/jsunittest/src/assertions.js +244 -0
- data/vendor/jsunittest/src/common.js +191 -0
- data/vendor/jsunittest/src/jsunittest.js +1004 -0
- data/vendor/jsunittest/src/logger.js +86 -0
- data/vendor/jsunittest/src/message_template.js +17 -0
- data/vendor/jsunittest/src/orig/unittest.js +484 -0
- data/vendor/jsunittest/src/prototype/event.js +72 -0
- data/vendor/jsunittest/src/prototype/template.js +33 -0
- data/vendor/jsunittest/src/runner.js +120 -0
- data/vendor/jsunittest/src/test_case.js +106 -0
- data/vendor/jsunittest/tasks/deploy.rake +29 -0
- data/vendor/jsunittest/tasks/environment.rake +7 -0
- data/vendor/jsunittest/tasks/javascript_test_autotest_tasks.rake +44 -0
- data/vendor/jsunittest/tasks/tmbundle.rake +24 -0
- data/vendor/jsunittest/tasks/website.rake +53 -0
- data/vendor/jsunittest/test/assets/example_test.html +50 -0
- data/{app_generators/newjs/templates → vendor/jsunittest}/test/assets/prototype.js +0 -0
- data/vendor/jsunittest/test/assets/unittest.css +54 -0
- data/{app_generators/newjs/templates → vendor/jsunittest}/test/assets/unittest.js +0 -0
- data/vendor/jsunittest/test/functional/jsunittest_test.html +209 -0
- data/vendor/jsunittest/test/unit/assertions_test.html +202 -0
- data/vendor/jsunittest/test/unit/common_test.html +61 -0
- data/vendor/jsunittest/test/unit/logger_test.html +98 -0
- data/vendor/jsunittest/test/unit/message_template_test.html +44 -0
- data/vendor/jsunittest/test/unit/runner_test.html +77 -0
- data/vendor/jsunittest/test/unit/template_test.html +57 -0
- data/vendor/jsunittest/test/unit/test_case_test.html +97 -0
- data/vendor/jsunittest/website/dist/jsunittest-0.7.2.js +1004 -0
- data/vendor/jsunittest/website/dist/jsunittest-getting-started.tar.gz +0 -0
- data/vendor/jsunittest/website/dist/jsunittest-getting-started.zip +0 -0
- data/vendor/jsunittest/website/dist/jsunittest-getting-started/assets/jsunittest.js +1004 -0
- data/vendor/jsunittest/website/dist/jsunittest-getting-started/assets/unittest.css +54 -0
- data/vendor/jsunittest/website/dist/jsunittest-getting-started/example_test.html +50 -0
- data/vendor/jsunittest/website/dist/jsunittest.js +1004 -0
- data/vendor/jsunittest/website/images/logo_bundle.png +0 -0
- data/vendor/jsunittest/website/images/passing_prototypejs_unittest_tests.jpg +0 -0
- data/vendor/jsunittest/website/index.html +94 -0
- data/vendor/jsunittest/website/index.txt +80 -0
- data/vendor/jsunittest/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/vendor/jsunittest/website/stylesheets/screen.css +138 -0
- data/vendor/jsunittest/website/template.html.erb +46 -0
- data/vendor/jsunittest/website/tmbundle/JavaScript Unit Testing.tmbundle.tar.gz +0 -0
- metadata +189 -24
- data/config/hoe.rb +0 -75
- data/config/requirements.rb +0 -17
- data/lib/newjs/version.rb +0 -9
- data/tasks/deployment.rake +0 -34
- data/tasks/jsunittest/update.rake +0 -18
- data/tasks/website.rake +0 -17
@@ -0,0 +1,86 @@
|
|
1
|
+
JsUnitTest.Unit.Logger = function(element) {
|
2
|
+
this.element = JsUnitTest.$(element);
|
3
|
+
if (this.element) this._createLogTable();
|
4
|
+
};
|
5
|
+
|
6
|
+
JsUnitTest.Unit.Logger.prototype.start = function(testName) {
|
7
|
+
if (!this.element) return;
|
8
|
+
var tbody = this.element.getElementsByTagName('tbody')[0];
|
9
|
+
|
10
|
+
var tr = document.createElement('tr');
|
11
|
+
var td;
|
12
|
+
|
13
|
+
//testname
|
14
|
+
td = document.createElement('td');
|
15
|
+
td.appendChild(document.createTextNode(testName));
|
16
|
+
tr.appendChild(td)
|
17
|
+
|
18
|
+
tr.appendChild(document.createElement('td'));//status
|
19
|
+
tr.appendChild(document.createElement('td'));//message
|
20
|
+
|
21
|
+
tbody.appendChild(tr);
|
22
|
+
};
|
23
|
+
|
24
|
+
JsUnitTest.Unit.Logger.prototype.setStatus = function(status) {
|
25
|
+
var logline = this.getLastLogLine();
|
26
|
+
logline.className = status;
|
27
|
+
var statusCell = logline.getElementsByTagName('td')[1];
|
28
|
+
statusCell.appendChild(document.createTextNode(status));
|
29
|
+
};
|
30
|
+
|
31
|
+
JsUnitTest.Unit.Logger.prototype.finish = function(status, summary) {
|
32
|
+
if (!this.element) return;
|
33
|
+
this.setStatus(status);
|
34
|
+
this.message(summary);
|
35
|
+
};
|
36
|
+
|
37
|
+
JsUnitTest.Unit.Logger.prototype.message = function(message) {
|
38
|
+
if (!this.element) return;
|
39
|
+
var cell = this.getMessageCell();
|
40
|
+
|
41
|
+
// cell.appendChild(document.createTextNode(this._toHTML(message)));
|
42
|
+
cell.innerHTML = this._toHTML(message);
|
43
|
+
};
|
44
|
+
|
45
|
+
JsUnitTest.Unit.Logger.prototype.summary = function(summary) {
|
46
|
+
if (!this.element) return;
|
47
|
+
var div = this.element.getElementsByTagName('div')[0];
|
48
|
+
div.innerHTML = this._toHTML(summary);
|
49
|
+
};
|
50
|
+
|
51
|
+
JsUnitTest.Unit.Logger.prototype.getLastLogLine = function() {
|
52
|
+
var tbody = this.element.getElementsByTagName('tbody')[0];
|
53
|
+
var loglines = tbody.getElementsByTagName('tr');
|
54
|
+
return loglines[loglines.length - 1];
|
55
|
+
};
|
56
|
+
|
57
|
+
JsUnitTest.Unit.Logger.prototype.getMessageCell = function() {
|
58
|
+
var logline = this.getLastLogLine();
|
59
|
+
return logline.getElementsByTagName('td')[2];
|
60
|
+
};
|
61
|
+
|
62
|
+
JsUnitTest.Unit.Logger.prototype._createLogTable = function() {
|
63
|
+
var html = '<div class="logsummary">running...</div>' +
|
64
|
+
'<table class="logtable">' +
|
65
|
+
'<thead><tr><th>Status</th><th>Test</th><th>Message</th></tr></thead>' +
|
66
|
+
'<tbody class="loglines"></tbody>' +
|
67
|
+
'</table>';
|
68
|
+
this.element.innerHTML = html;
|
69
|
+
};
|
70
|
+
|
71
|
+
JsUnitTest.Unit.Logger.prototype.appendActionButtons = function(actions) {
|
72
|
+
// actions = $H(actions);
|
73
|
+
// if (!actions.any()) return;
|
74
|
+
// var div = new Element("div", {className: 'action_buttons'});
|
75
|
+
// actions.inject(div, function(container, action) {
|
76
|
+
// var button = new Element("input").setValue(action.key).observe("click", action.value);
|
77
|
+
// button.type = "button";
|
78
|
+
// return container.insert(button);
|
79
|
+
// });
|
80
|
+
// this.getMessageCell().insert(div);
|
81
|
+
};
|
82
|
+
|
83
|
+
JsUnitTest.Unit.Logger.prototype._toHTML = function(txt) {
|
84
|
+
return JsUnitTest.escapeHTML(txt).replace(/\n/g,"<br/>");
|
85
|
+
};
|
86
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
JsUnitTest.Unit.MessageTemplate = function(string) {
|
2
|
+
var parts = [];
|
3
|
+
var str = JsUnitTest.scan((string || ''), /(?=[^\\])\?|(?:\\\?|[^\?])+/, function(part) {
|
4
|
+
parts.push(part[0]);
|
5
|
+
});
|
6
|
+
this.parts = parts;
|
7
|
+
};
|
8
|
+
|
9
|
+
JsUnitTest.Unit.MessageTemplate.prototype.evaluate = function(params) {
|
10
|
+
var results = [];
|
11
|
+
for (var i=0; i < this.parts.length; i++) {
|
12
|
+
var part = this.parts[i];
|
13
|
+
var result = (part == '?') ? JsUnitTest.inspect(params.shift()) : part.replace(/\\\?/, '?');
|
14
|
+
results.push(result);
|
15
|
+
};
|
16
|
+
return results.join('');
|
17
|
+
};
|
@@ -0,0 +1,484 @@
|
|
1
|
+
// common.js
|
2
|
+
var Test = {
|
3
|
+
Unit: {
|
4
|
+
inspect: Object.inspect // security exception workaround
|
5
|
+
}
|
6
|
+
};
|
7
|
+
|
8
|
+
// logger.js
|
9
|
+
Test.Unit.Logger = Class.create({
|
10
|
+
initialize: function(element) {
|
11
|
+
this.element = $(element);
|
12
|
+
if (this.element) this._createLogTable();
|
13
|
+
},
|
14
|
+
|
15
|
+
start: function(testName) {
|
16
|
+
if (!this.element) return;
|
17
|
+
this.element.down('tbody').insert('<tr><td>' + testName + '</td><td></td><td></td></tr>');
|
18
|
+
},
|
19
|
+
|
20
|
+
setStatus: function(status) {
|
21
|
+
this.getLastLogLine().addClassName(status).down('td', 1).update(status);
|
22
|
+
},
|
23
|
+
|
24
|
+
finish: function(status, summary) {
|
25
|
+
if (!this.element) return;
|
26
|
+
this.setStatus(status);
|
27
|
+
this.message(summary);
|
28
|
+
},
|
29
|
+
|
30
|
+
message: function(message) {
|
31
|
+
if (!this.element) return;
|
32
|
+
this.getMessageCell().update(this._toHTML(message));
|
33
|
+
},
|
34
|
+
|
35
|
+
summary: function(summary) {
|
36
|
+
if (!this.element) return;
|
37
|
+
this.element.down('div').update(this._toHTML(summary));
|
38
|
+
},
|
39
|
+
|
40
|
+
getLastLogLine: function() {
|
41
|
+
return this.element.select('tr').last()
|
42
|
+
},
|
43
|
+
|
44
|
+
getMessageCell: function() {
|
45
|
+
return this.getLastLogLine().down('td', 2);
|
46
|
+
},
|
47
|
+
|
48
|
+
_createLogTable: function() {
|
49
|
+
var html = '<div class="logsummary">running...</div>' +
|
50
|
+
'<table class="logtable">' +
|
51
|
+
'<thead><tr><th>Status</th><th>Test</th><th>Message</th></tr></thead>' +
|
52
|
+
'<tbody class="loglines"></tbody>' +
|
53
|
+
'</table>';
|
54
|
+
this.element.update(html);
|
55
|
+
|
56
|
+
},
|
57
|
+
|
58
|
+
appendActionButtons: function(actions) {
|
59
|
+
actions = $H(actions);
|
60
|
+
if (!actions.any()) return;
|
61
|
+
var div = new Element("div", {className: 'action_buttons'});
|
62
|
+
actions.inject(div, function(container, action) {
|
63
|
+
var button = new Element("input").setValue(action.key).observe("click", action.value);
|
64
|
+
button.type = "button";
|
65
|
+
return container.insert(button);
|
66
|
+
});
|
67
|
+
this.getMessageCell().insert(div);
|
68
|
+
},
|
69
|
+
|
70
|
+
_toHTML: function(txt) {
|
71
|
+
return txt.escapeHTML().replace(/\n/g,"<br/>");
|
72
|
+
}
|
73
|
+
});
|
74
|
+
|
75
|
+
// runner.js
|
76
|
+
Test.Unit.Runner = Class.create({
|
77
|
+
initialize: function(testcases) {
|
78
|
+
var options = this.options = Object.extend({
|
79
|
+
testLog: 'testlog'
|
80
|
+
}, arguments[1] || {});
|
81
|
+
|
82
|
+
options.resultsURL = this.queryParams.resultsURL;
|
83
|
+
options.testLog = $(options.testLog);
|
84
|
+
|
85
|
+
this.tests = this.getTests(testcases);
|
86
|
+
this.currentTest = 0;
|
87
|
+
this.logger = new Test.Unit.Logger(options.testLog);
|
88
|
+
Event.observe(window, "load", function() {
|
89
|
+
this.runTests.bind(this).delay(0.1);
|
90
|
+
}.bind(this));
|
91
|
+
},
|
92
|
+
|
93
|
+
queryParams: window.location.search.parseQuery(),
|
94
|
+
|
95
|
+
getTests: function(testcases) {
|
96
|
+
var tests, options = this.options;
|
97
|
+
if (this.queryParams.tests) tests = this.queryParams.tests.split(',');
|
98
|
+
else if (options.tests) tests = options.tests;
|
99
|
+
else if (options.test) tests = [option.test];
|
100
|
+
else tests = Object.keys(testcases).grep(/^test/);
|
101
|
+
|
102
|
+
return tests.map(function(test) {
|
103
|
+
if (testcases[test])
|
104
|
+
return new Test.Unit.Testcase(test, testcases[test], testcases.setup, testcases.teardown);
|
105
|
+
}).compact();
|
106
|
+
},
|
107
|
+
|
108
|
+
getResult: function() {
|
109
|
+
var results = {
|
110
|
+
tests: this.tests.length,
|
111
|
+
assertions: 0,
|
112
|
+
failures: 0,
|
113
|
+
errors: 0
|
114
|
+
};
|
115
|
+
|
116
|
+
return this.tests.inject(results, function(results, test) {
|
117
|
+
results.assertions += test.assertions;
|
118
|
+
results.failures += test.failures;
|
119
|
+
results.errors += test.errors;
|
120
|
+
return results;
|
121
|
+
});
|
122
|
+
},
|
123
|
+
|
124
|
+
postResults: function() {
|
125
|
+
if (this.options.resultsURL) {
|
126
|
+
new Ajax.Request(this.options.resultsURL,
|
127
|
+
{ method: 'get', parameters: this.getResult(), asynchronous: false });
|
128
|
+
}
|
129
|
+
},
|
130
|
+
|
131
|
+
runTests: function() {
|
132
|
+
var test = this.tests[this.currentTest], actions;
|
133
|
+
|
134
|
+
if (!test) return this.finish();
|
135
|
+
if (!test.isWaiting) this.logger.start(test.name);
|
136
|
+
test.run();
|
137
|
+
if(test.isWaiting) {
|
138
|
+
this.logger.message("Waiting for " + test.timeToWait + "ms");
|
139
|
+
setTimeout(this.runTests.bind(this), test.timeToWait || 1000);
|
140
|
+
return;
|
141
|
+
}
|
142
|
+
|
143
|
+
this.logger.finish(test.status(), test.summary());
|
144
|
+
if (actions = test.actions) this.logger.appendActionButtons(actions);
|
145
|
+
this.currentTest++;
|
146
|
+
// tail recursive, hopefully the browser will skip the stackframe
|
147
|
+
this.runTests();
|
148
|
+
},
|
149
|
+
|
150
|
+
finish: function() {
|
151
|
+
this.postResults();
|
152
|
+
this.logger.summary(this.summary());
|
153
|
+
},
|
154
|
+
|
155
|
+
summary: function() {
|
156
|
+
return '#{tests} tests, #{assertions} assertions, #{failures} failures, #{errors} errors'
|
157
|
+
.interpolate(this.getResult());
|
158
|
+
}
|
159
|
+
});
|
160
|
+
|
161
|
+
// message_template.js
|
162
|
+
Test.Unit.MessageTemplate = Class.create({
|
163
|
+
initialize: function(string) {
|
164
|
+
var parts = [];
|
165
|
+
(string || '').scan(/(?=[^\\])\?|(?:\\\?|[^\?])+/, function(part) {
|
166
|
+
parts.push(part[0]);
|
167
|
+
});
|
168
|
+
this.parts = parts;
|
169
|
+
},
|
170
|
+
|
171
|
+
evaluate: function(params) {
|
172
|
+
return this.parts.map(function(part) {
|
173
|
+
return part == '?' ? Test.Unit.inspect(params.shift()) : part.replace(/\\\?/, '?');
|
174
|
+
}).join('');
|
175
|
+
}
|
176
|
+
});
|
177
|
+
|
178
|
+
// assertions.js
|
179
|
+
Test.Unit.Assertions = {
|
180
|
+
buildMessage: function(message, template) {
|
181
|
+
var args = $A(arguments).slice(2);
|
182
|
+
return (message ? message + '\n' : '') + new Test.Unit.MessageTemplate(template).evaluate(args);
|
183
|
+
},
|
184
|
+
|
185
|
+
flunk: function(message) {
|
186
|
+
this.assertBlock(message || 'Flunked', function() { return false });
|
187
|
+
},
|
188
|
+
|
189
|
+
assertBlock: function(message, block) {
|
190
|
+
try {
|
191
|
+
block.call(this) ? this.pass() : this.fail(message);
|
192
|
+
} catch(e) { this.error(e) }
|
193
|
+
},
|
194
|
+
|
195
|
+
assert: function(expression, message) {
|
196
|
+
message = this.buildMessage(message || 'assert', 'got <?>', expression);
|
197
|
+
this.assertBlock(message, function() { return expression });
|
198
|
+
},
|
199
|
+
|
200
|
+
assertEqual: function(expected, actual, message) {
|
201
|
+
message = this.buildMessage(message || 'assertEqual', 'expected <?>, actual: <?>', expected, actual);
|
202
|
+
this.assertBlock(message, function() { return expected == actual });
|
203
|
+
},
|
204
|
+
|
205
|
+
assertNotEqual: function(expected, actual, message) {
|
206
|
+
message = this.buildMessage(message || 'assertNotEqual', 'expected <?>, actual: <?>', expected, actual);
|
207
|
+
this.assertBlock(message, function() { return expected != actual });
|
208
|
+
},
|
209
|
+
|
210
|
+
assertEnumEqual: function(expected, actual, message) {
|
211
|
+
expected = $A(expected);
|
212
|
+
actual = $A(actual);
|
213
|
+
message = this.buildMessage(message || 'assertEnumEqual', 'expected <?>, actual: <?>', expected, actual);
|
214
|
+
this.assertBlock(message, function() {
|
215
|
+
return expected.length == actual.length && expected.zip(actual).all(function(pair) { return pair[0] == pair[1] });
|
216
|
+
});
|
217
|
+
},
|
218
|
+
|
219
|
+
assertEnumNotEqual: function(expected, actual, message) {
|
220
|
+
expected = $A(expected);
|
221
|
+
actual = $A(actual);
|
222
|
+
message = this.buildMessage(message || 'assertEnumNotEqual', '<?> was the same as <?>', expected, actual);
|
223
|
+
this.assertBlock(message, function() {
|
224
|
+
return expected.length != actual.length || expected.zip(actual).any(function(pair) { return pair[0] != pair[1] });
|
225
|
+
});
|
226
|
+
},
|
227
|
+
|
228
|
+
assertHashEqual: function(expected, actual, message) {
|
229
|
+
expected = $H(expected);
|
230
|
+
actual = $H(actual);
|
231
|
+
var expected_array = expected.toArray().sort(), actual_array = actual.toArray().sort();
|
232
|
+
message = this.buildMessage(message || 'assertHashEqual', 'expected <?>, actual: <?>', expected, actual);
|
233
|
+
// from now we recursively zip & compare nested arrays
|
234
|
+
var block = function() {
|
235
|
+
return expected_array.length == actual_array.length &&
|
236
|
+
expected_array.zip(actual_array).all(function(pair) {
|
237
|
+
return pair.all(Object.isArray) ?
|
238
|
+
pair[0].zip(pair[1]).all(arguments.callee) : pair[0] == pair[1];
|
239
|
+
});
|
240
|
+
};
|
241
|
+
this.assertBlock(message, block);
|
242
|
+
},
|
243
|
+
|
244
|
+
assertHashNotEqual: function(expected, actual, message) {
|
245
|
+
expected = $H(expected);
|
246
|
+
actual = $H(actual);
|
247
|
+
var expected_array = expected.toArray().sort(), actual_array = actual.toArray().sort();
|
248
|
+
message = this.buildMessage(message || 'assertHashNotEqual', '<?> was the same as <?>', expected, actual);
|
249
|
+
// from now we recursively zip & compare nested arrays
|
250
|
+
var block = function() {
|
251
|
+
return !(expected_array.length == actual_array.length &&
|
252
|
+
expected_array.zip(actual_array).all(function(pair) {
|
253
|
+
return pair.all(Object.isArray) ?
|
254
|
+
pair[0].zip(pair[1]).all(arguments.callee) : pair[0] == pair[1];
|
255
|
+
}));
|
256
|
+
};
|
257
|
+
this.assertBlock(message, block);
|
258
|
+
},
|
259
|
+
|
260
|
+
assertIdentical: function(expected, actual, message) {
|
261
|
+
message = this.buildMessage(message || 'assertIdentical', 'expected <?>, actual: <?>', expected, actual);
|
262
|
+
this.assertBlock(message, function() { return expected === actual });
|
263
|
+
},
|
264
|
+
|
265
|
+
assertNotIdentical: function(expected, actual, message) {
|
266
|
+
message = this.buildMessage(message || 'assertNotIdentical', 'expected <?>, actual: <?>', expected, actual);
|
267
|
+
this.assertBlock(message, function() { return expected !== actual });
|
268
|
+
},
|
269
|
+
|
270
|
+
assertNull: function(obj, message) {
|
271
|
+
message = this.buildMessage(message || 'assertNull', 'got <?>', obj);
|
272
|
+
this.assertBlock(message, function() { return obj === null });
|
273
|
+
},
|
274
|
+
|
275
|
+
assertNotNull: function(obj, message) {
|
276
|
+
message = this.buildMessage(message || 'assertNotNull', 'got <?>', obj);
|
277
|
+
this.assertBlock(message, function() { return obj !== null });
|
278
|
+
},
|
279
|
+
|
280
|
+
assertUndefined: function(obj, message) {
|
281
|
+
message = this.buildMessage(message || 'assertUndefined', 'got <?>', obj);
|
282
|
+
this.assertBlock(message, function() { return typeof obj == "undefined" });
|
283
|
+
},
|
284
|
+
|
285
|
+
assertNotUndefined: function(obj, message) {
|
286
|
+
message = this.buildMessage(message || 'assertNotUndefined', 'got <?>', obj);
|
287
|
+
this.assertBlock(message, function() { return typeof obj != "undefined" });
|
288
|
+
},
|
289
|
+
|
290
|
+
assertNullOrUndefined: function(obj, message) {
|
291
|
+
message = this.buildMessage(message || 'assertNullOrUndefined', 'got <?>', obj);
|
292
|
+
this.assertBlock(message, function() { return obj == null });
|
293
|
+
},
|
294
|
+
|
295
|
+
assertNotNullOrUndefined: function(obj, message) {
|
296
|
+
message = this.buildMessage(message || 'assertNotNullOrUndefined', 'got <?>', obj);
|
297
|
+
this.assertBlock(message, function() { return obj != null });
|
298
|
+
},
|
299
|
+
|
300
|
+
assertMatch: function(expected, actual, message) {
|
301
|
+
message = this.buildMessage(message || 'assertMatch', 'regex <?> did not match <?>', expected, actual);
|
302
|
+
this.assertBlock(message, function() { return new RegExp(expected).exec(actual) });
|
303
|
+
},
|
304
|
+
|
305
|
+
assertNoMatch: function(expected, actual, message) {
|
306
|
+
message = this.buildMessage(message || 'assertNoMatch', 'regex <?> matched <?>', expected, actual);
|
307
|
+
this.assertBlock(message, function() { return !(new RegExp(expected).exec(actual)) });
|
308
|
+
},
|
309
|
+
|
310
|
+
assertHidden: function(element, message) {
|
311
|
+
message = this.buildMessage(message || 'assertHidden', '? isn\'t hidden.', element);
|
312
|
+
this.assertBlock(message, function() { return element.style.display == 'none' });
|
313
|
+
},
|
314
|
+
|
315
|
+
assertInstanceOf: function(expected, actual, message) {
|
316
|
+
message = this.buildMessage(message || 'assertInstanceOf', '<?> was not an instance of the expected type', actual);
|
317
|
+
this.assertBlock(message, function() { return actual instanceof expected });
|
318
|
+
},
|
319
|
+
|
320
|
+
assertNotInstanceOf: function(expected, actual, message) {
|
321
|
+
message = this.buildMessage(message || 'assertNotInstanceOf', '<?> was an instance of the expected type', actual);
|
322
|
+
this.assertBlock(message, function() { return !(actual instanceof expected) });
|
323
|
+
},
|
324
|
+
|
325
|
+
assertRespondsTo: function(method, obj, message) {
|
326
|
+
message = this.buildMessage(message || 'assertRespondsTo', 'object doesn\'t respond to <?>', method);
|
327
|
+
this.assertBlock(message, function() { return (method in obj && typeof obj[method] == 'function') });
|
328
|
+
},
|
329
|
+
|
330
|
+
assertRaise: function(exceptionName, method, message) {
|
331
|
+
message = this.buildMessage(message || 'assertRaise', '<?> exception expected but none was raised', exceptionName);
|
332
|
+
var block = function() {
|
333
|
+
try {
|
334
|
+
method();
|
335
|
+
return false;
|
336
|
+
} catch(e) {
|
337
|
+
if (e.name == exceptionName) return true;
|
338
|
+
else throw e;
|
339
|
+
}
|
340
|
+
};
|
341
|
+
this.assertBlock(message, block);
|
342
|
+
},
|
343
|
+
|
344
|
+
assertNothingRaised: function(method, message) {
|
345
|
+
try {
|
346
|
+
method();
|
347
|
+
this.assert(true, "Expected nothing to be thrown");
|
348
|
+
} catch(e) {
|
349
|
+
message = this.buildMessage(message || 'assertNothingRaised', '<?> was thrown when nothing was expected.', e);
|
350
|
+
this.flunk(message);
|
351
|
+
}
|
352
|
+
},
|
353
|
+
|
354
|
+
_isVisible: function(element) {
|
355
|
+
element = $(element);
|
356
|
+
if(!element.parentNode) return true;
|
357
|
+
this.assertNotNull(element);
|
358
|
+
if(element.style && Element.getStyle(element, 'display') == 'none')
|
359
|
+
return false;
|
360
|
+
|
361
|
+
return arguments.callee.call(this, element.parentNode);
|
362
|
+
},
|
363
|
+
|
364
|
+
assertVisible: function(element, message) {
|
365
|
+
message = this.buildMessage(message, '? was not visible.', element);
|
366
|
+
this.assertBlock(message, function() { return this._isVisible(element) });
|
367
|
+
},
|
368
|
+
|
369
|
+
assertNotVisible: function(element, message) {
|
370
|
+
message = this.buildMessage(message, '? was not hidden and didn\'t have a hidden parent either.', element);
|
371
|
+
this.assertBlock(message, function() { return !this._isVisible(element) });
|
372
|
+
},
|
373
|
+
|
374
|
+
assertElementsMatch: function() {
|
375
|
+
var pass = true, expressions = $A(arguments), elements = $A(expressions.shift());
|
376
|
+
if (elements.length != expressions.length) {
|
377
|
+
message = this.buildMessage('assertElementsMatch', 'size mismatch: ? elements, ? expressions (?).', elements.length, expressions.length, expressions);
|
378
|
+
this.flunk(message);
|
379
|
+
pass = false;
|
380
|
+
}
|
381
|
+
elements.zip(expressions).all(function(pair, index) {
|
382
|
+
var element = $(pair.first()), expression = pair.last();
|
383
|
+
if (element.match(expression)) return true;
|
384
|
+
message = this.buildMessage('assertElementsMatch', 'In index <?>: expected <?> but got ?', index, expression, element);
|
385
|
+
this.flunk(message);
|
386
|
+
pass = false;
|
387
|
+
}.bind(this))
|
388
|
+
|
389
|
+
if (pass) this.assert(true, "Expected all elements to match.");
|
390
|
+
},
|
391
|
+
|
392
|
+
assertElementMatches: function(element, expression, message) {
|
393
|
+
this.assertElementsMatch([element], expression);
|
394
|
+
}
|
395
|
+
};
|
396
|
+
|
397
|
+
// test_case.js
|
398
|
+
Test.Unit.Testcase = Class.create(Test.Unit.Assertions, {
|
399
|
+
initialize: function(name, test, setup, teardown) {
|
400
|
+
this.name = name;
|
401
|
+
this.test = test || Prototype.emptyFunction;
|
402
|
+
this.setup = setup || Prototype.emptyFunction;
|
403
|
+
this.teardown = teardown || Prototype.emptyFunction;
|
404
|
+
this.messages = [];
|
405
|
+
this.actions = {};
|
406
|
+
},
|
407
|
+
|
408
|
+
isWaiting: false,
|
409
|
+
timeToWait: 1000,
|
410
|
+
assertions: 0,
|
411
|
+
failures: 0,
|
412
|
+
errors: 0,
|
413
|
+
isRunningFromRake: window.location.port == 4711,
|
414
|
+
|
415
|
+
wait: function(time, nextPart) {
|
416
|
+
this.isWaiting = true;
|
417
|
+
this.test = nextPart;
|
418
|
+
this.timeToWait = time;
|
419
|
+
},
|
420
|
+
|
421
|
+
run: function(rethrow) {
|
422
|
+
try {
|
423
|
+
try {
|
424
|
+
if (!this.isWaiting) this.setup();
|
425
|
+
this.isWaiting = false;
|
426
|
+
this.test();
|
427
|
+
} finally {
|
428
|
+
if(!this.isWaiting) {
|
429
|
+
this.teardown();
|
430
|
+
}
|
431
|
+
}
|
432
|
+
}
|
433
|
+
catch(e) {
|
434
|
+
if (rethrow) throw e;
|
435
|
+
this.error(e, this);
|
436
|
+
}
|
437
|
+
},
|
438
|
+
|
439
|
+
summary: function() {
|
440
|
+
var msg = '#{assertions} assertions, #{failures} failures, #{errors} errors\n';
|
441
|
+
return msg.interpolate(this) + this.messages.join("\n");
|
442
|
+
},
|
443
|
+
|
444
|
+
pass: function() {
|
445
|
+
this.assertions++;
|
446
|
+
},
|
447
|
+
|
448
|
+
fail: function(message) {
|
449
|
+
this.failures++;
|
450
|
+
var line = "";
|
451
|
+
try {
|
452
|
+
throw new Error("stack");
|
453
|
+
} catch(e){
|
454
|
+
line = (/\.html:(\d+)/.exec(e.stack || '') || ['',''])[1];
|
455
|
+
}
|
456
|
+
this.messages.push("Failure: " + message + (line ? " Line #" + line : ""));
|
457
|
+
},
|
458
|
+
|
459
|
+
info: function(message) {
|
460
|
+
this.messages.push("Info: " + message);
|
461
|
+
},
|
462
|
+
|
463
|
+
error: function(error, test) {
|
464
|
+
this.errors++;
|
465
|
+
this.actions['retry with throw'] = function() { test.run(true) };
|
466
|
+
this.messages.push(error.name + ": "+ error.message + "(" + Test.inspect(error) + ")");
|
467
|
+
},
|
468
|
+
|
469
|
+
status: function() {
|
470
|
+
if (this.failures > 0) return 'failed';
|
471
|
+
if (this.errors > 0) return 'error';
|
472
|
+
return 'passed';
|
473
|
+
},
|
474
|
+
|
475
|
+
benchmark: function(operation, iterations) {
|
476
|
+
var startAt = new Date();
|
477
|
+
(iterations || 1).times(operation);
|
478
|
+
var timeTaken = ((new Date())-startAt);
|
479
|
+
this.info((arguments[2] || 'Operation') + ' finished ' +
|
480
|
+
iterations + ' iterations in ' + (timeTaken/1000)+'s' );
|
481
|
+
return timeTaken;
|
482
|
+
}
|
483
|
+
});
|
484
|
+
|