@@ -126,14 +126,14 @@ describe('The mock library', function()
126
126
return mock (m2 ):shouldBeCalledWith (1 , 2 , 3 )
127
127
end
128
128
129
- function codeUnderTestRuns ()
129
+ function theCodeUnderTestRuns ()
130
130
m1 ()
131
131
m2 (1 , 2 , 3 )
132
132
end
133
133
134
134
somethingShouldHappen ():
135
135
andAlso (anotherThingShouldHappen ()):
136
- when (codeUnderTestRuns )
136
+ when (theCodeUnderTestRuns )
137
137
end )
138
138
139
139
it (' should allow a table of functions to be mocked' , function ()
@@ -173,7 +173,7 @@ describe('The mock library', function()
173
173
function someObject :foo () end
174
174
function someObject :bar () end
175
175
176
- mockedObject = mock :mockObject (someObject )
176
+ local mockedObject = mock :mockObject (someObject )
177
177
178
178
mock (mockedObject .foo ):shouldBeCalledWith (1 ):andWillReturn (2 ):
179
179
andAlso (mock (mockedObject .bar ):shouldBeCalled ()):
@@ -189,7 +189,7 @@ describe('The mock library', function()
189
189
190
190
function someObject :foo () end
191
191
192
- mockedObject = mock :mockObject (someObject )
192
+ local mockedObject = mock :mockObject (someObject )
193
193
194
194
mock (mockedObject .foo ):shouldBeCalledWith (1 ):andWillReturn (2 ):
195
195
when (function ()
@@ -198,7 +198,45 @@ describe('The mock library', function()
198
198
end )
199
199
end )
200
200
201
+ it (' should let you expect a function to be called multiple times' , function ()
202
+ local f = mock :mockFunction ()
203
+
204
+ mock (f ):shouldBeCalledWith (2 ):andWillReturn (1 ):multipleTimes (3 ):
205
+ when (function ()
206
+ assert (f (2 ) == 1 )
207
+ assert (f (2 ) == 1 )
208
+ assert (f (2 ) == 1 )
209
+ end )
210
+ end )
211
+
212
+ it (' should fail if a function is not called enough times' , function ()
213
+ shouldFail (function ()
214
+ local f = mock :mockFunction ()
215
+
216
+ mock (f ):shouldBeCalledWith (2 ):andWillReturn (1 ):multipleTimes (3 ):
217
+ when (function ()
218
+ assert (f (2 ) == 1 )
219
+ assert (f (2 ) == 1 )
220
+ end )
221
+ end )
222
+ end )
223
+
224
+ it (' should fail if a function is called too many times' , function ()
225
+ shouldFail (function ()
226
+ local f = mock :mockFunction ()
227
+
228
+ mock (f ):shouldBeCalledWith (2 ):andWillReturn (1 ):multipleTimes (2 ):
229
+ when (function ()
230
+ assert (f (2 ) == 1 )
231
+ assert (f (2 ) == 1 )
232
+ assert (f (2 ) == 1 )
233
+ end )
234
+ end )
235
+ end )
236
+
201
237
-- ordering
202
238
239
+ -- multiple times
240
+
203
241
-- allowed vs. not allowed functions on the expectation (ie: state machine for expectation)
204
242
end )
0 commit comments