newjs 1.5.1 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (184) hide show
  1. data/History.txt +11 -0
  2. data/Manifest.txt +162 -14
  3. data/{README.txt → README.rdoc} +1 -1
  4. data/Rakefile +25 -3
  5. data/app_generators/newjs_iphone/templates/Html/test/assets/jsunittest.js +41 -13
  6. data/app_generators/newjs_iphone/templates/Html/test/assets/unittest.css +4 -0
  7. data/features/development.feature +13 -0
  8. data/features/imported_files_for_generators.feature +19 -0
  9. data/features/steps/common.rb +205 -0
  10. data/features/steps/env.rb +6 -0
  11. data/javascript_test_generators/functional_test/functional_test_generator.rb +9 -1
  12. data/javascript_test_generators/functional_test/templates/test/assets/jshoulda.js +186 -0
  13. data/javascript_test_generators/functional_test/templates/test/test.html.erb +15 -1
  14. data/javascript_test_generators/unit_test/templates/test/assets/jshoulda.js +186 -0
  15. data/javascript_test_generators/unit_test/templates/test/test.html.erb +18 -20
  16. data/javascript_test_generators/unit_test/templates/test/test_jshoulda.html.erb +45 -0
  17. data/javascript_test_generators/unit_test/unit_test_generator.rb +11 -3
  18. data/lib/newjs.rb +3 -2
  19. data/newjs_iphone_generators/page/USAGE +5 -0
  20. data/newjs_iphone_generators/page/page_generator.rb +36 -0
  21. data/newjs_iphone_generators/page/templates/src/name.css.erb +0 -0
  22. data/newjs_iphone_generators/page/templates/src/name.html.erb +13 -0
  23. data/newjs_iphone_generators/page/templates/src/name.js.erb +4 -0
  24. data/newjs_iphone_generators/page/templates/test/fixtures/name.js.erb +5 -0
  25. data/newjs_iphone_generators/page/templates/test/unit/name_test.html.erb +61 -0
  26. data/rack_generators/javascript_test/USAGE +5 -0
  27. data/rack_generators/javascript_test/javascript_test_generator.rb +88 -0
  28. data/rack_generators/javascript_test/templates/assets/jshoulda.js +186 -0
  29. data/rack_generators/javascript_test/templates/assets/jsunittest.js +1004 -0
  30. data/rack_generators/javascript_test/templates/assets/unittest.css +54 -0
  31. data/rack_generators/javascript_test/templates/ext/jquery.js +3408 -0
  32. data/{app_generators/newjs_iphone/templates/Html/test/assets → rack_generators/javascript_test/templates/ext}/prototype.js +56 -122
  33. data/rack_generators/javascript_test/templates/library.js.erb +3 -0
  34. data/rack_generators/javascript_test/templates/test.html.erb +59 -0
  35. data/rack_generators/javascript_test/templates/test_jshoulda.html.erb +48 -0
  36. data/rails_generators/javascript_test/javascript_test_generator.rb +15 -3
  37. data/rails_generators/javascript_test/templates/assets/jshoulda.js +186 -0
  38. data/rails_generators/javascript_test/templates/test_jshoulda.html.erb +48 -0
  39. data/script/console +10 -0
  40. data/script/destroy +1 -1
  41. data/tasks/vendor/update/jshoulda.rake +18 -0
  42. data/tasks/vendor/update/jsunittest.rake +18 -0
  43. data/test/test_functional_test_generator.rb +13 -0
  44. data/test/test_generator_helper.rb +10 -1
  45. data/test/test_page_generator.rb +50 -0
  46. data/test/test_rack_javascript_test.rb +166 -0
  47. data/test/{test_javascript_test_generator.rb → test_rails_javascript_test_generator.rb} +15 -1
  48. data/test/test_unit_test_generator.rb +13 -0
  49. data/vendor/jshoulda/History.txt +108 -0
  50. data/vendor/jshoulda/License.txt +20 -0
  51. data/vendor/jshoulda/README.mdown +34 -0
  52. data/vendor/jshoulda/Rakefile +120 -0
  53. data/vendor/jshoulda/config/javascript_test_autotest.yml.sample +15 -0
  54. data/vendor/jshoulda/dist/jshoulda-0.0.1.js +62 -0
  55. data/vendor/jshoulda/dist/jshoulda-0.0.2.js +72 -0
  56. data/vendor/jshoulda/dist/jshoulda-0.0.3.js +72 -0
  57. data/vendor/jshoulda/dist/jshoulda-1.0.1.js +74 -0
  58. data/vendor/jshoulda/dist/jshoulda-1.0.js +72 -0
  59. data/vendor/jshoulda/dist/jshoulda-1.1.js +110 -0
  60. data/vendor/jshoulda/dist/jshoulda-1.2.1.js +186 -0
  61. data/vendor/jshoulda/dist/jshoulda-1.2.js +141 -0
  62. data/vendor/jshoulda/dist/jshoulda-1.2.x.js +142 -0
  63. data/vendor/jshoulda/dist/jshoulda.js +186 -0
  64. data/vendor/jshoulda/jshoulda/test/basic_test.html +42 -0
  65. data/vendor/jshoulda/lib/jstest.rb +382 -0
  66. data/vendor/jshoulda/lib/protodoc.rb +36 -0
  67. data/vendor/jshoulda/script/destroy +14 -0
  68. data/vendor/jshoulda/script/generate +14 -0
  69. data/vendor/jshoulda/script/js_autotest +1 -0
  70. data/vendor/jshoulda/script/rstakeout +97 -0
  71. data/vendor/jshoulda/site/asset_defaults.yaml +6 -0
  72. data/vendor/jshoulda/site/config.yaml +3 -0
  73. data/vendor/jshoulda/site/content/content.html +27 -0
  74. data/vendor/jshoulda/site/content/content.yaml +4 -0
  75. data/vendor/jshoulda/site/content/tutorial/tutorial.html +268 -0
  76. data/vendor/jshoulda/site/content/tutorial/tutorial.yaml +4 -0
  77. data/vendor/jshoulda/site/css/blackboard.css +88 -0
  78. data/vendor/jshoulda/site/css/jshoulda_site.css +33 -0
  79. data/vendor/jshoulda/site/css/unittest.css +42 -0
  80. data/vendor/jshoulda/site/example/minimal.html +55 -0
  81. data/vendor/jshoulda/site/js/editable.js +42 -0
  82. data/vendor/jshoulda/site/layouts/default/default.html +29 -0
  83. data/vendor/jshoulda/site/layouts/default/default.yaml +4 -0
  84. data/vendor/jshoulda/site/layouts/home_test/home_test.js +18 -0
  85. data/vendor/jshoulda/site/layouts/home_test/home_test.yaml +4 -0
  86. data/vendor/jshoulda/site/lib/analytics.rb +12 -0
  87. data/vendor/jshoulda/site/lib/default.rb +2 -0
  88. data/vendor/jshoulda/site/lib/example.rb +10 -0
  89. data/vendor/jshoulda/site/lib/hash.rb +11 -0
  90. data/vendor/jshoulda/site/lib/highlight.rb +17 -0
  91. data/vendor/jshoulda/site/page_defaults.yaml +10 -0
  92. data/vendor/jshoulda/site/templates/default/default.html +1 -0
  93. data/vendor/jshoulda/site/templates/default/default.yaml +4 -0
  94. data/vendor/jshoulda/src/HEADER +8 -0
  95. data/vendor/jshoulda/src/jshoulda.js +177 -0
  96. data/vendor/jshoulda/src/jshoulda.js.erb +3 -0
  97. data/vendor/jshoulda/tasks/bundle.rake +12 -0
  98. data/vendor/jshoulda/tasks/demo.rake +9 -0
  99. data/vendor/jshoulda/tasks/deploy.rake +29 -0
  100. data/{tasks → vendor/jshoulda/tasks}/environment.rake +0 -0
  101. data/vendor/jshoulda/tasks/javascript_test_autotest_tasks.rake +45 -0
  102. data/vendor/jshoulda/tasks/site.rake +74 -0
  103. data/vendor/jshoulda/test/assets/jsunittest.js +1004 -0
  104. data/vendor/jshoulda/test/assets/prototype.js +4324 -0
  105. data/{app_generators/newjs_iphone/templates/Html/test/assets/unittest.js → vendor/jshoulda/test/assets/prototype_unittest.js} +15 -9
  106. data/vendor/jshoulda/test/assets/unittest.css +50 -0
  107. data/vendor/jshoulda/test/unit/factory_test.html +82 -0
  108. data/vendor/jshoulda/test/unit/jshoulda2_test.html +85 -0
  109. data/vendor/jshoulda/test/unit/jshoulda_prototype_test.html +87 -0
  110. data/vendor/jshoulda/test/unit/jshoulda_test.html +86 -0
  111. data/vendor/jshoulda/test/unit/merge_methods_test.html +77 -0
  112. data/vendor/jshoulda/test/unit/names_and_count.html +68 -0
  113. data/vendor/jshoulda/test/unit/no_config_test.html +57 -0
  114. data/vendor/jshoulda/test/unit/styles_test.html +77 -0
  115. data/vendor/jshoulda/test/unit/unify_runners.html +69 -0
  116. data/vendor/jshoulda/test/unit/unnamed_context_test.html +67 -0
  117. data/vendor/jsunittest/Capfile +4 -0
  118. data/vendor/jsunittest/History.txt +37 -0
  119. data/{License.txt → vendor/jsunittest/License.txt} +0 -0
  120. data/vendor/jsunittest/README.txt +21 -0
  121. data/vendor/jsunittest/Rakefile +118 -0
  122. data/vendor/jsunittest/config/deploy.rb +20 -0
  123. data/vendor/jsunittest/config/website.yml.sample +2 -0
  124. data/vendor/jsunittest/dist/jsunittest-0.7.2.js +1004 -0
  125. data/vendor/jsunittest/dist/jsunittest.js +1004 -0
  126. data/vendor/jsunittest/dist/unittest.css +54 -0
  127. data/vendor/jsunittest/lib/jstest.rb +390 -0
  128. data/vendor/jsunittest/lib/protodoc.rb +36 -0
  129. data/vendor/jsunittest/script/destroy +14 -0
  130. data/vendor/jsunittest/script/generate +14 -0
  131. data/vendor/jsunittest/script/js_autotest +1 -0
  132. data/vendor/jsunittest/script/rstakeout +97 -0
  133. data/vendor/jsunittest/script/txt2html +75 -0
  134. data/vendor/jsunittest/src/HEADER +8 -0
  135. data/vendor/jsunittest/src/ajax.js +121 -0
  136. data/vendor/jsunittest/src/assertions.js +244 -0
  137. data/vendor/jsunittest/src/common.js +191 -0
  138. data/vendor/jsunittest/src/jsunittest.js +1004 -0
  139. data/vendor/jsunittest/src/logger.js +86 -0
  140. data/vendor/jsunittest/src/message_template.js +17 -0
  141. data/vendor/jsunittest/src/orig/unittest.js +484 -0
  142. data/vendor/jsunittest/src/prototype/event.js +72 -0
  143. data/vendor/jsunittest/src/prototype/template.js +33 -0
  144. data/vendor/jsunittest/src/runner.js +120 -0
  145. data/vendor/jsunittest/src/test_case.js +106 -0
  146. data/vendor/jsunittest/tasks/deploy.rake +29 -0
  147. data/vendor/jsunittest/tasks/environment.rake +7 -0
  148. data/vendor/jsunittest/tasks/javascript_test_autotest_tasks.rake +44 -0
  149. data/vendor/jsunittest/tasks/tmbundle.rake +24 -0
  150. data/vendor/jsunittest/tasks/website.rake +53 -0
  151. data/vendor/jsunittest/test/assets/example_test.html +50 -0
  152. data/{app_generators/newjs/templates → vendor/jsunittest}/test/assets/prototype.js +0 -0
  153. data/vendor/jsunittest/test/assets/unittest.css +54 -0
  154. data/{app_generators/newjs/templates → vendor/jsunittest}/test/assets/unittest.js +0 -0
  155. data/vendor/jsunittest/test/functional/jsunittest_test.html +209 -0
  156. data/vendor/jsunittest/test/unit/assertions_test.html +202 -0
  157. data/vendor/jsunittest/test/unit/common_test.html +61 -0
  158. data/vendor/jsunittest/test/unit/logger_test.html +98 -0
  159. data/vendor/jsunittest/test/unit/message_template_test.html +44 -0
  160. data/vendor/jsunittest/test/unit/runner_test.html +77 -0
  161. data/vendor/jsunittest/test/unit/template_test.html +57 -0
  162. data/vendor/jsunittest/test/unit/test_case_test.html +97 -0
  163. data/vendor/jsunittest/website/dist/jsunittest-0.7.2.js +1004 -0
  164. data/vendor/jsunittest/website/dist/jsunittest-getting-started.tar.gz +0 -0
  165. data/vendor/jsunittest/website/dist/jsunittest-getting-started.zip +0 -0
  166. data/vendor/jsunittest/website/dist/jsunittest-getting-started/assets/jsunittest.js +1004 -0
  167. data/vendor/jsunittest/website/dist/jsunittest-getting-started/assets/unittest.css +54 -0
  168. data/vendor/jsunittest/website/dist/jsunittest-getting-started/example_test.html +50 -0
  169. data/vendor/jsunittest/website/dist/jsunittest.js +1004 -0
  170. data/vendor/jsunittest/website/images/logo_bundle.png +0 -0
  171. data/vendor/jsunittest/website/images/passing_prototypejs_unittest_tests.jpg +0 -0
  172. data/vendor/jsunittest/website/index.html +94 -0
  173. data/vendor/jsunittest/website/index.txt +80 -0
  174. data/vendor/jsunittest/website/javascripts/rounded_corners_lite.inc.js +285 -0
  175. data/vendor/jsunittest/website/stylesheets/screen.css +138 -0
  176. data/vendor/jsunittest/website/template.html.erb +46 -0
  177. data/vendor/jsunittest/website/tmbundle/JavaScript Unit Testing.tmbundle.tar.gz +0 -0
  178. metadata +189 -24
  179. data/config/hoe.rb +0 -75
  180. data/config/requirements.rb +0 -17
  181. data/lib/newjs/version.rb +0 -9
  182. data/tasks/deployment.rake +0 -34
  183. data/tasks/jsunittest/update.rake +0 -18
  184. data/tasks/website.rake +0 -17
