Skip to content

Commit b24fc15

Browse files
committed
Show call list when all calls do not occur. Closes #20.
1 parent ad3cf46 commit b24fc15

File tree

4 files changed

+62
-2
lines changed

4 files changed

+62
-2
lines changed

rockspecs/mach-4.4-0.rockspec

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package = 'mach'
2+
version = '4.4-0'
3+
source = {
4+
url = 'https://github.com/ryanplusplus/mach.lua/archive/v4.4-0.tar.gz',
5+
dir = 'mach.lua-4.4-0/src'
6+
}
7+
description = {
8+
summary = 'Simple mocking framework for Lua inspired by CppUMock and designed for readability.',
9+
homepage = 'https://github.com/ryanplusplus/mach.lua/',
10+
license = 'MIT <http://opensource.org/licenses/MIT>'
11+
}
12+
dependencies = {
13+
'lua >= 5.1'
14+
}
15+
build = {
16+
type = 'builtin',
17+
modules = {
18+
['mach'] = 'mach.lua',
19+
['mach.Expectation'] = 'mach/Expectation.lua',
20+
['mach.ExpectedCall'] = 'mach/ExpectedCall.lua',
21+
['mach.CompletedCall'] = 'mach/CompletedCall.lua',
22+
['mach.unexpected_call_error'] = 'mach/unexpected_call_error.lua',
23+
['mach.unexpected_args_error'] = 'mach/unexpected_args_error.lua',
24+
['mach.out_of_order_call_error'] = 'mach/out_of_order_call_error.lua',
25+
['mach.format_call_status'] = 'mach/format_call_status.lua',
26+
['mach.format_arguments'] = 'mach/format_arguments.lua',
27+
['mach.deep_compare_matcher'] = 'mach/deep_compare_matcher.lua',
28+
['mach.match'] = 'mach/match.lua',
29+
['mach.any'] = 'mach/any.lua',
30+
}
31+
}

spec/mach_spec.lua

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('The mach library', function()
3939
end)
4040

4141
it('should alert you when a function is not called', function()
42-
should_fail_with('not all calls occurred', function()
42+
should_fail_with('Not all calls occurred', function()
4343
f:should_be_called():when(function() end)
4444
end)
4545
end)
@@ -569,6 +569,25 @@ describe('The mach library', function()
569569
end)
570570
end)
571571

572+
it('should report completed and incomplete calls in not all calls occurred errors', function()
573+
local expected_failure =
574+
'Not all calls occurred\n' ..
575+
'Completed calls:\n' ..
576+
'\tf1()\n' ..
577+
'Incomplete calls:\n' ..
578+
'\tf2()\n' ..
579+
'\tf3()'
580+
581+
should_fail_with_exactly(expected_failure, function()
582+
f1:should_be_called():
583+
and_then(f2:should_be_called()):
584+
and_then(f3:should_be_called()):
585+
when(function()
586+
f1()
587+
end)
588+
end)
589+
end)
590+
572591
it('should omit the completed call list in an error when no calls were completed', function()
573592
local expected_failure =
574593
'Unexpected function call f3()\n' ..

src/mach/Expectation.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local CompletedCall = require 'mach.CompletedCall'
33
local unexpected_call_error = require 'mach.unexpected_call_error'
44
local unexpected_args_error = require 'mach.unexpected_args_error'
55
local out_of_order_call_error = require 'mach.out_of_order_call_error'
6+
local not_all_calls_occurred_error = require 'mach.not_all_calls_occurred_error'
67

78
local expectation = {}
89
expectation.__index = expectation
@@ -96,7 +97,7 @@ function expectation:when(thunk)
9697

9798
for _, call in pairs(self._calls) do
9899
if call:is_required() then
99-
error('not all calls occurred', 2)
100+
not_all_calls_occurred_error(self._completed_calls, self._calls, 2)
100101
end
101102
end
102103
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
local format_call_status = require 'mach.format_call_status'
2+
3+
return function(completed_calls, incomplete_calls, level)
4+
local message =
5+
'Not all calls occurred' ..
6+
format_call_status(completed_calls, incomplete_calls)
7+
8+
error(message, level + 1)
9+
end

0 commit comments

Comments
 (0)