File tree Expand file tree Collapse file tree 1 file changed +61
-0
lines changed Expand file tree Collapse file tree 1 file changed +61
-0
lines changed Original file line number Diff line number Diff line change
1
+ mock.lua
2
+ ========
3
+
4
+ Simple mocking framework for Lua based on CppUTest
5
+
6
+ ## Mocking a Function
7
+
8
+ mock = require 'Mock'
9
+
10
+ local f = mock:function()
11
+
12
+ mock(f):shouldBeCalled():
13
+ when(function() f() end)
14
+
15
+ ## Mocking a Method
16
+
17
+ mock = require 'Mock'
18
+
19
+ o = {}
20
+ o.m = mock:method()
21
+
22
+ mock(m):shouldBeCalled():
23
+ when(function() o:m() end)
24
+
25
+ ## Mocking a Table
26
+
27
+ mock = require 'Mock'
28
+
29
+ someTable = {
30
+ foo = function() end,
31
+ bar = function() end
32
+ }
33
+
34
+ mockedTable = mock:table(someTable)
35
+
36
+ mock(mockedTable.foo):shouldBeCalled():
37
+ when(function() mockedTable.foo() end)
38
+
39
+ ## Mocking an Object
40
+
41
+ mock = require 'Mock'
42
+
43
+ someObject = {}
44
+ function someObject:foo() end
45
+ function someObject:bar() end
46
+
47
+ mockedObject = mock:object(someObject)
48
+
49
+ mock(mockedObject.foo):shouldBeCalled():
50
+ when(function() mockedObject:foo() end)
51
+
52
+ ## Multiple Expectations
53
+
54
+ mock = require 'Mock'
55
+
56
+ local f1 = mock:function()
57
+ local f2 = mock:function()
58
+
59
+ mock(f1):shouldBeCalled():
60
+ andAlso(mock(f2):shouldBeCalled()):
61
+ when(function() f1(); f2() end)
You can’t perform that action at this time.
0 commit comments