@@ -255,27 +255,31 @@ describe('The mock library', function()
255
255
it (' should fail if when is not preceeded by shouldBeCalled or shouldBeCalledWith' , function ()
256
256
shouldFailWith (' incomplete expectation' , function ()
257
257
local f = mock :mockFunction (' f' )
258
+
258
259
mock (f ):when (function () end )
259
260
end )
260
261
end )
261
262
262
263
it (' should fail if after is not preceeded by shouldBeCalled or shouldBeCalledWith' , function ()
263
264
shouldFailWith (' incomplete expectation' , function ()
264
265
local f = mock :mockFunction (' f' )
266
+
265
267
mock (f ):after (function () end )
266
268
end )
267
269
end )
268
270
269
271
it (' should fail if shouldBeCalled is used after a call has already been specified' , function ()
270
272
shouldFailWith (' call already specified' , function ()
271
273
local f = mock :mockFunction (' f' )
274
+
272
275
mock (f ):shouldBeCalled ():shouldBeCalled ()
273
276
end )
274
277
end )
275
278
276
279
it (' should fail if shouldBeCalled is used after a call has already been specified' , function ()
277
280
shouldFailWith (' call already specified' , function ()
278
281
local f = mock :mockFunction (' f' )
282
+
279
283
mock (f ):shouldBeCalled ():shouldBeCalledWith ()
280
284
end )
281
285
end )
@@ -321,4 +325,38 @@ describe('The mock library', function()
321
325
end )
322
326
end )
323
327
end )
328
+
329
+ it (' should catch out of order calls when mixed with unordered calls' , function ()
330
+ local f1 = mock :mockFunction (' f1' )
331
+ local f2 = mock :mockFunction (' f2' )
332
+ local f3 = mock :mockFunction (' f3' )
333
+
334
+ shouldFailWith (' unexpected function "f3" called' , function ()
335
+ mock (f1 ):shouldBeCalled ():
336
+ andAlso (mock (f2 ):shouldBeCalled ()):
337
+ andThen (mock (f3 ):shouldBeCalled ()):
338
+ when (function ()
339
+ f2 ()
340
+ f3 ()
341
+ f1 ()
342
+ end )
343
+ end )
344
+ end )
345
+
346
+ it (' should allow ordered and unordered calls to be mixed' , function ()
347
+ local f = mock :mockFunction (' f' )
348
+
349
+ mock (f ):shouldBeCalledWith (1 ):
350
+ andAlso (mock (f ):shouldBeCalledWith (2 )):
351
+ andThen (mock (f ):shouldBeCalledWith (3 )):
352
+ andAlso (mock (f ):shouldBeCalledWith (4 )):
353
+ when (function ()
354
+ f (2 )
355
+ f (1 )
356
+ f (4 )
357
+ f (3 )
358
+ end )
359
+ end )
360
+
361
+ -- may be called? ie: calls that are not required
324
362
end )
0 commit comments