Software /
code /
prosody
Changeset
8623:ab242c513bf4
util.async: tests: Add helper function to create mock watcher callbacks
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 17 Mar 2018 18:12:31 +0000 |
parents | 8622:92fee8a6c988 |
children | 8624:5325f0e1791b |
files | spec/util_async_spec.lua |
diffstat | 1 files changed, 15 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/spec/util_async_spec.lua Sat Mar 17 23:00:04 2018 +0100 +++ b/spec/util_async_spec.lua Sat Mar 17 18:12:31 2018 +0000 @@ -8,17 +8,23 @@ else print = function () end end + + local function mock_watchers() + return setmetatable(mock{ + ready = function () end; + waiting = function () end; + error = function () end; + }, { + __index = function (_, event) + -- Unexpected watcher called + assert(false); + end; + }) + end + local function new(func, name) local log = {}; - return async.runner(func, setmetatable({}, { - __index = function (_, event) - return function (runner, err) - print(name or runner.id, "event", event, err) - print "--" - table.insert(log, { event = event, err = err }); - end; - end; - })), log; + return async.runner(func, mock_watchers()), log; end describe("#runner", function() it("should work", function()