Skip to content

Commit ea61543

Browse files
committed
Slight improvement to failure message for unexpected calls
1 parent 0ea96f0 commit ea61543

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

mock.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ function ExpectedCall:getReturnValues(...)
5353
return table.unpack(self._return)
5454
end
5555

56+
function ExpectedCall:toString()
57+
return
58+
end
5659

5760

5861
MockExpectation = {}
@@ -77,7 +80,7 @@ end
7780
function MockExpectation:when(thunk)
7881
local function called(m, name, args)
7982
assert(#self._calls > 0, 'unexpected call')
80-
assert(self._calls[1]:functionMatches(m), 'unexpected function "' .. name .. '" called', 2)
83+
assert(self._calls[1]:functionMatches(m), 'unexpected function call ' .. name .. '(' .. table.concat(args, ', ') .. ') occurred', 2)
8184
assert(self._calls[1]:argsMatch(args), 'unexpected arguments provided to function "' .. name .. '"')
8285

8386
return table.remove(self._calls, 1):getReturnValues()

spec/mock_spec.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('The mock library', function()
2828
it('should alert you when a function is not called', function()
2929
local f = mock:mockFunction('f')
3030

31-
shouldFail(function()
31+
shouldFailWith('not all calls occurred', function()
3232
mock(f):shouldBeCalled():
3333
when(function() end)
3434
end)
@@ -38,7 +38,7 @@ describe('The mock library', function()
3838
local f1 = mock:mockFunction('f1')
3939
local f2 = mock:mockFunction('f2')
4040

41-
shouldFailWith('unexpected function "f2" called', function()
41+
shouldFailWith('unexpected function call f2() occurred', function()
4242
mock(f1):shouldBeCalled():
4343
when(function() f2() end)
4444
end)
@@ -47,7 +47,7 @@ describe('The mock library', function()
4747
it('should alert you when a function is called unexpectedly', function()
4848
local f = mock:mockFunction('f')
4949

50-
shouldFailWith('unexpected function "f" called', function()
50+
shouldFailWith('unexpected function call f() occurred', function()
5151
f()
5252
end)
5353
end)

0 commit comments

Comments
 (0)