File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -54,7 +54,6 @@ function ExpectedCall:getReturnValues(...)
54
54
end
55
55
56
56
57
-
58
57
MockExpectation = {}
59
58
60
59
function MockExpectation :new (m )
@@ -70,7 +69,12 @@ function MockExpectation:new(m)
70
69
end
71
70
72
71
function MockExpectation :andWillReturn (...)
72
+ if # self ._calls == 0 then
73
+ error (' cannot set return value for an unspecified call' , 2 )
74
+ end
75
+
73
76
self ._calls [# self ._calls ]:setReturnValues (... )
77
+
74
78
return self
75
79
end
76
80
Original file line number Diff line number Diff line change @@ -245,6 +245,14 @@ describe('The mock library', function()
245
245
end )
246
246
end )
247
247
248
+ it (' should fail if andWillReturn is not preceeded by shouldBeCalled or shouldBeCalledWith' , function ()
249
+ shouldFailWith (' cannot set return value for an unspecified call' , function ()
250
+ local f = mock :mockFunction (' f' )
251
+
252
+ mock (f ):andWillReturn (1 )
253
+ end )
254
+ end )
255
+
248
256
-- ordering
249
257
250
258
-- 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