# HG changeset patch # User Matthew Wild # Date 1521310351 0 # Node ID ab242c513bf46c7a9458757688a67232c3449bf2 # Parent 92fee8a6c988da1ef37f764229d8f8bf2f15f521 util.async: tests: Add helper function to create mock watcher callbacks diff -r 92fee8a6c988 -r ab242c513bf4 spec/util_async_spec.lua --- 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()