Skip to content

Commit 677a138

Browse files
committed
Fixed handling of deeply nested expectations. Closes #17.
1 parent c7ddd98 commit 677a138

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

spec/mach_spec.lua

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,19 @@ describe('The mach library', function()
408408
end)
409409
end)
410410

411+
it('should correctly handle ordering when expected calls are deeply nested', function()
412+
f:should_be_called_with(1):
413+
and_also(f:should_be_called_with(2):
414+
and_then(f:should_be_called_with(3):
415+
and_also(f:should_be_called_with(4)))):
416+
when(function()
417+
f(2)
418+
f(1)
419+
f(4)
420+
f(3)
421+
end)
422+
end)
423+
411424
it('should allow a strictly ordered call to occur after a missing optional call', function()
412425
f1:may_be_called():and_then(f2:should_be_called()):when(function()
413426
f2()

src/mach/Expectation.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ function expectation:after(thunk)
110110
end
111111

112112
function expectation:and_then(other)
113-
for _, call in ipairs(other._calls) do
114-
call:fix_order()
113+
for i, call in ipairs(other._calls) do
114+
if i == 1 then call:fix_order() end
115115
table.insert(self._calls, call)
116116
end
117117

0 commit comments

Comments
 (0)