@@ -10,7 +10,7 @@ local mach = require 'mach'
10
10
11
11
local f = mach .mock_function (' f' )
12
12
13
- f : should_be_called (): when (function () f () end )
13
+ f . should_be_called (). when (function () f () end )
14
14
```
15
15
16
16
## Mocking a Method
@@ -21,7 +21,7 @@ local mach = require 'mach'
21
21
local o = {}
22
22
o .m = mach .mock_method (' m' )
23
23
24
- o .m : should_be_called (): when (function () o :m () end )
24
+ o .m . should_be_called (). when (function () o :m () end )
25
25
```
26
26
27
27
## Mocking a Table
@@ -36,7 +36,7 @@ local some_table = {
36
36
37
37
mocked_table = mach .mock_table (some_table , ' some_table' )
38
38
39
- mocked_table .foo : should_be_called (): when (function ()
39
+ mocked_table .foo . should_be_called (). when (function ()
40
40
mocked_table .foo ()
41
41
end )
42
42
```
@@ -52,7 +52,7 @@ function some_object:bar() end
52
52
53
53
mocked_object = mach .mock_object (some_object , ' some_object' )
54
54
55
- mocked_object .foo : should_be_called (): when (function ()
55
+ mocked_object .foo . should_be_called (). when (function ()
56
56
mocked_object :foo ()
57
57
end )
58
58
```
@@ -64,7 +64,7 @@ local mach = require 'mach'
64
64
65
65
local f = mach .mock_function (' f' )
66
66
67
- f : should_be_called_with_any_arguments (): when (function () f (' any' , ' args' , ' are' , ' fine' ) end )
67
+ f . should_be_called_with_any_arguments (). when (function () f (' any' , ' args' , ' are' , ' fine' ) end )
68
68
```
69
69
70
70
## Returning Values
@@ -74,7 +74,7 @@ local mach = require 'mach'
74
74
75
75
local f = mach .mock_function (' f' )
76
76
77
- f : should_be_called (): and_will_return (1 , 4 ): when (function ()
77
+ f . should_be_called (). and_will_return (1 , 4 ). when (function ()
78
78
local x , y = f ()
79
79
end )
80
80
```
@@ -86,7 +86,7 @@ local mach = require 'mach'
86
86
87
87
local f = mach .mock_function (' f' )
88
88
89
- f : should_be_called (): and_will_raise_error (' some error' ): when (function ()
89
+ f . should_be_called (). and_will_raise_error (' some error' ). when (function ()
90
90
f ()
91
91
end )
92
92
```
@@ -98,7 +98,7 @@ local mach = require 'mach'
98
98
99
99
local f = mach .mock_function (' f' )
100
100
101
- f : should_be_called (): multiple_times (2 ): when (function ()
101
+ f . should_be_called (). multiple_times (2 ). when (function ()
102
102
f ()
103
103
f ()
104
104
end )
@@ -112,9 +112,9 @@ local mach = require 'mach'
112
112
local f1 = mach .mock_function (' f1' )
113
113
local f2 = mach .mock_function (' f2' )
114
114
115
- f1 : should_be_called ():
116
- and_also (f2 : should_be_called ()):
117
- when (function ()
115
+ f1 . should_be_called ()
116
+ . and_also (f2 . should_be_called ())
117
+ . when (function ()
118
118
f1 ()
119
119
f2 ()
120
120
end )
@@ -127,7 +127,7 @@ local mach = require 'mach'
127
127
128
128
local f = mach .mock_function (' f' )
129
129
130
- f : may_be_called (): when (function () end )
130
+ f . may_be_called (). when (function () end )
131
131
```
132
132
133
133
## Optional Ordering
@@ -138,17 +138,17 @@ local mach = require 'mach'
138
138
local f = mach .mock_function (' f' )
139
139
140
140
-- Use and_then when order is important
141
- f : should_be_called_with (1 ):
142
- and_then (f : should_be_called_with (2 )):
143
- when (function ()
141
+ f . should_be_called_with (1 )
142
+ . and_then (f . should_be_called_with (2 ))
143
+ . when (function ()
144
144
f (2 ) -- Error, out of order call
145
145
f (1 )
146
146
end )
147
147
148
148
-- Use and_also when order is unimportant
149
- f : should_be_called_with (1 ):
150
- and_also (f : should_be_called_with (2 )):
151
- when (function ()
149
+ f . should_be_called_with (1 )
150
+ . and_also (f . should_be_called_with (2 ))
151
+ . when (function ()
152
152
f (2 ) -- No error, order is not fixed when 'and_also' is used
153
153
f (1 )
154
154
end )
@@ -161,11 +161,11 @@ local mach = require 'mach'
161
161
162
162
local f = mach .mock_function (' f' )
163
163
164
- f : should_be_called_with (1 ):
165
- and_also (f : should_be_called_with (2 )):
166
- and_then (f : should_be_called_with (3 )):
167
- and_also (f : should_be_called_with (4 )):
168
- when (function ()
164
+ f . should_be_called_with (1 )
165
+ . and_also (f . should_be_called_with (2 ))
166
+ . and_then (f . should_be_called_with (3 ))
167
+ . and_also (f . should_be_called_with (4 ))
168
+ . when (function ()
169
169
f (2 )
170
170
f (1 )
171
171
f (4 )
@@ -180,8 +180,8 @@ local mach = require 'mach'
180
180
181
181
local f = mach .mockFunction ();
182
182
183
- f : should_be_called_with (mach .match ({ 1 , 2 , 3 })):
184
- when (function ()
183
+ f . should_be_called_with (mach .match ({ 1 , 2 , 3 }))
184
+ . when (function ()
185
185
f ({ 1 , 2 , 3 })
186
186
end )
187
187
```
197
197
198
198
local f = mach .mockFunction ();
199
199
200
- f : should_be_called_with (mach .match ({ 1 , 2 , 3 }, custom_matcher )):
201
- when (function ()
200
+ f . should_be_called_with (mach .match ({ 1 , 2 , 3 }, custom_matcher ))
201
+ . when (function ()
202
202
f ({ 1 , 4 , 9 })
203
203
end )
204
204
```
@@ -210,8 +210,8 @@ local mach = require 'mach'
210
210
211
211
local f = mach .mockFunction ();
212
212
213
- f : should_be_called_with (mach .any , 42 ):
214
- when (function ()
213
+ f . should_be_called_with (mach .any , 42 )
214
+ . when (function ()
215
215
f ({ ' whatever' }, 42 )
216
216
end )
217
217
```
@@ -223,7 +223,7 @@ local mach = require 'mach'
223
223
224
224
local f = mach .mock_function (' f' )
225
225
226
- f : should_be_called (): and_other_calls_should_be_ignored (): when (function ()
226
+ f . should_be_called (). and_other_calls_should_be_ignored (). when (function ()
227
227
f ()
228
228
f (1 )
229
229
end )
@@ -234,7 +234,7 @@ local mach = require 'mach'
234
234
235
235
local f = mach .mock_function (' f' )
236
236
237
- f : should_be_called (): with_other_calls_ignored (): when (function ()
237
+ f . should_be_called (). with_other_calls_ignored (). when (function ()
238
238
f ()
239
239
f (1 )
240
240
end )
@@ -262,11 +262,11 @@ local m1 = mach.mock_function('m1')
262
262
local m2 = mach .mock_function (' m2' )
263
263
264
264
function something_should_happen ()
265
- return m1 : should_be_called ()
265
+ return m1 . should_be_called ()
266
266
end
267
267
268
268
function another_thing_should_happen ()
269
- return m2 : should_be_called_with (1 , 2 , 3 )
269
+ return m2 . should_be_called_with (1 , 2 , 3 )
270
270
end
271
271
272
272
function the_code_under_test_runs ()
@@ -275,9 +275,9 @@ function the_code_under_test_runs()
275
275
end
276
276
277
277
-- Actual test:
278
- something_should_happen ():
279
- and_also (another_thing_should_happen ()):
280
- when (the_code_under_test_runs )
278
+ something_should_happen ()
279
+ . and_also (another_thing_should_happen ())
280
+ . when (the_code_under_test_runs )
281
281
```
282
282
283
283
## Handy Error messages
@@ -289,9 +289,9 @@ local f1 = mach.mock_function('f1')
289
289
local f2 = mach .mock_function (' f2' )
290
290
local f2 = mach .mock_function (' f3' )
291
291
292
- f1 : should_be_called_with (1 ):
293
- and_also (f2 : should_be_called_with (2 )):
294
- when (function ()
292
+ f1 . should_be_called_with (1 )
293
+ . and_also (f2 . should_be_called_with (2 ))
294
+ . when (function ()
295
295
f1 (1 )
296
296
f3 (3 )
297
297
end )
0 commit comments