headless-squirrel 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. data/README.rdoc +55 -0
  2. data/Rakefile +27 -0
  3. data/bin/jstest +10 -0
  4. data/lib/headless_squirrel.rb +2 -0
  5. data/lib/headless_squirrel/console.rb +24 -0
  6. data/lib/headless_squirrel/runner.rb +70 -0
  7. data/lib/headless_squirrel/test.rb +17 -0
  8. data/lib/headless_squirrel/test_case.rb +158 -0
  9. data/test/fixtures/a_unit_test.html +27 -0
  10. data/test/fixtures/a_unit_test.js +22 -0
  11. data/test/fixtures/syntax_error.html +27 -0
  12. data/test/fixtures/syntax_error.js +5 -0
  13. data/test/fixtures/type_error.html +27 -0
  14. data/test/fixtures/type_error.js +1 -0
  15. data/test/regression/prototype/unit/ajax_test.html +29 -0
  16. data/test/regression/prototype/unit/array_test.html +28 -0
  17. data/test/regression/prototype/unit/assets/prototype.js +4900 -0
  18. data/test/regression/prototype/unit/assets/unittest.css +50 -0
  19. data/test/regression/prototype/unit/assets/unittest.js +615 -0
  20. data/test/regression/prototype/unit/assets/unittest_transport.js +1 -0
  21. data/test/regression/prototype/unit/base_test.html +27 -0
  22. data/test/regression/prototype/unit/class_test.html +27 -0
  23. data/test/regression/prototype/unit/date_test.html +27 -0
  24. data/test/regression/prototype/unit/dom_test.html +304 -0
  25. data/test/regression/prototype/unit/element_mixins_test.html +30 -0
  26. data/test/regression/prototype/unit/enumerable_test.html +35 -0
  27. data/test/regression/prototype/unit/event_test.html +31 -0
  28. data/test/regression/prototype/unit/fixtures/ajax.html +2 -0
  29. data/test/regression/prototype/unit/fixtures/ajax.js +42 -0
  30. data/test/regression/prototype/unit/fixtures/array.html +1 -0
  31. data/test/regression/prototype/unit/fixtures/class.js +83 -0
  32. data/test/regression/prototype/unit/fixtures/content.html +1 -0
  33. data/test/regression/prototype/unit/fixtures/data.json +1 -0
  34. data/test/regression/prototype/unit/fixtures/dom.css +84 -0
  35. data/test/regression/prototype/unit/fixtures/dom.html +278 -0
  36. data/test/regression/prototype/unit/fixtures/dom.js +17 -0
  37. data/test/regression/prototype/unit/fixtures/element_mixins.html +4 -0
  38. data/test/regression/prototype/unit/fixtures/element_mixins.js +2 -0
  39. data/test/regression/prototype/unit/fixtures/empty.html +0 -0
  40. data/test/regression/prototype/unit/fixtures/empty.js +1 -0
  41. data/test/regression/prototype/unit/fixtures/enumerable.html +8 -0
  42. data/test/regression/prototype/unit/fixtures/enumerable.js +23 -0
  43. data/test/regression/prototype/unit/fixtures/event.html +4 -0
  44. data/test/regression/prototype/unit/fixtures/form.html +108 -0
  45. data/test/regression/prototype/unit/fixtures/function.js +13 -0
  46. data/test/regression/prototype/unit/fixtures/hash.js +25 -0
  47. data/test/regression/prototype/unit/fixtures/hello.js +1 -0
  48. data/test/regression/prototype/unit/fixtures/logo.gif +0 -0
  49. data/test/regression/prototype/unit/fixtures/object.html +6 -0
  50. data/test/regression/prototype/unit/fixtures/object.js +7 -0
  51. data/test/regression/prototype/unit/fixtures/position.html +9 -0
  52. data/test/regression/prototype/unit/fixtures/selector.html +71 -0
  53. data/test/regression/prototype/unit/fixtures/string.js +8 -0
  54. data/test/regression/prototype/unit/fixtures/unittest.html +18 -0
  55. data/test/regression/prototype/unit/form_test.html +135 -0
  56. data/test/regression/prototype/unit/function_test.html +27 -0
  57. data/test/regression/prototype/unit/hash_test.html +27 -0
  58. data/test/regression/prototype/unit/number_test.html +27 -0
  59. data/test/regression/prototype/unit/object_test.html +32 -0
  60. data/test/regression/prototype/unit/periodical_executer_test.html +27 -0
  61. data/test/regression/prototype/unit/position_test.html +36 -0
  62. data/test/regression/prototype/unit/prototype_test.html +27 -0
  63. data/test/regression/prototype/unit/range_test.html +27 -0
  64. data/test/regression/prototype/unit/regexp_test.html +27 -0
  65. data/test/regression/prototype/unit/selector_test.html +98 -0
  66. data/test/regression/prototype/unit/string_test.html +27 -0
  67. data/test/regression/prototype/unit/tests/ajax_test.js +379 -0
  68. data/test/regression/prototype/unit/tests/array_test.js +186 -0
  69. data/test/regression/prototype/unit/tests/base_test.js +43 -0
  70. data/test/regression/prototype/unit/tests/class_test.js +136 -0
  71. data/test/regression/prototype/unit/tests/date_test.js +5 -0
  72. data/test/regression/prototype/unit/tests/dom_test.js +1493 -0
  73. data/test/regression/prototype/unit/tests/element_mixins_test.js +32 -0
  74. data/test/regression/prototype/unit/tests/enumerable_test.js +271 -0
  75. data/test/regression/prototype/unit/tests/event_test.js +235 -0
  76. data/test/regression/prototype/unit/tests/form_test.js +382 -0
  77. data/test/regression/prototype/unit/tests/function_test.js +133 -0
  78. data/test/regression/prototype/unit/tests/hash_test.js +178 -0
  79. data/test/regression/prototype/unit/tests/number_test.js +44 -0
  80. data/test/regression/prototype/unit/tests/object_test.js +180 -0
  81. data/test/regression/prototype/unit/tests/periodical_executer_test.js +15 -0
  82. data/test/regression/prototype/unit/tests/position_test.js +44 -0
  83. data/test/regression/prototype/unit/tests/prototype_test.js +43 -0
  84. data/test/regression/prototype/unit/tests/range_test.js +58 -0
  85. data/test/regression/prototype/unit/tests/regexp_test.js +42 -0
  86. data/test/regression/prototype/unit/tests/selector_test.js +408 -0
  87. data/test/regression/prototype/unit/tests/string_test.js +548 -0
  88. data/test/regression/prototype/unit/tests/unittest_test.js +148 -0
  89. data/test/regression/prototype/unit/unittest_test.html +45 -0
  90. data/test/regression/prototype/upstream +1 -0
  91. data/test/regression/scriptaculous/unit/_ajax_inplaceeditor_ipce_alt_text.html +1 -0
  92. data/test/regression/scriptaculous/unit/_ajax_inplaceeditor_ipce_collection.js +1 -0
  93. data/test/regression/scriptaculous/unit/_ajax_inplaceeditor_result.html +1 -0
  94. data/test/regression/scriptaculous/unit/_ajax_inplaceeditor_result2.html +1 -0
  95. data/test/regression/scriptaculous/unit/_ajax_inplaceeditor_tagged.html +1 -0
  96. data/test/regression/scriptaculous/unit/_ajax_inplaceeditor_text.html +1 -0
  97. data/test/regression/scriptaculous/unit/_ajax_updater_result.html +20 -0
  98. data/test/regression/scriptaculous/unit/_autocomplete_result.html +11 -0
  99. data/test/regression/scriptaculous/unit/_autocomplete_result_nobr.html +1 -0
  100. data/test/regression/scriptaculous/unit/ajax_autocompleter_test.html +243 -0
  101. data/test/regression/scriptaculous/unit/ajax_inplaceeditor_test.html +895 -0
  102. data/test/regression/scriptaculous/unit/assets/builder.js +134 -0
  103. data/test/regression/scriptaculous/unit/assets/controls.js +963 -0
  104. data/test/regression/scriptaculous/unit/assets/dragdrop.js +973 -0
  105. data/test/regression/scriptaculous/unit/assets/effects.js +1122 -0
  106. data/test/regression/scriptaculous/unit/assets/javascripttest.rb +203 -0
  107. data/test/regression/scriptaculous/unit/assets/prototype.js +4320 -0
  108. data/test/regression/scriptaculous/unit/assets/scriptaculous.js +66 -0
  109. data/test/regression/scriptaculous/unit/assets/slider.js +273 -0
  110. data/test/regression/scriptaculous/unit/assets/sound.js +57 -0
  111. data/test/regression/scriptaculous/unit/assets/unittest.js +566 -0
  112. data/test/regression/scriptaculous/unit/bdd_test.html +150 -0
  113. data/test/regression/scriptaculous/unit/builder_test.html +262 -0
  114. data/test/regression/scriptaculous/unit/dragdrop_test.html +131 -0
  115. data/test/regression/scriptaculous/unit/effects_test.html +547 -0
  116. data/test/regression/scriptaculous/unit/element_test.html +116 -0
  117. data/test/regression/scriptaculous/unit/icon.png +0 -0
  118. data/test/regression/scriptaculous/unit/index.html +70 -0
  119. data/test/regression/scriptaculous/unit/loading_test.html +41 -0
  120. data/test/regression/scriptaculous/unit/position_clone_test.html +312 -0
  121. data/test/regression/scriptaculous/unit/slider_test.html +437 -0
  122. data/test/regression/scriptaculous/unit/sortable_test.html +205 -0
  123. data/test/regression/scriptaculous/unit/string_test.html +71 -0
  124. data/test/regression/scriptaculous/unit/unittest_test.html +154 -0
  125. data/test/regression/scriptaculous/upstream +1 -0
  126. data/test/test_helper.rb +20 -0
  127. data/test/unit/runner_test.rb +165 -0
  128. data/test/unit/test_case_test.rb +207 -0
  129. data/test/unit/test_test.rb +24 -0
  130. metadata +209 -0
