diff spec/util_async_spec.lua @ 8681:0c077800cd70

util.async: Make parameters to async.runner() optional
author Matthew Wild <mwild1@gmail.com>
date Fri, 23 Mar 2018 14:02:33 +0000
parents 2aa85b0cd2b8
children 867ac771fb6e
line wrap: on
line diff
--- a/spec/util_async_spec.lua	Fri Mar 23 14:01:42 2018 +0100
+++ b/spec/util_async_spec.lua	Fri Mar 23 14:02:33 2018 +0000
@@ -94,6 +94,26 @@
 			assert.equal(last_item, values[#values]);
 		end);
 
+		it("should work with no parameters", function ()
+			local item = "fail";
+			local r = async.runner();
+			local f = spy.new(function () item = "success"; end);
+			r:run(f);
+			assert.spy(f).was.called();
+			assert.equal(item, "success");
+		end);
+
+		it("supports a default error handler", function ()
+			local item = "fail";
+			local r = async.runner();
+			local f = spy.new(function () error("test error"); end);
+			assert.error_matches(function ()
+				r:run(f);
+			end, "test error");
+			assert.spy(f).was.called();
+			assert.equal(item, "fail");
+		end);
+
 		describe("#errors", function ()
 			describe("should notify", function ()
 				local last_processed_item, last_error;