Skip to content

Commit aa289f1

Browse files
committed
Raise error when and_will_raise_error used without an expected call
1 parent 7636860 commit aa289f1

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

spec/mach_spec.lua

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,20 +291,27 @@ describe('The mach library', function()
291291
end)
292292
end)
293293

294-
it('should fail if and_will_return is not preceeded by should_be_called or should_be_called_with', function()
294+
it('should fail if and_will_return is not preceeded by an expected call', function()
295295
should_fail_with('cannot set return value for an unspecified call', function()
296296
local f = mach.mock_function('f')
297297
f:and_will_return(1)
298298
end)
299299
end)
300300

301-
it('should fail if when is not preceeded by should_be_called or should_be_called_with', function()
301+
it('should fail if and_will_raise_error is not preceeded by an expected call', function()
302+
should_fail_with('cannot set error for an unspecified call', function()
303+
local f = mach.mock_function('f')
304+
f:and_will_raise_error(1)
305+
end)
306+
end)
307+
308+
it('should fail if when is not preceeded by an expected call', function()
302309
should_fail_with('incomplete expectation', function()
303310
f:when(function() end)
304311
end)
305312
end)
306313

307-
it('should fail if after is not preceeded by should_be_called or should_be_called_with', function()
314+
it('should fail if after is not preceeded by an expected call', function()
308315
should_fail_with('incomplete expectation', function()
309316
f:after(function() end)
310317
end)

src/mach/Expectation.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ function expectation:and_will_return(...)
2929
end
3030

3131
function expectation:and_will_raise_error(...)
32-
-- if not self._call_specified then
33-
-- error('cannot set return value for an unspecified call', 2)
34-
-- end
32+
if not self._call_specified then
33+
error('cannot set error for an unspecified call', 2)
34+
end
3535

3636
self._calls[#self._calls]:set_error(...)
3737

0 commit comments

Comments
 (0)