1
1
describe (' The mock library' , function ()
2
- moq = require ' moq '
2
+ mock = require ' mock '
3
3
4
4
local function shouldFail (test )
5
5
if pcall (test ) then
@@ -8,68 +8,68 @@ describe('The mock library', function()
8
8
end
9
9
10
10
it (' should allow you to verify that a function is called' , function ()
11
- local m = moq .createMockFunction ()
11
+ local m = mock .createMockFunction ()
12
12
13
- moq (m ):shouldBeCalled ():
13
+ mock (m ):shouldBeCalled ():
14
14
when (function () m () end )
15
15
end )
16
16
17
17
it (' should alert you when a function is not called' , function ()
18
- local m = moq .createMockFunction ()
18
+ local m = mock .createMockFunction ()
19
19
20
20
shouldFail (function ()
21
- moq (m ):shouldBeCalled ():
21
+ mock (m ):shouldBeCalled ():
22
22
when (function () end )
23
23
end )
24
24
end )
25
25
26
26
it (' should alert you when the wrong function is called' , function ()
27
- local m1 = moq .createMockFunction ()
28
- local m2 = moq .createMockFunction ()
27
+ local m1 = mock .createMockFunction ()
28
+ local m2 = mock .createMockFunction ()
29
29
30
30
shouldFail (function ()
31
- moq (m1 ):shouldBeCalled ():
31
+ mock (m1 ):shouldBeCalled ():
32
32
when (function () m2 () end )
33
33
end )
34
34
end )
35
35
36
36
it (' should alert you when a function is called unexpectedly' , function ()
37
- local m = moq .createMockFunction ()
37
+ local m = mock .createMockFunction ()
38
38
39
39
shouldFail (function ()
40
40
m ()
41
41
end )
42
42
end )
43
43
44
44
it (' should allow you to verify that a function has been called with the correct arguments' , function ()
45
- local m = moq .createMockFunction ()
45
+ local m = mock .createMockFunction ()
46
46
47
- moq (m ):shouldBeCalledWith (1 , ' 2' ):
47
+ mock (m ):shouldBeCalledWith (1 , ' 2' ):
48
48
when (function () m (1 , ' 2' ) end )
49
49
end )
50
50
51
51
it (' should alert you when a function has been called with incorrect arguments' , function ()
52
- local m = moq .createMockFunction ()
52
+ local m = mock .createMockFunction ()
53
53
54
54
shouldFail (function ()
55
- moq (m ):shouldBeCalledWith (1 , ' 2' ):
55
+ mock (m ):shouldBeCalledWith (1 , ' 2' ):
56
56
when (function () m (1 , ' 3' ) end )
57
57
end )
58
58
end )
59
59
60
60
it (' should allow you to specify the return value of a mocked function' , function ()
61
- local m = moq .createMockFunction ()
61
+ local m = mock .createMockFunction ()
62
62
63
- moq (m ):shouldBeCalled ():andWillReturn (4 ):
63
+ mock (m ):shouldBeCalled ():andWillReturn (4 ):
64
64
when (function ()
65
65
assert .is .equal (m (), 4 )
66
66
end )
67
67
end )
68
68
69
69
it (' should allow you to specify multiple return values for a mocked function' , function ()
70
- local m = moq .createMockFunction ()
70
+ local m = mock .createMockFunction ()
71
71
72
- moq (m ):shouldBeCalled ():andWillReturn (1 , 2 ):
72
+ mock (m ):shouldBeCalled ():andWillReturn (1 , 2 ):
73
73
when (function ()
74
74
r1 , r2 = m ()
75
75
assert .is .equal (r1 , 1 )
@@ -78,35 +78,35 @@ describe('The mock library', function()
78
78
end )
79
79
80
80
it (' should allow you to check that a function has been called multiple times' , function ()
81
- local m = moq .createMockFunction ()
81
+ local m = mock .createMockFunction ()
82
82
83
- moq (m ):shouldBeCalled ():
84
- andAlso (moq (m ):shouldBeCalledWith (1 , 2 , 3 )):
83
+ mock (m ):shouldBeCalled ():
84
+ andAlso (mock (m ):shouldBeCalledWith (1 , 2 , 3 )):
85
85
when (function ()
86
86
m ()
87
87
m (1 , 2 , 3 )
88
88
end )
89
89
end )
90
90
91
91
it (' should allow you to check that multiple functions are called' , function ()
92
- local m1 = moq .createMockFunction ()
93
- local m2 = moq .createMockFunction ()
92
+ local m1 = mock .createMockFunction ()
93
+ local m2 = mock .createMockFunction ()
94
94
95
- moq (m1 ):shouldBeCalled ():
96
- andAlso (moq (m2 ):shouldBeCalledWith (1 , 2 , 3 )):
95
+ mock (m1 ):shouldBeCalled ():
96
+ andAlso (mock (m2 ):shouldBeCalledWith (1 , 2 , 3 )):
97
97
when (function ()
98
98
m1 ()
99
99
m2 (1 , 2 , 3 )
100
100
end )
101
101
end )
102
102
103
103
it (' should allow you to mix and match call types' , function ()
104
- local m1 = moq .createMockFunction ()
105
- local m2 = moq .createMockFunction ()
104
+ local m1 = mock .createMockFunction ()
105
+ local m2 = mock .createMockFunction ()
106
106
107
- moq (m1 ):shouldBeCalled ():
108
- andAlso (moq (m2 ):shouldBeCalledWith (1 , 2 , 3 )):
109
- andThen (moq (m2 ):shouldBeCalledWith (1 ):andWillReturn (4 )):
107
+ mock (m1 ):shouldBeCalled ():
108
+ andAlso (mock (m2 ):shouldBeCalledWith (1 , 2 , 3 )):
109
+ andThen (mock (m2 ):shouldBeCalledWith (1 ):andWillReturn (4 )):
110
110
when (function ()
111
111
m1 ()
112
112
m2 (1 , 2 , 3 )
@@ -115,15 +115,15 @@ describe('The mock library', function()
115
115
end )
116
116
117
117
it (' should allow functions to be used to improve readability' , function ()
118
- local m1 = moq .createMockFunction ()
119
- local m2 = moq .createMockFunction ()
118
+ local m1 = mock .createMockFunction ()
119
+ local m2 = mock .createMockFunction ()
120
120
121
121
function somethingShouldHappen ()
122
- return moq (m1 ):shouldBeCalled ()
122
+ return mock (m1 ):shouldBeCalled ()
123
123
end
124
124
125
125
function anotherThingShouldHappen ()
126
- return moq (m2 ):shouldBeCalledWith (1 , 2 , 3 )
126
+ return mock (m2 ):shouldBeCalledWith (1 , 2 , 3 )
127
127
end
128
128
129
129
function codeUnderTestRuns ()
@@ -142,10 +142,10 @@ describe('The mock library', function()
142
142
bar = function () end
143
143
}
144
144
145
- mockedTable = moq .createMockTable (someTable )
145
+ mockedTable = mock .createMockTable (someTable )
146
146
147
- moq (mockedTable .foo ):shouldBeCalledWith (1 ):andWillReturn (2 ):
148
- andAlso (moq (mockedTable .bar ):shouldBeCalled ()):
147
+ mock (mockedTable .foo ):shouldBeCalledWith (1 ):andWillReturn (2 ):
148
+ andAlso (mock (mockedTable .bar ):shouldBeCalled ()):
149
149
when (function ()
150
150
mockedTable .foo (1 )
151
151
mockedTable .bar ()
@@ -158,9 +158,9 @@ describe('The mock library', function()
158
158
foo = function () end
159
159
}
160
160
161
- mockedTable = moq .createMockTable (someTable )
161
+ mockedTable = mock .createMockTable (someTable )
162
162
163
- moq (mockedTable .foo ):shouldBeCalledWith (1 ):andWillReturn (2 ):
163
+ mock (mockedTable .foo ):shouldBeCalledWith (1 ):andWillReturn (2 ):
164
164
when (function ()
165
165
mockedTable :foo (1 )
166
166
end )
@@ -173,10 +173,10 @@ describe('The mock library', function()
173
173
function someObject :foo () end
174
174
function someObject :bar () end
175
175
176
- mockedObject = moq .createMockObject (someObject )
176
+ mockedObject = mock .createMockObject (someObject )
177
177
178
- moq (mockedObject .foo ):shouldBeCalledWith (1 ):andWillReturn (2 ):
179
- andAlso (moq (mockedObject .bar ):shouldBeCalled ()):
178
+ mock (mockedObject .foo ):shouldBeCalledWith (1 ):andWillReturn (2 ):
179
+ andAlso (mock (mockedObject .bar ):shouldBeCalled ()):
180
180
when (function ()
181
181
mockedObject :foo (1 )
182
182
mockedObject :bar ()
@@ -189,9 +189,9 @@ describe('The mock library', function()
189
189
190
190
function someObject :foo () end
191
191
192
- mockedObject = moq .createMockObject (someObject )
192
+ mockedObject = mock .createMockObject (someObject )
193
193
194
- moq (mockedObject .foo ):shouldBeCalledWith (1 ):andWillReturn (2 ):
194
+ mock (mockedObject .foo ):shouldBeCalledWith (1 ):andWillReturn (2 ):
195
195
when (function ()
196
196
mockedObject .foo (1 )
197
197
end )
0 commit comments