@@ -10,8 +10,9 @@ mach = require 'mach'
10
10
11
11
local f = mach .mock_function ()
12
12
13
- f :should_be_called ():
14
- when (function () f () end )
13
+ f :should_be_called ():when (
14
+ function () f ()
15
+ end )
15
16
```
16
17
17
18
## Mocking a Method
@@ -22,8 +23,9 @@ mach = require 'mach'
22
23
local o = {}
23
24
o .m = mach .mach_method ()
24
25
25
- m :should_be_called ():
26
- when (function () o :m () end )
26
+ m :should_be_called ():when (
27
+ function () o :m ()
28
+ end )
27
29
```
28
30
29
31
## Mocking a Table
@@ -38,8 +40,9 @@ local some_table = {
38
40
39
41
mocked_table = mach .mockTable (some_table )
40
42
41
- mocked_table .foo :should_be_called ():
42
- when (function () mocked_table .foo () end )
43
+ mocked_table .foo :should_be_called ():when (
44
+ function () mocked_table .foo ()
45
+ end )
43
46
```
44
47
45
48
## Mocking an Object
@@ -53,8 +56,9 @@ function some_object:bar() end
53
56
54
57
mocked_object = mach .mock_object (some_object )
55
58
56
- mocked_object .foo :should_be_called ():
57
- when (function () mocked_object :foo () end )
59
+ mocked_object .foo :should_be_called ():when (function ()
60
+ mocked_object :foo ()
61
+ end )
58
62
```
59
63
60
64
## Multiple Expectations
@@ -66,8 +70,11 @@ local f1 = mach.mock_function()
66
70
local f2 = mach .mock_function ()
67
71
68
72
f1 :should_be_called ():
69
- and_also (f2 :should_be_called ()):
70
- when (function () f1 (); f2 () end )
73
+ and_also (f2 :should_be_called ()):
74
+ when (function ()
75
+ f1 ()
76
+ f2 ()
77
+ end )
71
78
```
72
79
73
80
## Optional Expectations
@@ -77,8 +84,7 @@ mach = require 'mach'
77
84
78
85
local f = mach .mock_function ()
79
86
80
- f :mayBeCalled ():
81
- when (function () end )
87
+ f :mayBeCalled ():when (function () end )
82
88
```
83
89
84
90
## Optional Ordering
@@ -90,19 +96,19 @@ local f = mach.mock_function()
90
96
91
97
-- Use and_also when order is important
92
98
f :should_be_called_with (1 ):
93
- and_then (f :should_be_called_with (2 )):
94
- when (function ()
95
- f (2 ) -- Error, out of order call
96
- f (1 )
97
- end )
99
+ and_then (f :should_be_called_with (2 )):
100
+ when (function ()
101
+ f (2 ) -- Error, out of order call
102
+ f (1 )
103
+ end )
98
104
99
105
-- Use and_also when order is unimportant
100
106
f :should_be_called_with (1 ):
101
- and_also (f :should_be_called_with (2 )):
102
- when (function ()
103
- f (2 ) -- No error, order is not fixed when 'and_also' is used
104
- f (1 )
105
- end )
107
+ and_also (f :should_be_called_with (2 )):
108
+ when (function ()
109
+ f (2 ) -- No error, order is not fixed when 'and_also' is used
110
+ f (1 )
111
+ end )
106
112
```
107
113
108
114
## Mixed Ordering
@@ -113,15 +119,15 @@ mach = require 'mach'
113
119
local f = mach .mock_function ()
114
120
115
121
f :should_be_called_with (1 ):
116
- and_also (f :should_be_called_with (2 )):
117
- and_then (f :should_be_called_with (3 )):
118
- and_also (f :should_be_called_with (4 )):
119
- when (function ()
120
- f (2 )
121
- f (1 )
122
- f (4 )
123
- f (3 )
124
- end )
122
+ and_also (f :should_be_called_with (2 )):
123
+ and_then (f :should_be_called_with (3 )):
124
+ and_also (f :should_be_called_with (4 )):
125
+ when (function ()
126
+ f (2 )
127
+ f (1 )
128
+ f (4 )
129
+ f (3 )
130
+ end )
125
131
```
126
132
127
133
## Flexible Syntax
147
153
148
154
-- Actual test:
149
155
something_should_happen ():
150
- and_also (another_thing_should_happen ()):
151
- when (the_code_under_test_runs )
156
+ and_also (another_thing_should_happen ()):
157
+ when (the_code_under_test_runs )
152
158
```
0 commit comments