@@ -28,7 +28,7 @@ describe('The mock library', function()
28
28
it (' should alert you when a function is not called' , function ()
29
29
local f = mock :mockFunction (' f' )
30
30
31
- shouldFail ( function ()
31
+ shouldFailWith ( ' not all calls occurred ' , function ()
32
32
mock (f ):shouldBeCalled ():
33
33
when (function () end )
34
34
end )
@@ -38,7 +38,7 @@ describe('The mock library', function()
38
38
local f1 = mock :mockFunction (' f1' )
39
39
local f2 = mock :mockFunction (' f2' )
40
40
41
- shouldFailWith (' unexpected function "f2" called ' , function ()
41
+ shouldFailWith (' unexpected function call f2() ' , function ()
42
42
mock (f1 ):shouldBeCalled ():
43
43
when (function () f2 () end )
44
44
end )
@@ -47,7 +47,7 @@ describe('The mock library', function()
47
47
it (' should alert you when a function is called unexpectedly' , function ()
48
48
local f = mock :mockFunction (' f' )
49
49
50
- shouldFailWith (' unexpected function "f" called ' , function ()
50
+ shouldFailWith (' unexpected function call f() ' , function ()
51
51
f ()
52
52
end )
53
53
end )
@@ -194,6 +194,32 @@ describe('The mock library', function()
194
194
end )
195
195
end )
196
196
197
+ it (' should allow mocking of any callable in an object, not just functions' , function ()
198
+ local someTable = {
199
+ foo = {}
200
+ }
201
+
202
+ setmetatable (someTable .foo , {__call = function () end })
203
+
204
+ local mockedTable = mock :mockTable (someTable )
205
+
206
+ mock (mockedTable .foo ):shouldBeCalled ():
207
+ when (function () mockedTable .foo () end )
208
+ end )
209
+
210
+ it (' should allow mocking of any callable in a table, not just functions' , function ()
211
+ local someObject = {
212
+ foo = {}
213
+ }
214
+
215
+ setmetatable (someObject .foo , {__call = function () end })
216
+
217
+ local mockedObject = mock :mockObject (someObject )
218
+
219
+ mock (mockedObject .foo ):shouldBeCalled ():
220
+ when (function () mockedObject :foo () end )
221
+ end )
222
+
197
223
it (' should fail when a method is incorrectly used as a function' , function ()
198
224
shouldFail (function ()
199
225
local someObject = {}
@@ -307,7 +333,7 @@ describe('The mock library', function()
307
333
local f1 = mock :mockFunction (' f1' )
308
334
local f2 = mock :mockFunction (' f2' )
309
335
310
- shouldFailWith (' unexpected function "f2" called ' , function ()
336
+ shouldFailWith (' unexpected function call f2() ' , function ()
311
337
mock (f1 ):shouldBeCalled ():
312
338
andThen (mock (f2 ):shouldBeCalled ()):
313
339
when (function ()
@@ -316,7 +342,7 @@ describe('The mock library', function()
316
342
end )
317
343
end )
318
344
319
- shouldFailWith (' unexpected arguments provided to function "f1" ' , function ()
345
+ shouldFailWith (' unexpected arguments provided to function f1 ' , function ()
320
346
mock (f1 ):shouldBeCalledWith (1 ):
321
347
andThen (mock (f2 ):shouldBeCalled (2 )):
322
348
when (function ()
@@ -331,7 +357,7 @@ describe('The mock library', function()
331
357
local f2 = mock :mockFunction (' f2' )
332
358
local f3 = mock :mockFunction (' f3' )
333
359
334
- shouldFailWith (' unexpected function "f3" called ' , function ()
360
+ shouldFailWith (' unexpected function call f3() ' , function ()
335
361
mock (f1 ):shouldBeCalled ():
336
362
andAlso (mock (f2 ):shouldBeCalled ()):
337
363
andThen (mock (f3 ):shouldBeCalled ()):
0 commit comments