@@ -0,0 +1,110 @@
1
+ /* jShoulda, version 1.1
2
+ * (c) 2008 Choan Galvez
3
+ *
4
+ * jShoulda is freely distributable under
5
+ * the terms of an MIT-style license.
6
+ * For details, see the web site: http://jshoulda.scriptia.net
7
+ *
8
+ *--------------------------------------------------------------------------*/
9
+
10
+ var jShoulda = function() {
11
+ // the test runner
12
+ var tr;
13
+
14
+ function dummy() {
15
+ };
16
+
17
+ function runQueue(queue, name, before, after) {
18
+ var i, tests;
19
+ for (i = 0; i < queue.length; i += 1) {
20
+ tests = queue[i](name, before, after);
21
+ if (tests)
22
+ tr.tests.push(tests);
23
+ }
24
+ before.pop();
25
+ after.pop();
26
+ }
27
+
28
+ function makeBatch(fn_a) {
29
+ var copy = fn_a.slice(0);
30
+ return function() {
31
+ for (var i = 0; i < copy.length; i += 1) {
32
+ copy[i].call(this);
33
+ }
34
+ };
35
+ }
36
+
37
+ function context(name) {
38
+ var queue = Array.prototype.slice.call(arguments, 1);
39
+ var obj = {};
40
+ // shift arguments if the second one is a
41
+ // configuration object
42
+ if (typeof arguments[1] === 'object') {
43
+ obj = queue.shift();
44
+ }
45
+ obj.before = obj.setup || obj.before || dummy;
46
+ obj.after = obj.teardown || obj.after || dummy;
47
+ var beforeQueue;
48
+ var afterQueue;
49
+ return function(outerName, before, after) {
50
+ // the root context gets no outerName or a configuration object
51
+ // as its first argument
52
+ var prefix = outerName;
53
+ var is_root = !!(outerName == undefined || typeof outerName == 'object');
54
+ if (is_root) {
55
+ tr = new Test.Unit.Runner({}, outerName || {});
56
+ prefix = '';
57
+ }
58
+ beforeQueue = before ? before.push(obj.before) && before : [obj.before];
59
+ afterQueue = after ? after.push(obj.after) && after : [obj.after];
60
+ runQueue(queue, [prefix, name].join(' '), beforeQueue, afterQueue);
61
+ if (is_root) {
62
+ return tr;
63
+ }
64
+ return false; // do not add to the tests queue
65
+ };
66
+ };
67
+
68
+
69
+ function getShouldAlias(connector) {
70
+ return function (name, fn) {
71
+ return function(prefix, before, after) {
72
+ var beforeBatch = makeBatch(before);
73
+ var afterBatch = makeBatch(after);
74
+ return new Test.Unit.Testcase([prefix, name].join(' ' + connector + ' '), fn, beforeBatch, afterBatch);
75
+ };
76
+ };
77
+ }
78
+
79
+ function setShouldAlias(name, host) {
80
+ var connector = name;
81
+ if (typeof host == 'string') {
82
+ connector = host;
83
+ host = arguments[2];
84
+ }
85
+ host = host || window;
86
+ host[name] = getShouldAlias(connector);
87
+ return jShoulda;
88
+ }
89
+
90
+ function setContextAlias(name, host) {
91
+ host = host || window;
92
+ host[name] = getContextAlias();
93
+ return jShoulda;
94
+ }
95
+
96
+ function getContextAlias() {
97
+ return context;
98
+ }
99
+
100
+
101
+ return {
102
+ setShouldAlias : setShouldAlias,
103
+ setContextAlias : setContextAlias,
104
+ }
105
+
106
+ }();
107
+
108
+ jShoulda
109
+ .setShouldAlias('should')
110
+ .setContextAlias('context');
@@ -0,0 +1,186 @@
1
+ /* jShoulda, version 1.2.1
2
+ * (c) 2008 Choan Galvez
3
+ *
4
+ * jShoulda is freely distributable under
5
+ * the terms of an MIT-style license.
6
+ * For details, see the web site: http://jshoulda.scriptia.net
7
+ *
8
+ *--------------------------------------------------------------------------*/
9
+
10
+ var jShoulda = function() {
11
+ // the test runner
12
+ var tr,
13
+ // handle all testcases with the same testrunner
14
+ unique = false,
15
+ // styles definitions
16
+ styles = {};
17
+
18
+ function dummy() {
19
+ };
20
+
21
+ function runQueue(queue, name, before, after, ext) {
22
+ var i, tests;
23
+ for (i = 0; i < queue.length; i += 1) {
24
+ tests = queue[i](name, before, after, ext);
25
+ if (tests)
26
+ tr.tests.push(tests);
27
+ }
28
+ before.pop();
29
+ after.pop();
30
+ }
31
+
32
+ function makeBatch(fn_a) {
33
+ var copy = fn_a.slice(0);
34
+ return function() {
35
+ for (var i = 0; i < copy.length; i += 1) {
36
+ copy[i].call(this);
37
+ }
38
+ };
39
+ }
40
+
41
+ function getContextAlias(prefix) {
42
+ if (prefix) prefix += ' ';
43
+ return function (name, config, args) {
44
+ var queue = Array.prototype.slice.call(arguments, 0);
45
+ var cName = '';
46
+ var obj = {};
47
+ // shift arguments if the first one is a string
48
+ if (typeof queue[0] == 'string') {
49
+ if (name) { cName += prefix; }
50
+ cName += queue.shift();
51
+ }
52
+ if (typeof queue[0] === 'object') {
53
+ obj = queue.shift();
54
+ }
55
+
56
+ obj.before = obj.setup || obj.before || dummy;
57
+ obj.after = obj.teardown || obj.after || dummy;
58
+ var beforeQueue;
59
+ var afterQueue;
60
+ var extensions = merge({}, obj || {});
61
+
62
+ return function(outerName, before, after, ext) {
63
+ // the root context gets no outerName or a configuration object
64
+ // as its first argument
65
+ var prefix = outerName;
66
+ var is_root = !!(outerName == undefined || typeof outerName == 'object');
67
+ if (is_root) {
68
+ tr = (tr && unique) ? tr : new Test.Unit.Runner({}, outerName || {});
69
+ prefix = '';
70
+ }
71
+ // shift arguments if the second one is a
72
+ // configuration object
73
+ beforeQueue = before ? before.push(obj.before) && before : [obj.before];
74
+ afterQueue = after ? after.push(obj.after) && after : [obj.after];
75
+ runQueue(queue, [prefix, cName].join(' ').replace(/^\s+/, ''), beforeQueue, afterQueue, merge(extensions, ext));
76
+ if (is_root) {
77
+ return tr;
78
+ }
79
+ return false; // do not add to the tests queue
80
+ };
81
+ };
82
+ };
83
+
84
+ function merge(sub, sup) {
85
+ for (var i in sup) {
86
+ if (i.search(/^(before|after|setup|teardown)$/) != -1) continue;
87
+ if (sup.hasOwnProperty(i)) {
88
+ sub[i] = sup[i];
89
+ }
90
+ }
91
+ return sub;
92
+ }
93
+
94
+
95
+ function getShouldAlias(connector) {
96
+ return function (name, fn) {
97
+ return function(prefix, before, after, extensions) {
98
+ var beforeBatch = makeBatch(before);
99
+ var afterBatch = makeBatch(after);
100
+ var unit = new Test.Unit.Testcase([prefix, name].join(' ' + connector + ' '), fn, beforeBatch, afterBatch);
101
+ merge(unit, extensions);
102
+ return unit;
103
+ };
104
+ };
105
+ }
106
+
107
+ function setShouldAlias(name, host) {
108
+ var connector = name;
109
+ if (typeof host == 'string') {
110
+ connector = host;
111
+ host = arguments[2];
112
+ }
113
+ host = host || window;
114
+ host[name] = getShouldAlias(connector);
115
+ return jShoulda;
116
+ }
117
+
118
+ function setContextAlias(name, host) {
119
+ var prefix = '';
120
+ if (typeof host == 'string') {
121
+ prefix = host;
122
+ host = arguments[2];
123
+ }
124
+ host = host || window;
125
+ host[name] = getContextAlias(prefix);
126
+ return jShoulda;
127
+ }
128
+
129
+ function useStyle(name) {
130
+ var style, i;
131
+ if (name in styles) {
132
+ style = styles[name];
133
+ if ('context' in style) {
134
+ for (i = 0; i < style.context.length; i += 2) {
135
+ setContextAlias(style.context[i], style.context[i+1]);
136
+ }
137
+ }
138
+ if ('should' in style) {
139
+ for (i = 0; i < style.should.length; i += 2) {
140
+ setShouldAlias(style.should[i], style.should[i+1]);
141
+ }
142
+ }
143
+ if (style.unify) unifyRunners();
144
+ }
145
+ else throw { name: 'UndefinedStyle', message: 'There is not "'+name+'" style defined' };
146
+ return jShoulda;
147
+ }
148
+
149
+ function defineStyle(name, opts, aliases) {
150
+ styles[name] = opts;
151
+ for (var i = 2; i < arguments.length; i += 1) {
152
+ styles[arguments[i]] = opts;
153
+ }
154
+ return jShoulda;
155
+ }
156
+
157
+ function unifyRunners (options) {
158
+ if (options) {
159
+ tr = options instanceof Test.Unit.Runner ? options : new Test.Unit.Runner({}, options || {});
160
+ }
161
+ unique = true;
162
+ return jShoulda;
163
+ }
164
+
165
+ return {
166
+ setShouldAlias : setShouldAlias,
167
+ setContextAlias : setContextAlias,
168
+ unifyRunners : unifyRunners,
169
+ useStyle : useStyle,
170
+ defineStyle: defineStyle
171
+ };
172
+
173
+ }();
174
+
175
+ jShoulda
176
+ .defineStyle('describe', {
177
+ context: [ 'describe', '' ],
178
+ should: [ 'it', '' ],
179
+ unify: false
180
+ }, 'it')
181
+ .defineStyle('context', {
182
+ context : [ 'context', '' ],
183
+ should : [ 'should', 'should' ],
184
+ unify : false
185
+ }, 'should')
186
+ .useStyle('should');
@@ -0,0 +1,141 @@
1
+ /* jShoulda, version 1.2
2
+ * (c) 2008 Choan Galvez
3
+ *
4
+ * jShoulda is freely distributable under
5
+ * the terms of an MIT-style license.
6
+ * For details, see the web site: http://jshoulda.scriptia.net
7
+ *
8
+ *--------------------------------------------------------------------------*/
9
+
10
+ var jShoulda = function() {
11
+ // the test runner
12
+ var tr, unique = false;
13
+
14
+ function dummy() {
15
+ };
16
+
17
+ function runQueue(queue, name, before, after, ext) {
18
+ var i, tests;
19
+ for (i = 0; i < queue.length; i += 1) {
20
+ tests = queue[i](name, before, after, ext);
21
+ if (tests)
22
+ tr.tests.push(tests);
23
+ }
24
+ before.pop();
25
+ after.pop();
26
+ }
27
+
28
+ function makeBatch(fn_a) {
29
+ var copy = fn_a.slice(0);
30
+ return function() {
31
+ for (var i = 0; i < copy.length; i += 1) {
32
+ copy[i].call(this);
33
+ }
34
+ };
35
+ }
36
+ function getContextAlias(prefix) {
37
+ if (prefix) prefix += ' ';
38
+ return function (name, config, args) {
39
+ var queue = Array.prototype.slice.call(arguments, 0);
40
+ var cName = '';
41
+ var obj = {};
42
+ // shift arguments if the first one is a string
43
+ if (typeof queue[0] == 'string') {
44
+ if (name) { cName += prefix; }
45
+ cName += queue.shift();
46
+ }
47
+ if (typeof queue[0] === 'object') {
48
+ obj = queue.shift();
49
+ }
50
+
51
+ obj.before = obj.setup || obj.before || dummy;
52
+ obj.after = obj.teardown || obj.after || dummy;
53
+ var beforeQueue;
54
+ var afterQueue;
55
+ var extensions = merge({}, obj || {});
56
+
57
+ return function(outerName, before, after, ext) {
58
+ // the root context gets no outerName or a configuration object
59
+ // as its first argument
60
+ var prefix = outerName;
61
+ var is_root = !!(outerName == undefined || typeof outerName == 'object');
62
+ if (is_root) {
63
+ tr = (tr && unique) ? tr : new Test.Unit.Runner({}, outerName || {});
64
+ prefix = '';
65
+ }
66
+ // shift arguments if the second one is a
67
+ // configuration object
68
+ beforeQueue = before ? before.push(obj.before) && before : [obj.before];
69
+ afterQueue = after ? after.push(obj.after) && after : [obj.after];
70
+ runQueue(queue, [prefix, cName].join(' '), beforeQueue, afterQueue, merge(extensions, ext));
71
+ if (is_root) {
72
+ return tr;
73
+ }
74
+ return false; // do not add to the tests queue
75
+ };
76
+ };
77
+ };
78
+
79
+ function merge(sub, sup) {
80
+ for (var i in sup) {
81
+ if (i.search(/^(before|after|setup|teardown)$/) != -1) continue;
82
+ if (sup.hasOwnProperty(i)) {
83
+ sub[i] = sup[i];
84
+ }
85
+ }
86
+ return sub;
87
+ }
88
+
89
+
90
+ function getShouldAlias(connector) {
91
+ return function (name, fn) {
92
+ return function(prefix, before, after, extensions) {
93
+ var beforeBatch = makeBatch(before);
94
+ var afterBatch = makeBatch(after);
95
+ var unit = new Test.Unit.Testcase([prefix, name].join(' ' + connector + ' '), fn, beforeBatch, afterBatch);
96
+ merge(unit, extensions);
97
+ return unit;
98
+ };
99
+ };
100
+ }
101
+
102
+ function setShouldAlias(name, host) {
103
+ var connector = name;
104
+ if (typeof host == 'string') {
105
+ connector = host;
106
+ host = arguments[2];
107
+ }
108
+ host = host || window;
109
+ host[name] = getShouldAlias(connector);
110
+ return jShoulda;
111
+ }
112
+
113
+ function setContextAlias(name, host) {
114
+ var prefix = '';
115
+ if (typeof host == 'string') {
116
+ prefix = host;
117
+ host = arguments[2];
118
+ }
119
+ host = host || window;
120
+ host[name] = getContextAlias(prefix);
121
+ return jShoulda;
122
+ }
123
+
124
+
125
+ return {
126
+ setShouldAlias : setShouldAlias,
127
+ setContextAlias : setContextAlias,
128
+ unifyRunners : function(options) {
129
+ if (options) {
130
+ tr = options instanceof Test.Unit.Runner ? options : new Test.Unit.Runner({}, options || {});
131
+ }
132
+ unique = true;
133
+ return jShoulda;
134
+ }
135
+ };
136
+
137
+ }();
138
+
139
+ jShoulda
140
+ .setShouldAlias('should')
141
+ .setContextAlias('context');
@@ -0,0 +1,142 @@
1
+ /* jShoulda, version 1.2.x
2
+ * (c) 2008 Choan Galvez
3
+ *
4
+ * jShoulda is freely distributable under
5
+ * the terms of an MIT-style license.
6
+ * For details, see the web site: http://jshoulda.scriptia.net
7
+ *
8
+ *--------------------------------------------------------------------------*/
9
+
10
+ var jShoulda = function() {
11
+ // the test runner
12
+ var tr, unique = false;
13
+
14
+ function dummy() {
15
+ };
16
+
17
+ function runQueue(queue, name, before, after, ext) {
18
+ var i, tests;
19
+ for (i = 0; i < queue.length; i += 1) {
20
+ tests = queue[i](name, before, after, ext);
21
+ if (tests)
22
+ tr.tests.push(tests);
23
+ }
24
+ before.pop();
25
+ after.pop();
26
+ }
27
+
28
+ function makeBatch(fn_a) {
29
+ var copy = fn_a.slice(0);
30
+ return function() {
31
+ for (var i = 0; i < copy.length; i += 1) {
32
+ copy[i].call(this);
33
+ }
34
+ };
35
+ }
36
+ function getContextAlias(prefix) {
37
+ if (prefix) prefix += ' ';
38
+ return function (name, config, args) {
39
+ var queue = Array.prototype.slice.call(arguments, 0);
40
+ var cName = '';
41
+ var obj = {};
42
+ // shift arguments if the first one is a string
43
+ if (typeof queue[0] == 'string') {
44
+ if (name) { cName += prefix; }
45
+ cName += queue.shift();
46
+ }
47
+ if (typeof queue[0] === 'object') {
48
+ obj = queue.shift();
49
+ }
50
+
51
+ obj.before = obj.setup || obj.before || dummy;
52
+ obj.after = obj.teardown || obj.after || dummy;
53
+ var beforeQueue;
54
+ var afterQueue;
55
+ var extensions = merge({}, obj || {});
56
+
57
+ return function(outerName, before, after, ext) {
58
+ // the root context gets no outerName or a configuration object
59
+ // as its first argument
60
+ var prefix = outerName;
61
+ var is_root = !!(outerName == undefined || typeof outerName == 'object');
62
+ // debugger;
63
+ if (is_root) {
64
+ tr = (tr && unique) ? tr : new Test.Unit.Runner({}, outerName || {});
65
+ prefix = '';
66
+ }
67
+ // shift arguments if the second one is a
68
+ // configuration object
69
+ beforeQueue = before ? before.push(obj.before) && before : [obj.before];
70
+ afterQueue = after ? after.push(obj.after) && after : [obj.after];
71
+ runQueue(queue, [prefix, cName].join(' ').replace(/^\s+/, ''), beforeQueue, afterQueue, merge(extensions, ext));
72
+ if (is_root) {
73
+ return tr;
74
+ }
75
+ return false; // do not add to the tests queue
76
+ };
77
+ };
78
+ };
79
+
80
+ function merge(sub, sup) {
81
+ for (var i in sup) {
82
+ if (i.search(/^(before|after|setup|teardown)$/) != -1) continue;
83
+ if (sup.hasOwnProperty(i)) {
84
+ sub[i] = sup[i];
85
+ }
86
+ }
87
+ return sub;
88
+ }
89
+
90
+
91
+ function getShouldAlias(connector) {
92
+ return function (name, fn) {
93
+ return function(prefix, before, after, extensions) {
94
+ var beforeBatch = makeBatch(before);
95
+ var afterBatch = makeBatch(after);
96
+ var unit = new Test.Unit.Testcase([prefix, name].join(' ' + connector + ' '), fn, beforeBatch, afterBatch);
97
+ merge(unit, extensions);
98
+ return unit;
99
+ };
100
+ };
101
+ }
102
+
103
+ function setShouldAlias(name, host) {
104
+ var connector = name;
105
+ if (typeof host == 'string') {
106
+ connector = host;
107
+ host = arguments[2];
108
+ }
109
+ host = host || window;
110
+ host[name] = getShouldAlias(connector);
111
+ return jShoulda;
112
+ }
113
+
114
+ function setContextAlias(name, host) {
115
+ var prefix = '';
116
+ if (typeof host == 'string') {
117
+ prefix = host;
118
+ host = arguments[2];
119
+ }
120
+ host = host || window;
121
+ host[name] = getContextAlias(prefix);
122
+ return jShoulda;
123
+ }
124
+
125
+
126
+ return {
127
+ setShouldAlias : setShouldAlias,
128
+ setContextAlias : setContextAlias,
129
+ unifyRunners : function(options) {
130
+ if (options) {
131
+ tr = options instanceof Test.Unit.Runner ? options : new Test.Unit.Runner({}, options || {});
132
+ }
133
+ unique = true;
134
+ return jShoulda;
135
+ }
136
+ };
137
+
138
+ }();
139
+
140
+ jShoulda
141
+ .setShouldAlias('should')
142
+ .setContextAlias('context');