# HG changeset patch # User Kim Alvefur # Date 1521648193 -3600 # Node ID 638ff2ad98e6b9b238287ecb967e77f456def026 # Parent a267dfa9d81df30b2a555a34dbfae59368d97dc1 util.pubsub: Add simple test covering publishing and retrieving an item diff -r a267dfa9d81d -r 638ff2ad98e6 spec/util_pubsub_spec.lua --- a/spec/util_pubsub_spec.lua Wed Mar 21 23:20:59 2018 +0100 +++ b/spec/util_pubsub_spec.lua Wed Mar 21 17:03:13 2018 +0100 @@ -28,4 +28,28 @@ end); end); end); + + describe("simple publishing", function () + local broadcaster = spy.new(function () end); + local service = pubsub.new({ broadcaster = broadcaster; }); + + it("creates a node", function () + assert.truthy(service:create("node", true)); + end); + + it("publishes an item", function () + assert.truthy(service:publish("node", true, "1", "item 1")); + end); + + it("called the broadcaster", function () + assert.spy(broadcaster).was_called(); + end); + + it("should return one item", function () + local ok, ret = service:get_items("node", true); + assert.truthy(ok); + assert.same({ "1", ["1"] = "item 1" }, ret); + end); + + end); end);