@@ -276,11 +276,11 @@ describe('The mock library', function()
276
276
end )
277
277
end )
278
278
279
- it (' should fail if shouldBeCalled is used after a call has already been specified' , function ()
279
+ it (' should fail if shouldBeCalledWith is used after a call has already been specified' , function ()
280
280
shouldFailWith (' call already specified' , function ()
281
281
local f = mock :mockFunction (' f' )
282
282
283
- mock (f ):shouldBeCalled ():shouldBeCalledWith ()
283
+ mock (f ):shouldBeCalled ():shouldBeCalledWith (4 )
284
284
end )
285
285
end )
286
286
@@ -358,5 +358,67 @@ describe('The mock library', function()
358
358
end )
359
359
end )
360
360
361
- -- may be called? ie: calls that are not required
361
+ it (' should allow soft expectations to be called' , function ()
362
+ local f = mock :mockFunction (' f' )
363
+
364
+ mock (f ):mayBeCalled ():
365
+ when (function ()
366
+ f ()
367
+ end )
368
+ end )
369
+
370
+ it (' should allow soft expectations to be omitted' , function ()
371
+ local f = mock :mockFunction (' f' )
372
+
373
+ mock (f ):mayBeCalled ():
374
+ when (function () end )
375
+ end )
376
+
377
+ it (' should allow soft expectations with return values' , function ()
378
+ local f = mock :mockFunction (' f' )
379
+
380
+ mock (f ):mayBeCalled ():andWillReturn (3 ):
381
+ when (function ()
382
+ assert (f () == 3 )
383
+ end )
384
+ end )
385
+
386
+ it (' should allow soft expectations with arguments to be called' , function ()
387
+ local f = mock :mockFunction (' f' )
388
+
389
+ mock (f ):mayBeCalledWith (4 ):
390
+ when (function ()
391
+ f (4 )
392
+ end )
393
+ end )
394
+
395
+ it (' should allow soft expectations with arguments to be omitted' , function ()
396
+ local f = mock :mockFunction (' f' )
397
+
398
+ mock (f ):mayBeCalledWith (4 ):
399
+ when (function () end )
400
+ end )
401
+
402
+ it (' should allow soft expectations with arguments to be omitted' , function ()
403
+ local f = mock :mockFunction (' f' )
404
+
405
+ mock (f ):mayBeCalledWith (4 ):
406
+ when (function () end )
407
+ end )
408
+
409
+ it (' should fail if mayBeCalled is used after a call has already been specified' , function ()
410
+ shouldFailWith (' call already specified' , function ()
411
+ local f = mock :mockFunction (' f' )
412
+
413
+ mock (f ):shouldBeCalled ():mayBeCalled ()
414
+ end )
415
+ end )
416
+
417
+ it (' should fail if mayBeCalledWith is used after a call has already been specified' , function ()
418
+ shouldFailWith (' call already specified' , function ()
419
+ local f = mock :mockFunction (' f' )
420
+
421
+ mock (f ):shouldBeCalled ():mayBeCalledWith (4 )
422
+ end )
423
+ end )
362
424
end )
0 commit comments