Merge remote-tracking branch 'myk002/myk_multi_mock' into develop

develop
lethosor 2021-06-25 01:27:46 -04:00
commit 4945018e92
No known key found for this signature in database
GPG Key ID: 76A269552F4F58C1
2 changed files with 12 additions and 4 deletions

@ -81,9 +81,9 @@ function mock.restore(...)
return _patch_impl(patches, callback, true)
end
function mock.func(return_value)
function mock.func(...)
local f = {
return_value = return_value,
return_values = {...},
call_count = 0,
call_args = {},
}
@ -92,7 +92,7 @@ function mock.func(return_value)
__call = function(self, ...)
self.call_count = self.call_count + 1
table.insert(self.call_args, {...})
return self.return_value
return table.unpack(self.return_values)
end,
})

@ -203,6 +203,14 @@ end
function test.func_call_return_value()
local f = mock.func(7)
expect.eq(f(), 7)
f.return_value = 9
f.return_values = {9}
expect.eq(f(), 9)
end
function test.func_call_return_multiple_values()
local f = mock.func(7,5,{imatable='snarfsnarf'})
local a, b, c = f()
expect.eq(7, a)
expect.eq(5, b)
expect.table_eq({imatable='snarfsnarf'}, c)
end