File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -79,6 +79,8 @@ function MockExpectation:andWillReturn(...)
79
79
end
80
80
81
81
function MockExpectation :when (thunk )
82
+ if # self ._calls == 0 then error (' incomplete expectation' , 2 ) end
83
+
82
84
local function called (m , name , args )
83
85
assert (# self ._calls > 0 , ' unexpected call' )
84
86
assert (self ._calls [1 ]:functionMatches (m ), ' unexpected function "' .. name .. ' " called' , 2 )
@@ -93,6 +95,8 @@ function MockExpectation:when(thunk)
93
95
end
94
96
95
97
function MockExpectation :after (thunk )
98
+ if # self ._calls == 0 then error (' incomplete expectation' , 2 ) end
99
+
96
100
self :when (thunk )
97
101
end
98
102
Original file line number Diff line number Diff line change @@ -253,6 +253,22 @@ describe('The mock library', function()
253
253
end )
254
254
end )
255
255
256
+ it (' should fail if when is not preceeded by shouldBeCalled or shouldBeCalledWith' , function ()
257
+ shouldFailWith (' incomplete expectation' , function ()
258
+ local f = mock :mockFunction (' f' )
259
+
260
+ mock (f ):when (function () end )
261
+ end )
262
+ end )
263
+
264
+ it (' should fail if after is not preceeded by shouldBeCalled or shouldBeCalledWith' , function ()
265
+ shouldFailWith (' incomplete expectation' , function ()
266
+ local f = mock :mockFunction (' f' )
267
+
268
+ mock (f ):after (function () end )
269
+ end )
270
+ end )
271
+
256
272
-- ordering
257
273
258
274
-- allowed vs. not allowed functions on the expectation (ie: state machine for expectation)
You can’t perform that action at this time.
0 commit comments