Skip to content

Commit 24275ba

Browse files
committed
Allow custom matchers. Closes #8.
1 parent 4e3f610 commit 24275ba

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

spec/mach_spec.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,4 +643,19 @@ describe('The mach library', function()
643643
end)
644644
end)
645645
end)
646+
647+
it('should allow custom matchers to be used', function()
648+
local function always_matches() return true end
649+
local function never_matches() return false end
650+
651+
f:should_be_called_with(mach.match({ a = 1, b = 2 }, always_matches)):when(function()
652+
f({ a = 11, b = 22 })
653+
end)
654+
655+
should_fail(function()
656+
f:should_be_called_with(mach.match({ a = 1, b = 2 }, never_matches)):when(function()
657+
f({ a = 1, b = 2 })
658+
end)
659+
end)
660+
end)
646661
end)

src/mach.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ function mach.mock_object(o, name)
9292
return mocked
9393
end
9494

95-
function mach.match(value)
96-
return setmetatable({ value = value, matcher = default_matcher }, mach_match)
95+
function mach.match(value, matcher)
96+
return setmetatable({ value = value, matcher = matcher or default_matcher }, mach_match)
9797
end
9898

9999
return setmetatable(mach, { __call = function(_, ...) return Expectation(...) end })

0 commit comments

Comments
 (0)