diff options
author | Matthew Wild <mwild1@gmail.com> | 2018-03-17 18:12:31 +0000 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2018-03-17 18:12:31 +0000 |
commit | 62e076edbbaddeac1664d107d25c25fc9b9db385 (patch) | |
tree | 31e0916480ee1f00bd65085377f077121d8791f9 /spec | |
parent | 6dd39bd91112ad99a474a3b7f9881524e151e7cf (diff) | |
download | prosody-62e076edbbaddeac1664d107d25c25fc9b9db385.tar.gz prosody-62e076edbbaddeac1664d107d25c25fc9b9db385.zip |
util.async: tests: Add helper function to create mock watcher callbacks
Diffstat (limited to 'spec')
-rw-r--r-- | spec/util_async_spec.lua | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/spec/util_async_spec.lua b/spec/util_async_spec.lua index 955e3921..7cd125b7 100644 --- a/spec/util_async_spec.lua +++ b/spec/util_async_spec.lua @@ -8,17 +8,23 @@ describe("util.async", function() else print = function () end end - local function new(func, name) - local log = {}; - return async.runner(func, setmetatable({}, { + + local function mock_watchers() + return setmetatable(mock{ + ready = function () end; + waiting = function () end; + error = function () end; + }, { __index = function (_, event) - return function (runner, err) - print(name or runner.id, "event", event, err) - print "--" - table.insert(log, { event = event, err = err }); - end; + -- Unexpected watcher called + assert(false); end; - })), log; + }) + end + + local function new(func, name) + local log = {}; + return async.runner(func, mock_watchers()), log; end describe("#runner", function() it("should work", function() |