Skip to content

Commit 2362dcb

Browse files
committed
Refactored to remove duplicated code
1 parent 54aabd6 commit 2362dcb

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

src/mach.lua

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ function mock_called(m, name, args)
2020
return subscriber(m, name, args)
2121
end
2222

23+
function create_expectation(_, method)
24+
return function(self, ...)
25+
local expectation = Expectation(self)
26+
return expectation[method](expectation, ...)
27+
end
28+
end
29+
2330
function mach.mock_function(name)
2431
name = name or '<anonymous>'
2532
local f = {}
@@ -29,12 +36,7 @@ function mach.mock_function(name)
2936
return mock_called(f, name, table.pack(...))
3037
end,
3138

32-
__index = function(_, method)
33-
return function(self, ...)
34-
local expectation = Expectation(self)
35-
return expectation[method](expectation, ...)
36-
end
37-
end
39+
__index = create_expectation
3840
})
3941

4042
return f
@@ -50,12 +52,7 @@ function mach.mock_method(name)
5052
return mock_called(m, name, args)
5153
end,
5254

53-
__index = function(_, method)
54-
return function(self, ...)
55-
local expectation = Expectation(self)
56-
return expectation[method](expectation, ...)
57-
end
58-
end
55+
__index = create_expectation
5956
})
6057

6158
return m

0 commit comments

Comments
 (0)