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 | c2ef1d7b32863d662b4decc8176604a49f289869 (patch) | |
tree | 31e0916480ee1f00bd65085377f077121d8791f9 /spec/util_async_spec.lua | |
parent | f8e818026229579e5201b6225866d8b072ad586a (diff) | |
download | prosody-c2ef1d7b32863d662b4decc8176604a49f289869.tar.gz prosody-c2ef1d7b32863d662b4decc8176604a49f289869.zip |
util.async: tests: Add helper function to create mock watcher callbacks
Diffstat (limited to 'spec/util_async_spec.lua')
-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() |