@@ -0,0 +1,66 @@
1
+ // Copyright (c) 2005-2008 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining
4
+ // a copy of this software and associated documentation files (the
5
+ // "Software"), to deal in the Software without restriction, including
6
+ // without limitation the rights to use, copy, modify, merge, publish,
7
+ // distribute, sublicense, and/or sell copies of the Software, and to
8
+ // permit persons to whom the Software is furnished to do so, subject to
9
+ // the following conditions:
10
+ //
11
+ // The above copyright notice and this permission notice shall be
12
+ // included in all copies or substantial portions of the Software.
13
+ //
14
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+ //
22
+ // For details, see the script.aculo.us web site: http://script.aculo.us/
23
+
24
+ var Scriptaculous = {
25
+ Version: '1.8.2',
26
+ require: function(libraryName) {
27
+ try{
28
+ // inserting via DOM fails in Safari 2.0, so brute force approach
29
+ document.write('<script type="text/javascript" src="'+libraryName+'"><\/script>');
30
+ } catch(e) {
31
+ // for xhtml+xml served content, fall back to DOM methods
32
+ var script = document.createElement('script');
33
+ script.type = 'text/javascript';
34
+ script.src = libraryName;
35
+ document.getElementsByTagName('head')[0].appendChild(script);
36
+ }
37
+ },
38
+ REQUIRED_PROTOTYPE: '1.6.0.3',
39
+ load: function() {
40
+ function convertVersionString(versionString) {
41
+ var v = versionString.replace(/_.*|\./g, '');
42
+ v = parseInt(v + '0'.times(4-v.length));
43
+ return versionString.indexOf('_') > -1 ? v-1 : v;
44
+ }
45
+
46
+ if((typeof Prototype=='undefined') ||
47
+ (typeof Element == 'undefined') ||
48
+ (typeof Element.Methods=='undefined') ||
49
+ (convertVersionString(Prototype.Version) <
50
+ convertVersionString(Scriptaculous.REQUIRED_PROTOTYPE)))
51
+ throw("script.aculo.us requires the Prototype JavaScript framework >= " +
52
+ Scriptaculous.REQUIRED_PROTOTYPE);
53
+
54
+ var js = /scriptaculous\.js(\?.*)?$/;
55
+ $$('head script[src]').findAll(function(s) {
56
+ return s.src.match(js);
57
+ }).each(function(s) {
58
+ var path = s.src.replace(js, ''),
59
+ includes = s.src.match(/\?.*load=([a-z,]*)/);
60
+ (includes ? includes[1] : 'builder,effects,dragdrop,controls,slider,sound').split(',').each(
61
+ function(include) { Scriptaculous.require(path+include+'.js') });
62
+ });
63
+ }
64
+ };
65
+
66
+ Scriptaculous.load();
@@ -0,0 +1,273 @@
1
+ // Copyright (c) 2005-2008 Marty Haught, Thomas Fuchs
2
+ //
3
+ // script.aculo.us is freely distributable under the terms of an MIT-style license.
4
+ // For details, see the script.aculo.us web site: http://script.aculo.us/
5
+
6
+ if (!Control) var Control = { };
7
+
8
+ // options:
9
+ // axis: 'vertical', or 'horizontal' (default)
10
+ //
11
+ // callbacks:
12
+ // onChange(value)
13
+ // onSlide(value)
14
+ Control.Slider = Class.create({
15
+ initialize: function(handle, track, options) {
16
+ var slider = this;
17
+
18
+ if (Object.isArray(handle)) {
19
+ this.handles = handle.collect( function(e) { return $(e) });
20
+ } else {
21
+ this.handles = [$(handle)];
22
+ }
23
+
24
+ this.track = $(track);
25
+ this.options = options || { };
26
+
27
+ this.axis = this.options.axis || 'horizontal';
28
+ this.increment = this.options.increment || 1;
29
+ this.step = parseInt(this.options.step || '1');
30
+ this.range = this.options.range || $R(0,1);
31
+
32
+ this.value = 0; // assure backwards compat
33
+ this.values = this.handles.map( function() { return 0 });
34
+ this.spans = this.options.spans ? this.options.spans.map(function(s){ return $(s) }) : false;
35
+ this.options.startSpan = $(this.options.startSpan || null);
36
+ this.options.endSpan = $(this.options.endSpan || null);
37
+
38
+ this.restricted = this.options.restricted || false;
39
+
40
+ this.maximum = this.options.maximum || this.range.end;
41
+ this.minimum = this.options.minimum || this.range.start;
42
+
43
+ // Will be used to align the handle onto the track, if necessary
44
+ this.alignX = parseInt(this.options.alignX || '0');
45
+ this.alignY = parseInt(this.options.alignY || '0');
46
+
47
+ this.trackLength = this.maximumOffset() - this.minimumOffset();
48
+
49
+ this.handleLength = this.isVertical() ?
50
+ (this.handles[0].offsetHeight != 0 ?
51
+ this.handles[0].offsetHeight : this.handles[0].style.height.replace(/px$/,"")) :
52
+ (this.handles[0].offsetWidth != 0 ? this.handles[0].offsetWidth :
53
+ this.handles[0].style.width.replace(/px$/,""));
54
+
55
+ this.active = false;
56
+ this.dragging = false;
57
+ this.disabled = false;
58
+
59
+ if (this.options.disabled) this.setDisabled();
60
+
61
+ // Allowed values array
62
+ this.allowedValues = this.options.values ? this.options.values.sortBy(Prototype.K) : false;
63
+ if (this.allowedValues) {
64
+ this.minimum = this.allowedValues.min();
65
+ this.maximum = this.allowedValues.max();
66
+ }
67
+
68
+ this.eventMouseDown = this.startDrag.bindAsEventListener(this);
69
+ this.eventMouseUp = this.endDrag.bindAsEventListener(this);
70
+ this.eventMouseMove = this.update.bindAsEventListener(this);
71
+
72
+ // Initialize handles in reverse (make sure first handle is active)
73
+ this.handles.each( function(h,i) {
74
+ i = slider.handles.length-1-i;
75
+ slider.setValue(parseFloat(
76
+ (Object.isArray(slider.options.sliderValue) ?
77
+ slider.options.sliderValue[i] : slider.options.sliderValue) ||
78
+ slider.range.start), i);
79
+ h.makePositioned().observe("mousedown", slider.eventMouseDown);
80
+ });
81
+
82
+ this.track.observe("mousedown", this.eventMouseDown);
83
+ document.observe("mouseup", this.eventMouseUp);
84
+ document.observe("mousemove", this.eventMouseMove);
85
+
86
+ this.initialized = true;
87
+ },
88
+ dispose: function() {
89
+ var slider = this;
90
+ Event.stopObserving(this.track, "mousedown", this.eventMouseDown);
91
+ Event.stopObserving(document, "mouseup", this.eventMouseUp);
92
+ Event.stopObserving(document, "mousemove", this.eventMouseMove);
93
+ this.handles.each( function(h) {
94
+ Event.stopObserving(h, "mousedown", slider.eventMouseDown);
95
+ });
96
+ },
97
+ setDisabled: function(){
98
+ this.disabled = true;
99
+ },
100
+ setEnabled: function(){
101
+ this.disabled = false;
102
+ },
103
+ getNearestValue: function(value){
104
+ if (this.allowedValues){
105
+ if (value >= this.allowedValues.max()) return(this.allowedValues.max());
106
+ if (value <= this.allowedValues.min()) return(this.allowedValues.min());
107
+
108
+ var offset = Math.abs(this.allowedValues[0] - value);
109
+ var newValue = this.allowedValues[0];
110
+ this.allowedValues.each( function(v) {
111
+ var currentOffset = Math.abs(v - value);
112
+ if (currentOffset <= offset){
113
+ newValue = v;
114
+ offset = currentOffset;
115
+ }
116
+ });
117
+ return newValue;
118
+ }
119
+ if (value > this.range.end) return this.range.end;
120
+ if (value < this.range.start) return this.range.start;
121
+ return value;
122
+ },
123
+ setValue: function(sliderValue, handleIdx){
124
+ if (!this.active) {
125
+ this.activeHandleIdx = handleIdx || 0;
126
+ this.activeHandle = this.handles[this.activeHandleIdx];
127
+ this.updateStyles();
128
+ }
129
+ handleIdx = handleIdx || this.activeHandleIdx || 0;
130
+ if (this.initialized && this.restricted) {
131
+ if ((handleIdx>0) && (sliderValue<this.values[handleIdx-1]))
132
+ sliderValue = this.values[handleIdx-1];
133
+ if ((handleIdx < (this.handles.length-1)) && (sliderValue>this.values[handleIdx+1]))
134
+ sliderValue = this.values[handleIdx+1];
135
+ }
136
+ sliderValue = this.getNearestValue(sliderValue);
137
+ this.values[handleIdx] = sliderValue;
138
+ this.value = this.values[0]; // assure backwards compat
139
+
140
+ this.handles[handleIdx].style[this.isVertical() ? 'top' : 'left'] =
141
+ this.translateToPx(sliderValue);
142
+
143
+ this.drawSpans();
144
+ if (!this.dragging || !this.event) this.updateFinished();
145
+ },
146
+ setValueBy: function(delta, handleIdx) {
147
+ this.setValue(this.values[handleIdx || this.activeHandleIdx || 0] + delta,
148
+ handleIdx || this.activeHandleIdx || 0);
149
+ },
150
+ translateToPx: function(value) {
151
+ return Math.round(
152
+ ((this.trackLength-this.handleLength)/(this.range.end-this.range.start)) *
153
+ (value - this.range.start)) + "px";
154
+ },
155
+ translateToValue: function(offset) {
156
+ return ((offset/(this.trackLength-this.handleLength) *
157
+ (this.range.end-this.range.start)) + this.range.start);
158
+ },
159
+ getRange: function(range) {
160
+ var v = this.values.sortBy(Prototype.K);
161
+ range = range || 0;
162
+ return $R(v[range],v[range+1]);
163
+ },
164
+ minimumOffset: function(){
165
+ return(this.isVertical() ? this.alignY : this.alignX);
166
+ },
167
+ maximumOffset: function(){
168
+ return(this.isVertical() ?
169
+ (this.track.offsetHeight != 0 ? this.track.offsetHeight :
170
+ this.track.style.height.replace(/px$/,"")) - this.alignY :
171
+ (this.track.offsetWidth != 0 ? this.track.offsetWidth :
172
+ this.track.style.width.replace(/px$/,"")) - this.alignX);
173
+ },
174
+ isVertical: function(){
175
+ return (this.axis == 'vertical');
176
+ },
177
+ drawSpans: function() {
178
+ var slider = this;
179
+ if (this.spans)
180
+ $R(0, this.spans.length-1).each(function(r) { slider.setSpan(slider.spans[r], slider.getRange(r)) });
181
+ if (this.options.startSpan)
182
+ this.setSpan(this.options.startSpan,
183
+ $R(0, this.values.length>1 ? this.getRange(0).min() : this.value ));
184
+ if (this.options.endSpan)
185
+ this.setSpan(this.options.endSpan,
186
+ $R(this.values.length>1 ? this.getRange(this.spans.length-1).max() : this.value, this.maximum));
187
+ },
188
+ setSpan: function(span, range) {
189
+ if (this.isVertical()) {
190
+ span.style.top = this.translateToPx(range.start);
191
+ span.style.height = this.translateToPx(range.end - range.start + this.range.start);
192
+ } else {
193
+ span.style.left = this.translateToPx(range.start);
194
+ span.style.width = this.translateToPx(range.end - range.start + this.range.start);
195
+ }
196
+ },
197
+ updateStyles: function() {
198
+ this.handles.each( function(h){ Element.removeClassName(h, 'selected') });
199
+ Element.addClassName(this.activeHandle, 'selected');
200
+ },
201
+ startDrag: function(event) {
202
+ if (Event.isLeftClick(event)) {
203
+ if (!this.disabled){
204
+ this.active = true;
205
+
206
+ var handle = Event.element(event);
207
+ var pointer = [Event.pointerX(event), Event.pointerY(event)];
208
+ var track = handle;
209
+ if (track==this.track) {
210
+ var offsets = Position.cumulativeOffset(this.track);
211
+ this.event = event;
212
+ this.setValue(this.translateToValue(
213
+ (this.isVertical() ? pointer[1]-offsets[1] : pointer[0]-offsets[0])-(this.handleLength/2)
214
+ ));
215
+ var offsets = Position.cumulativeOffset(this.activeHandle);
216
+ this.offsetX = (pointer[0] - offsets[0]);
217
+ this.offsetY = (pointer[1] - offsets[1]);
218
+ } else {
219
+ // find the handle (prevents issues with Safari)
220
+ while((this.handles.indexOf(handle) == -1) && handle.parentNode)
221
+ handle = handle.parentNode;
222
+
223
+ if (this.handles.indexOf(handle)!=-1) {
224
+ this.activeHandle = handle;
225
+ this.activeHandleIdx = this.handles.indexOf(this.activeHandle);
226
+ this.updateStyles();
227
+
228
+ var offsets = Position.cumulativeOffset(this.activeHandle);
229
+ this.offsetX = (pointer[0] - offsets[0]);
230
+ this.offsetY = (pointer[1] - offsets[1]);
231
+ }
232
+ }
233
+ }
234
+ Event.stop(event);
235
+ }
236
+ },
237
+ update: function(event) {
238
+ if (this.active) {
239
+ if (!this.dragging) this.dragging = true;
240
+ this.draw(event);
241
+ if (Prototype.Browser.WebKit) window.scrollBy(0,0);
242
+ Event.stop(event);
243
+ }
244
+ },
245
+ draw: function(event) {
246
+ var pointer = [Event.pointerX(event), Event.pointerY(event)];
247
+ var offsets = Position.cumulativeOffset(this.track);
248
+ pointer[0] -= this.offsetX + offsets[0];
249
+ pointer[1] -= this.offsetY + offsets[1];
250
+ this.event = event;
251
+ this.setValue(this.translateToValue( this.isVertical() ? pointer[1] : pointer[0] ));
252
+ if (this.initialized && this.options.onSlide)
253
+ this.options.onSlide(this.values.length>1 ? this.values : this.value, this);
254
+ },
255
+ endDrag: function(event) {
256
+ if (this.active && this.dragging) {
257
+ this.finishDrag(event, true);
258
+ Event.stop(event);
259
+ }
260
+ this.active = false;
261
+ this.dragging = false;
262
+ },
263
+ finishDrag: function(event, success) {
264
+ this.active = false;
265
+ this.dragging = false;
266
+ this.updateFinished();
267
+ },
268
+ updateFinished: function() {
269
+ if (this.initialized && this.options.onChange)
270
+ this.options.onChange(this.values.length>1 ? this.values : this.value, this);
271
+ this.event = null;
272
+ }
273
+ });
@@ -0,0 +1,57 @@
1
+ // Copyright (c) 2005-2008 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
2
+ //
3
+ // Based on code created by Jules Gravinese (http://www.webveteran.com/)
4
+ //
5
+ // script.aculo.us is freely distributable under the terms of an MIT-style license.
6
+ // For details, see the script.aculo.us web site: http://script.aculo.us/
7
+
8
+ Sound = {
9
+ tracks: {},
10
+ _enabled: true,
11
+ template:
12
+ new Template('<embed style="height:0" id="sound_#{track}_#{id}" src="#{url}" loop="false" autostart="true" hidden="true"/>'),
13
+ enable: function(){
14
+ Sound._enabled = true;
15
+ },
16
+ disable: function(){
17
+ Sound._enabled = false;
18
+ },
19
+ play: function(url){
20
+ if(!Sound._enabled) return;
21
+ var options = Object.extend({
22
+ track: 'global', url: url, replace: false
23
+ }, arguments[1] || {});
24
+
25
+ if(options.replace && this.tracks[options.track]) {
26
+ $R(0, this.tracks[options.track].id).each(function(id){
27
+ var sound = $('sound_'+options.track+'_'+id);
28
+ sound.Stop && sound.Stop();
29
+ sound.remove();
30
+ });
31
+ this.tracks[options.track] = null;
32
+ }
33
+
34
+ if(!this.tracks[options.track])
35
+ this.tracks[options.track] = { id: 0 };
36
+ else
37
+ this.tracks[options.track].id++;
38
+
39
+ options.id = this.tracks[options.track].id;
40
+ $$('body')[0].insert(
41
+ Prototype.Browser.IE ? new Element('bgsound',{
42
+ id: 'sound_'+options.track+'_'+options.id,
43
+ src: options.url, loop: 1, autostart: true
44
+ }) : Sound.template.evaluate(options));
45
+ }
46
+ };
47
+
48
+ if(Prototype.Browser.Gecko && navigator.userAgent.indexOf("Win") > 0){
49
+ if(navigator.plugins && $A(navigator.plugins).detect(function(p){ return p.name.indexOf('QuickTime') != -1 }))
50
+ Sound.template = new Template('<object id="sound_#{track}_#{id}" width="0" height="0" type="audio/mpeg" data="#{url}"/>');
51
+ else if(navigator.plugins && $A(navigator.plugins).detect(function(p){ return p.name.indexOf('Windows Media') != -1 }))
52
+ Sound.template = new Template('<object id="sound_#{track}_#{id}" type="application/x-mplayer2" data="#{url}"></object>');
53
+ else if(navigator.plugins && $A(navigator.plugins).detect(function(p){ return p.name.indexOf('RealPlayer') != -1 }))
54
+ Sound.template = new Template('<embed type="audio/x-pn-realaudio-plugin" style="height:0" id="sound_#{track}_#{id}" src="#{url}" loop="false" autostart="true" hidden="true"/>');
55
+ else
56
+ Sound.play = function(){};
57
+ }
@@ -0,0 +1,566 @@
1
+ // Copyright (c) 2005-2008 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
2
+ // (c) 2005-2008 Jon Tirsen (http://www.tirsen.com)
3
+ // (c) 2005-2008 Michael Schuerig (http://www.schuerig.de/michael/)
4
+ //
5
+ // script.aculo.us is freely distributable under the terms of an MIT-style license.
6
+ // For details, see the script.aculo.us web site: http://script.aculo.us/
7
+
8
+ // experimental, Firefox-only
9
+ Event.simulateMouse = function(element, eventName) {
10
+ var options = Object.extend({
11
+ pointerX: 0,
12
+ pointerY: 0,
13
+ buttons: 0,
14
+ ctrlKey: false,
15
+ altKey: false,
16
+ shiftKey: false,
17
+ metaKey: false
18
+ }, arguments[2] || {});
19
+ var oEvent = document.createEvent("MouseEvents");
20
+ oEvent.initMouseEvent(eventName, true, true, document.defaultView,
21
+ options.buttons, options.pointerX, options.pointerY, options.pointerX, options.pointerY,
22
+ options.ctrlKey, options.altKey, options.shiftKey, options.metaKey, 0, $(element));
23
+
24
+ if(this.mark) Element.remove(this.mark);
25
+ this.mark = document.createElement('div');
26
+ this.mark.appendChild(document.createTextNode(" "));
27
+ document.body.appendChild(this.mark);
28
+ this.mark.style.position = 'absolute';
29
+ this.mark.style.top = options.pointerY + "px";
30
+ this.mark.style.left = options.pointerX + "px";
31
+ this.mark.style.width = "5px";
32
+ this.mark.style.height = "5px;";
33
+ this.mark.style.borderTop = "1px solid red;";
34
+ this.mark.style.borderLeft = "1px solid red;";
35
+
36
+ if(this.step)
37
+ alert('['+new Date().getTime().toString()+'] '+eventName+'/'+Test.Unit.inspect(options));
38
+
39
+ $(element).dispatchEvent(oEvent);
40
+ };
41
+
42
+ // Note: Due to a fix in Firefox 1.0.5/6 that probably fixed "too much", this doesn't work in 1.0.6 or DP2.
43
+ // You need to downgrade to 1.0.4 for now to get this working
44
+ // See https://bugzilla.mozilla.org/show_bug.cgi?id=289940 for the fix that fixed too much
45
+ Event.simulateKey = function(element, eventName) {
46
+ var options = Object.extend({
47
+ ctrlKey: false,
48
+ altKey: false,
49
+ shiftKey: false,
50
+ metaKey: false,
51
+ keyCode: 0,
52
+ charCode: 0
53
+ }, arguments[2] || {});
54
+
55
+ var oEvent = document.createEvent("KeyEvents");
56
+ oEvent.initKeyEvent(eventName, true, true, window,
57
+ options.ctrlKey, options.altKey, options.shiftKey, options.metaKey,
58
+ options.keyCode, options.charCode );
59
+ $(element).dispatchEvent(oEvent);
60
+ };
61
+
62
+ Event.simulateKeys = function(element, command) {
63
+ for(var i=0; i<command.length; i++) {
64
+ Event.simulateKey(element,'keypress',{charCode:command.charCodeAt(i)});
65
+ }
66
+ };
67
+
68
+ var Test = {};
69
+ Test.Unit = {};
70
+
71
+ // security exception workaround
72
+ Test.Unit.inspect = Object.inspect;
73
+
74
+ Test.Unit.Logger = Class.create();
75
+ Test.Unit.Logger.prototype = {
76
+ initialize: function(log) {
77
+ this.log = $(log);
78
+ if (this.log) {
79
+ this._createLogTable();
80
+ }
81
+ },
82
+ start: function(testName) {
83
+ if (!this.log) return;
84
+ this.testName = testName;
85
+ this.lastLogLine = document.createElement('tr');
86
+ this.statusCell = document.createElement('td');
87
+ this.nameCell = document.createElement('td');
88
+ this.nameCell.className = "nameCell";
89
+ this.nameCell.appendChild(document.createTextNode(testName));
90
+ this.messageCell = document.createElement('td');
91
+ this.lastLogLine.appendChild(this.statusCell);
92
+ this.lastLogLine.appendChild(this.nameCell);
93
+ this.lastLogLine.appendChild(this.messageCell);
94
+ this.loglines.appendChild(this.lastLogLine);
95
+ },
96
+ finish: function(status, summary) {
97
+ if (!this.log) return;
98
+ this.lastLogLine.className = status;
99
+ this.statusCell.innerHTML = status;
100
+ this.messageCell.innerHTML = this._toHTML(summary);
101
+ this.addLinksToResults();
102
+ },
103
+ message: function(message) {
104
+ if (!this.log) return;
105
+ this.messageCell.innerHTML = this._toHTML(message);
106
+ },
107
+ summary: function(summary) {
108
+ if (!this.log) return;
109
+ this.logsummary.innerHTML = this._toHTML(summary);
110
+ },
111
+ _createLogTable: function() {
112
+ this.log.innerHTML =
113
+ '<div id="logsummary"></div>' +
114
+ '<table id="logtable">' +
115
+ '<thead><tr><th>Status</th><th>Test</th><th>Message</th></tr></thead>' +
116
+ '<tbody id="loglines"></tbody>' +
117
+ '</table>';
118
+ this.logsummary = $('logsummary');
119
+ this.loglines = $('loglines');
120
+ },
121
+ _toHTML: function(txt) {
122
+ return txt.escapeHTML().replace(/\n/g,"<br/>");
123
+ },
124
+ addLinksToResults: function(){
125
+ $$("tr.failed .nameCell").each( function(td){ // todo: limit to children of this.log
126
+ td.title = "Run only this test";
127
+ Event.observe(td, 'click', function(){ window.location.search = "?tests=" + td.innerHTML;});
128
+ });
129
+ $$("tr.passed .nameCell").each( function(td){ // todo: limit to children of this.log
130
+ td.title = "Run all tests";
131
+ Event.observe(td, 'click', function(){ window.location.search = "";});
132
+ });
133
+ }
134
+ };
135
+
136
+ Test.Unit.Runner = Class.create();
137
+ Test.Unit.Runner.prototype = {
138
+ initialize: function(testcases) {
139
+ this.options = Object.extend({
140
+ testLog: 'testlog'
141
+ }, arguments[1] || {});
142
+ this.options.resultsURL = this.parseResultsURLQueryParameter();
143
+ this.options.tests = this.parseTestsQueryParameter();
144
+ if (this.options.testLog) {
145
+ this.options.testLog = $(this.options.testLog) || null;
146
+ }
147
+ if(this.options.tests) {
148
+ this.tests = [];
149
+ for(var i = 0; i < this.options.tests.length; i++) {
150
+ if(/^test/.test(this.options.tests[i])) {
151
+ this.tests.push(new Test.Unit.Testcase(this.options.tests[i], testcases[this.options.tests[i]], testcases["setup"], testcases["teardown"]));
152
+ }
153
+ }
154
+ } else {
155
+ if (this.options.test) {
156
+ this.tests = [new Test.Unit.Testcase(this.options.test, testcases[this.options.test], testcases["setup"], testcases["teardown"])];
157
+ } else {
158
+ this.tests = [];
159
+ for(var testcase in testcases) {
160
+ if(/^test/.test(testcase)) {
161
+ this.tests.push(
162
+ new Test.Unit.Testcase(
163
+ this.options.context ? ' -> ' + this.options.titles[testcase] : testcase,
164
+ testcases[testcase], testcases["setup"], testcases["teardown"]
165
+ ));
166
+ }
167
+ }
168
+ }
169
+ }
170
+ this.currentTest = 0;
171
+ this.logger = new Test.Unit.Logger(this.options.testLog);
172
+ setTimeout(this.runTests.bind(this), 1000);
173
+ },
174
+ parseResultsURLQueryParameter: function() {
175
+ return window.location.search.parseQuery()["resultsURL"];
176
+ },
177
+ parseTestsQueryParameter: function(){
178
+ if (window.location.search.parseQuery()["tests"]){
179
+ return window.location.search.parseQuery()["tests"].split(',');
180
+ };
181
+ },
182
+ // Returns:
183
+ // "ERROR" if there was an error,
184
+ // "FAILURE" if there was a failure, or
185
+ // "SUCCESS" if there was neither
186
+ getResult: function() {
187
+ var hasFailure = false;
188
+ for(var i=0;i<this.tests.length;i++) {
189
+ if (this.tests[i].errors > 0) {
190
+ return "ERROR";
191
+ }
192
+ if (this.tests[i].failures > 0) {
193
+ hasFailure = true;
194
+ }
195
+ }
196
+ if (hasFailure) {
197
+ return "FAILURE";
198
+ } else {
199
+ return "SUCCESS";
200
+ }
201
+ },
202
+ postResults: function() {
203
+ if (this.options.resultsURL) {
204
+ new Ajax.Request(this.options.resultsURL,
205
+ { method: 'get', parameters: 'result=' + this.getResult(), asynchronous: false });
206
+ }
207
+ },
208
+ runTests: function() {
209
+ var test = this.tests[this.currentTest];
210
+ if (!test) {
211
+ // finished!
212
+ this.postResults();
213
+ this.logger.summary(this.summary());
214
+ return;
215
+ }
216
+ if(!test.isWaiting) {
217
+ this.logger.start(test.name);
218
+ }
219
+ test.run();
220
+ if(test.isWaiting) {
221
+ this.logger.message("Waiting for " + test.timeToWait + "ms");
222
+ setTimeout(this.runTests.bind(this), test.timeToWait || 1000);
223
+ } else {
224
+ this.logger.finish(test.status(), test.summary());
225
+ this.currentTest++;
226
+ // tail recursive, hopefully the browser will skip the stackframe
227
+ this.runTests();
228
+ }
229
+ },
230
+ summary: function() {
231
+ var assertions = 0;
232
+ var failures = 0;
233
+ var errors = 0;
234
+ var messages = [];
235
+ for(var i=0;i<this.tests.length;i++) {
236
+ assertions += this.tests[i].assertions;
237
+ failures += this.tests[i].failures;
238
+ errors += this.tests[i].errors;
239
+ }
240
+ return (
241
+ (this.options.context ? this.options.context + ': ': '') +
242
+ this.tests.length + " tests, " +
243
+ assertions + " assertions, " +
244
+ failures + " failures, " +
245
+ errors + " errors");
246
+ }
247
+ };
248
+
249
+ Test.Unit.Assertions = Class.create();
250
+ Test.Unit.Assertions.prototype = {
251
+ initialize: function() {
252
+ this.assertions = 0;
253
+ this.failures = 0;
254
+ this.errors = 0;
255
+ this.messages = [];
256
+ },
257
+ summary: function() {
258
+ return (
259
+ this.assertions + " assertions, " +
260
+ this.failures + " failures, " +
261
+ this.errors + " errors" + "\n" +
262
+ this.messages.join("\n"));
263
+ },
264
+ pass: function() {
265
+ this.assertions++;
266
+ },
267
+ fail: function(message) {
268
+ this.failures++;
269
+ this.messages.push("Failure: " + message);
270
+ },
271
+ info: function(message) {
272
+ this.messages.push("Info: " + message);
273
+ },
274
+ error: function(error) {
275
+ this.errors++;
276
+ this.messages.push(error.name + ": "+ error.message + "(" + Test.Unit.inspect(error) +")");
277
+ },
278
+ status: function() {
279
+ if (this.failures > 0) return 'failed';
280
+ if (this.errors > 0) return 'error';
281
+ return 'passed';
282
+ },
283
+ assert: function(expression) {
284
+ var message = arguments[1] || 'assert: got "' + Test.Unit.inspect(expression) + '"';
285
+ try { expression ? this.pass() :
286
+ this.fail(message); }
287
+ catch(e) { this.error(e); }
288
+ },
289
+ assertEqual: function(expected, actual) {
290
+ var message = arguments[2] || "assertEqual";
291
+ try { (expected == actual) ? this.pass() :
292
+ this.fail(message + ': expected "' + Test.Unit.inspect(expected) +
293
+ '", actual "' + Test.Unit.inspect(actual) + '"'); }
294
+ catch(e) { this.error(e); }
295
+ },
296
+ assertInspect: function(expected, actual) {
297
+ var message = arguments[2] || "assertInspect";
298
+ try { (expected == actual.inspect()) ? this.pass() :
299
+ this.fail(message + ': expected "' + Test.Unit.inspect(expected) +
300
+ '", actual "' + Test.Unit.inspect(actual) + '"'); }
301
+ catch(e) { this.error(e); }
302
+ },
303
+ assertEnumEqual: function(expected, actual) {
304
+ var message = arguments[2] || "assertEnumEqual";
305
+ try { $A(expected).length == $A(actual).length &&
306
+ expected.zip(actual).all(function(pair) { return pair[0] == pair[1] }) ?
307
+ this.pass() : this.fail(message + ': expected ' + Test.Unit.inspect(expected) +
308
+ ', actual ' + Test.Unit.inspect(actual)); }
309
+ catch(e) { this.error(e); }
310
+ },
311
+ assertNotEqual: function(expected, actual) {
312
+ var message = arguments[2] || "assertNotEqual";
313
+ try { (expected != actual) ? this.pass() :
314
+ this.fail(message + ': got "' + Test.Unit.inspect(actual) + '"'); }
315
+ catch(e) { this.error(e); }
316
+ },
317
+ assertIdentical: function(expected, actual) {
318
+ var message = arguments[2] || "assertIdentical";
319
+ try { (expected === actual) ? this.pass() :
320
+ this.fail(message + ': expected "' + Test.Unit.inspect(expected) +
321
+ '", actual "' + Test.Unit.inspect(actual) + '"'); }
322
+ catch(e) { this.error(e); }
323
+ },
324
+ assertNotIdentical: function(expected, actual) {
325
+ var message = arguments[2] || "assertNotIdentical";
326
+ try { !(expected === actual) ? this.pass() :
327
+ this.fail(message + ': expected "' + Test.Unit.inspect(expected) +
328
+ '", actual "' + Test.Unit.inspect(actual) + '"'); }
329
+ catch(e) { this.error(e); }
330
+ },
331
+ assertNull: function(obj) {
332
+ var message = arguments[1] || 'assertNull';
333
+ try { (obj==null) ? this.pass() :
334
+ this.fail(message + ': got "' + Test.Unit.inspect(obj) + '"'); }
335
+ catch(e) { this.error(e); }
336
+ },
337
+ assertMatch: function(expected, actual) {
338
+ var message = arguments[2] || 'assertMatch';
339
+ var regex = new RegExp(expected);
340
+ try { (regex.exec(actual)) ? this.pass() :
341
+ this.fail(message + ' : regex: "' + Test.Unit.inspect(expected) + ' did not match: ' + Test.Unit.inspect(actual) + '"'); }
342
+ catch(e) { this.error(e); }
343
+ },
344
+ assertHidden: function(element) {
345
+ var message = arguments[1] || 'assertHidden';
346
+ this.assertEqual("none", element.style.display, message);
347
+ },
348
+ assertNotNull: function(object) {
349
+ var message = arguments[1] || 'assertNotNull';
350
+ this.assert(object != null, message);
351
+ },
352
+ assertType: function(expected, actual) {
353
+ var message = arguments[2] || 'assertType';
354
+ try {
355
+ (actual.constructor == expected) ? this.pass() :
356
+ this.fail(message + ': expected "' + Test.Unit.inspect(expected) +
357
+ '", actual "' + (actual.constructor) + '"'); }
358
+ catch(e) { this.error(e); }
359
+ },
360
+ assertNotOfType: function(expected, actual) {
361
+ var message = arguments[2] || 'assertNotOfType';
362
+ try {
363
+ (actual.constructor != expected) ? this.pass() :
364
+ this.fail(message + ': expected "' + Test.Unit.inspect(expected) +
365
+ '", actual "' + (actual.constructor) + '"'); }
366
+ catch(e) { this.error(e); }
367
+ },
368
+ assertInstanceOf: function(expected, actual) {
369
+ var message = arguments[2] || 'assertInstanceOf';
370
+ try {
371
+ (actual instanceof expected) ? this.pass() :
372
+ this.fail(message + ": object was not an instance of the expected type"); }
373
+ catch(e) { this.error(e); }
374
+ },
375
+ assertNotInstanceOf: function(expected, actual) {
376
+ var message = arguments[2] || 'assertNotInstanceOf';
377
+ try {
378
+ !(actual instanceof expected) ? this.pass() :
379
+ this.fail(message + ": object was an instance of the not expected type"); }
380
+ catch(e) { this.error(e); }
381
+ },
382
+ assertRespondsTo: function(method, obj) {
383
+ var message = arguments[2] || 'assertRespondsTo';
384
+ try {
385
+ (obj[method] && typeof obj[method] == 'function') ? this.pass() :
386
+ this.fail(message + ": object doesn't respond to [" + method + "]"); }
387
+ catch(e) { this.error(e); }
388
+ },
389
+ assertReturnsTrue: function(method, obj) {
390
+ var message = arguments[2] || 'assertReturnsTrue';
391
+ try {
392
+ var m = obj[method];
393
+ if(!m) m = obj['is'+method.charAt(0).toUpperCase()+method.slice(1)];
394
+ m() ? this.pass() :
395
+ this.fail(message + ": method returned false"); }
396
+ catch(e) { this.error(e); }
397
+ },
398
+ assertReturnsFalse: function(method, obj) {
399
+ var message = arguments[2] || 'assertReturnsFalse';
400
+ try {
401
+ var m = obj[method];
402
+ if(!m) m = obj['is'+method.charAt(0).toUpperCase()+method.slice(1)];
403
+ !m() ? this.pass() :
404
+ this.fail(message + ": method returned true"); }
405
+ catch(e) { this.error(e); }
406
+ },
407
+ assertRaise: function(exceptionName, method) {
408
+ var message = arguments[2] || 'assertRaise';
409
+ try {
410
+ method();
411
+ this.fail(message + ": exception expected but none was raised"); }
412
+ catch(e) {
413
+ ((exceptionName == null) || (e.name==exceptionName)) ? this.pass() : this.error(e);
414
+ }
415
+ },
416
+ assertElementsMatch: function() {
417
+ var expressions = $A(arguments), elements = $A(expressions.shift());
418
+ if (elements.length != expressions.length) {
419
+ this.fail('assertElementsMatch: size mismatch: ' + elements.length + ' elements, ' + expressions.length + ' expressions');
420
+ return false;
421
+ }
422
+ elements.zip(expressions).all(function(pair, index) {
423
+ var element = $(pair.first()), expression = pair.last();
424
+ if (element.match(expression)) return true;
425
+ this.fail('assertElementsMatch: (in index ' + index + ') expected ' + expression.inspect() + ' but got ' + element.inspect());
426
+ }.bind(this)) && this.pass();
427
+ },
428
+ assertElementMatches: function(element, expression) {
429
+ this.assertElementsMatch([element], expression);
430
+ },
431
+ benchmark: function(operation, iterations) {
432
+ var startAt = new Date();
433
+ (iterations || 1).times(operation);
434
+ var timeTaken = ((new Date())-startAt);
435
+ this.info((arguments[2] || 'Operation') + ' finished ' +
436
+ iterations + ' iterations in ' + (timeTaken/1000)+'s' );
437
+ return timeTaken;
438
+ },
439
+ _isVisible: function(element) {
440
+ element = $(element);
441
+ if(!element.parentNode) return true;
442
+ this.assertNotNull(element);
443
+ if(element.style && Element.getStyle(element, 'display') == 'none')
444
+ return false;
445
+
446
+ return this._isVisible(element.parentNode);
447
+ },
448
+ assertNotVisible: function(element) {
449
+ this.assert(!this._isVisible(element), Test.Unit.inspect(element) + " was not hidden and didn't have a hidden parent either. " + ("" || arguments[1]));
450
+ },
451
+ assertVisible: function(element) {
452
+ this.assert(this._isVisible(element), Test.Unit.inspect(element) + " was not visible. " + ("" || arguments[1]));
453
+ },
454
+ benchmark: function(operation, iterations) {
455
+ var startAt = new Date();
456
+ (iterations || 1).times(operation);
457
+ var timeTaken = ((new Date())-startAt);
458
+ this.info((arguments[2] || 'Operation') + ' finished ' +
459
+ iterations + ' iterations in ' + (timeTaken/1000)+'s' );
460
+ return timeTaken;
461
+ }
462
+ };
463
+
464
+ Test.Unit.Testcase = Class.create();
465
+ Object.extend(Object.extend(Test.Unit.Testcase.prototype, Test.Unit.Assertions.prototype), {
466
+ initialize: function(name, test, setup, teardown) {
467
+ Test.Unit.Assertions.prototype.initialize.bind(this)();
468
+ this.name = name;
469
+
470
+ if(typeof test == 'string') {
471
+ test = test.gsub(/(\.should[^\(]+\()/,'#{0}this,');
472
+ test = test.gsub(/(\.should[^\(]+)\(this,\)/,'#{1}(this)');
473
+ this.test = function() {
474
+ eval('with(this){'+test+'}');
475
+ }
476
+ } else {
477
+ this.test = test || function() {};
478
+ }
479
+
480
+ this.setup = setup || function() {};
481
+ this.teardown = teardown || function() {};
482
+ this.isWaiting = false;
483
+ this.timeToWait = 1000;
484
+ },
485
+ wait: function(time, nextPart) {
486
+ this.isWaiting = true;
487
+ this.test = nextPart;
488
+ this.timeToWait = time;
489
+ },
490
+ run: function() {
491
+ try {
492
+ try {
493
+ if (!this.isWaiting) this.setup.bind(this)();
494
+ this.isWaiting = false;
495
+ this.test.bind(this)();
496
+ } finally {
497
+ if(!this.isWaiting) {
498
+ this.teardown.bind(this)();
499
+ }
500
+ }
501
+ }
502
+ catch(e) { this.error(e); }
503
+ }
504
+ });
505
+
506
+ // *EXPERIMENTAL* BDD-style testing to please non-technical folk
507
+ // This draws many ideas from RSpec http://rspec.rubyforge.org/
508
+
509
+ Test.setupBDDExtensionMethods = function(){
510
+ var METHODMAP = {
511
+ shouldEqual: 'assertEqual',
512
+ shouldNotEqual: 'assertNotEqual',
513
+ shouldEqualEnum: 'assertEnumEqual',
514
+ shouldBeA: 'assertType',
515
+ shouldNotBeA: 'assertNotOfType',
516
+ shouldBeAn: 'assertType',
517
+ shouldNotBeAn: 'assertNotOfType',
518
+ shouldBeNull: 'assertNull',
519
+ shouldNotBeNull: 'assertNotNull',
520
+
521
+ shouldBe: 'assertReturnsTrue',
522
+ shouldNotBe: 'assertReturnsFalse',
523
+ shouldRespondTo: 'assertRespondsTo'
524
+ };
525
+ var makeAssertion = function(assertion, args, object) {
526
+ this[assertion].apply(this,(args || []).concat([object]));
527
+ };
528
+
529
+ Test.BDDMethods = {};
530
+ $H(METHODMAP).each(function(pair) {
531
+ Test.BDDMethods[pair.key] = function() {
532
+ var args = $A(arguments);
533
+ var scope = args.shift();
534
+ makeAssertion.apply(scope, [pair.value, args, this]); };
535
+ });
536
+
537
+ [Array.prototype, String.prototype, Number.prototype, Boolean.prototype].each(
538
+ function(p){ Object.extend(p, Test.BDDMethods) }
539
+ );
540
+ };
541
+
542
+ Test.context = function(name, spec, log){
543
+ Test.setupBDDExtensionMethods();
544
+
545
+ var compiledSpec = {};
546
+ var titles = {};
547
+ for(specName in spec) {
548
+ switch(specName){
549
+ case "setup":
550
+ case "teardown":
551
+ compiledSpec[specName] = spec[specName];
552
+ break;
553
+ default:
554
+ var testName = 'test'+specName.gsub(/\s+/,'-').camelize();
555
+ var body = spec[specName].toString().split('\n').slice(1);
556
+ if(/^\{/.test(body[0])) body = body.slice(1);
557
+ body.pop();
558
+ body = body.map(function(statement){
559
+ return statement.strip()
560
+ });
561
+ compiledSpec[testName] = body.join('\n');
562
+ titles[testName] = specName;
563
+ }
564
+ }
565
+ new Test.Unit.Runner(compiledSpec, { titles: titles, testLog: log || 'testlog', context: name });
566
+ };