From c2ef1d7b32863d662b4decc8176604a49f289869 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 17 Mar 2018 18:12:31 +0000 Subject: util.async: tests: Add helper function to create mock watcher callbacks --- spec/util_async_spec.lua | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'spec') 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() -- cgit v1.2.3