public
Description: BDD for OpenLaszlo.
Clone URL: git://github.com/osteele/lztestkit.git
+deferred callback facility
osteele (author)
Fri Feb 29 15:24:54 -0800 2008
commit  fe6e4c2643cf2d8bc11e2424ca4007bd5b1b7e07
tree    4b2482418be052156438822be056fb2a0cb69596
parent  dbaa55bb13653de2676c3aac09ec979de27de2ff
...
84
85
86
87
 
88
89
90
...
147
148
149
 
 
150
151
152
153
154
155
...
157
158
159
160
 
 
161
162
163
...
165
166
167
 
 
 
 
 
 
 
 
168
169
170
171
 
 
 
 
 
 
 
 
172
173
174
175
176
177
178
179
180
181
182
 
183
184
185
186
187
188
 
 
189
190
191
...
84
85
86
 
87
88
89
90
...
147
148
149
150
151
152
153
 
154
155
156
...
158
159
160
 
161
162
163
164
165
...
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
 
 
193
 
 
 
 
 
194
195
196
197
198
199
 
200
201
202
203
204
0
@@ -84,7 +84,7 @@ function MockObject(master) {
0
     addMethods(master);
0
     if (typeof master == 'function') {
0
         addMethods(new master);
0
- var finalizer = (master['mock']||{}).finalize;
0
+ var finalizer = (master['mock']||{})['finalize'] || null;
0
         finalizer && finalizer(this);
0
     }
0
     var mock = this.mock = {expects: expector, verify: verify, testCase: null};
0
@@ -147,9 +147,10 @@ function MockObject(master) {
0
             for (var ix = 0; ix < arguments.length; ix++)
0
                 if (expectation.arguments[ix] instanceof Mock.Callback)
0
                     expectation.arguments[ix].exec(arguments[ix]);
0
+ if (expectation.hasReturnValue)
0
+ return expectation.returnValue;
0
             if (stub)
0
                 return stub.applyTo(arguments);
0
- return expectation.value;
0
         };
0
         expector[name] = function() {
0
             Mock['trace'] && Debug.write('expect', name, arguments);
0
@@ -157,7 +158,8 @@ function MockObject(master) {
0
                 expectation = {
0
                     name: name,
0
                     arguments: Array.slice(arguments, 0),
0
- value: null
0
+ hasReturnValue: false,
0
+ returnValue: undefined
0
                 };
0
             expectations.push(expectation);
0
 
0
@@ -165,27 +167,38 @@ function MockObject(master) {
0
                 define('calls', calls),
0
                 define('returns', returns);
0
                 define.alias('calls.back', 'calls');
0
+ define('captures.callback', function(pos) {
0
+ if (arguments.length < 1)
0
+ pos = findFirstFunction();
0
+ var cb = expectation.arguments[pos] = Mock.callback(undefined);
0
+ cb.exec = function(fn) { this.fn = fn }
0
+ cb.call = function(values) { this.fn.apply(undefined, arguments) }
0
+ return cb;
0
+ });
0
                 define.empty('and');
0
                 define.modifier.dictionary(options);
0
                 define.modifier('eventually');
0
             });
0
+ function findFirstFunction() {
0
+ var args = expectation.arguments,
0
+ len = args.length;
0
+ for (var i = 0; i < len; i++)
0
+ if (args[i] == Function)
0
+ return i;
0
+ Debug.error('no function position');
0
+ }
0
 
0
             function calls(pos, value) {
0
                 if (arguments.length < 2) {
0
- var args = expectation.arguments,
0
- len = args.length;
0
                     value = pos;
0
- for (var i = 0; i < len; i++)
0
- if (args[i] == Function) {
0
- pos = i;
0
- break;
0
- }
0
+ pos = findFirstFunction();
0
                 }
0
                 var cb = expectation.arguments[pos] = Mock.callback(value);
0
                 cb.async = options.eventually;
0
             };
0
             function returns(value) {
0
- expectation.value = value;
0
+ expectation.hasReturnValue = true;
0
+ expectation.returnValue = value;
0
             }
0
         }
0
     }

Comments

    No one has commented yet.