@@ -8,9 +8,9 @@ Simple mocking framework for Lua inspired by CppUMock and designed for readabili
8
8
``` lua
9
9
mach = require ' mach'
10
10
11
- local f = mach .mockFunction ()
11
+ local f = mach .mock_function ()
12
12
13
- mach (f ):shouldBeCalled ():
13
+ mach (f ):should_be_called ():
14
14
when (function () f () end )
15
15
```
16
16
@@ -20,9 +20,9 @@ when(function() f() end)
20
20
mach = require ' mach'
21
21
22
22
local o = {}
23
- o .m = mach .mockMethod ()
23
+ o .m = mach .mach_method ()
24
24
25
- mach (m ):shouldBeCalled ():
25
+ mach (m ):should_be_called ():
26
26
when (function () o :m () end )
27
27
```
28
28
@@ -31,42 +31,42 @@ when(function() o:m() end)
31
31
``` lua
32
32
mach = require ' mach'
33
33
34
- local someTable = {
34
+ local some_table = {
35
35
foo = function () end ,
36
36
bar = function () end
37
37
}
38
38
39
- mockedTable = mach .mockTable (someTable )
39
+ mocked_table = mach .mockTable (some_table )
40
40
41
- mach (mockedTable .foo ):shouldBeCalled ():
42
- when (function () mockedTable .foo () end )
41
+ mach (mocked_table .foo ):should_be_called ():
42
+ when (function () mocked_table .foo () end )
43
43
```
44
44
45
45
## Mocking an Object
46
46
47
47
``` lua
48
48
mach = require ' mach'
49
49
50
- local someObject = {}
51
- function someObject :foo () end
52
- function someObject :bar () end
50
+ local some_object = {}
51
+ function some_object :foo () end
52
+ function some_object :bar () end
53
53
54
- mockedObject = mach .mockObject ( someObject )
54
+ mocked_object = mach .mock_object ( some_object )
55
55
56
- mach (mockedObject .foo ):shouldBeCalled ():
57
- when (function () mockedObject :foo () end )
56
+ mach (mocked_object .foo ):should_be_called ():
57
+ when (function () mocked_object :foo () end )
58
58
```
59
59
60
60
## Multiple Expectations
61
61
62
62
``` lua
63
63
mach = require ' mach'
64
64
65
- local f1 = mach .mockFunction ()
66
- local f2 = mach .mockFunction ()
65
+ local f1 = mach .mock_function ()
66
+ local f2 = mach .mock_function ()
67
67
68
- mach (f1 ):shouldBeCalled ():
69
- andAlso (mach (f2 ):shouldBeCalled ()):
68
+ mach (f1 ):should_be_called ():
69
+ and_also (mach (f2 ):should_be_called ()):
70
70
when (function () f1 (); f2 () end )
71
71
```
72
72
@@ -75,7 +75,7 @@ when(function() f1(); f2() end)
75
75
``` lua
76
76
mach = require ' mach'
77
77
78
- local f = mach .mockFunction ()
78
+ local f = mach .mock_function ()
79
79
80
80
mach (f ):mayBeCalled ():
81
81
when (function () end )
@@ -86,21 +86,21 @@ when(function() end)
86
86
``` lua
87
87
mach = require ' mach'
88
88
89
- local f = mach .mockFunction ()
89
+ local f = mach .mock_function ()
90
90
91
- -- Use andAlso when order is important
92
- mach (f ):shouldBeCalledWith (1 ):
93
- andThen (mach (f ):shouldBeCalledWith (2 )):
91
+ -- Use and_also when order is important
92
+ mach (f ):should_be_calledWith (1 ):
93
+ andThen (mach (f ):should_be_calledWith (2 )):
94
94
when (function ()
95
95
f (2 ) -- Error, out of order call
96
96
f (1 )
97
97
end )
98
98
99
- -- Use andAlso when order is unimportant
100
- mach (f ):shouldBeCalledWith (1 ):
101
- andAlso (mach (f ):shouldBeCalledWith (2 )):
99
+ -- Use and_also when order is unimportant
100
+ mach (f ):should_be_calledWith (1 ):
101
+ and_also (mach (f ):should_be_calledWith (2 )):
102
102
when (function ()
103
- f (2 ) -- No error, order is not fixed when 'andAlso ' is used
103
+ f (2 ) -- No error, order is not fixed when 'and_also ' is used
104
104
f (1 )
105
105
end )
106
106
```
@@ -110,12 +110,12 @@ end)
110
110
``` lua
111
111
mach = require ' mach'
112
112
113
- local f = mach .mockFunction ()
113
+ local f = mach .mock_function ()
114
114
115
- mach (f ):shouldBeCalledWith (1 ):
116
- andAlso (mach (f ):shouldBeCalledWith (2 )):
117
- andThen (mach (f ):shouldBeCalledWith (3 )):
118
- andAlso (mach (f ):shouldBeCalledWith (4 )):
115
+ mach (f ):should_be_calledWith (1 ):
116
+ and_also (mach (f ):should_be_calledWith (2 )):
117
+ andThen (mach (f ):should_be_calledWith (3 )):
118
+ and_also (mach (f ):should_be_calledWith (4 )):
119
119
when (function ()
120
120
f (2 )
121
121
f (1 )
@@ -129,24 +129,24 @@ end)
129
129
``` lua
130
130
mach = require ' mach'
131
131
132
- local m1 = mach .mockFunction ()
133
- local m2 = mach .mockFunction ()
132
+ local m1 = mach .mock_function ()
133
+ local m2 = mach .mock_function ()
134
134
135
- function somethingShouldHappen ()
136
- return mach (m1 ):shouldBeCalled ()
135
+ function something_should_happen ()
136
+ return mach (m1 ):should_be_called ()
137
137
end
138
138
139
- function anotherThingShouldHappen ()
140
- return mach (m2 ):shouldBeCalledWith (1 , 2 , 3 )
139
+ function another_thing_should_happen ()
140
+ return mach (m2 ):should_be_calledWith (1 , 2 , 3 )
141
141
end
142
142
143
- function theCodeUnderTestRuns ()
143
+ function the_code_under_test_runs ()
144
144
m1 ()
145
145
m2 (1 , 2 , 3 )
146
146
end
147
147
148
148
-- Actual test:
149
- somethingShouldHappen ():
150
- andAlso ( anotherThingShouldHappen ()):
151
- when (theCodeUnderTestRuns )
149
+ something_should_happen ():
150
+ and_also ( another_thing_should_happen ()):
151
+ when (the_code_under_test_runs )
152
152
```
0 commit comments