Testing the platform · 50 / 69
Avoid duplicate calls
YOUR TASK
Make this happen
Repeated host calls can duplicate work or side effects. The called_once matcher asserts that a single request causes one cache read.
Read the cases in
lesson.test.lua, then choose Check solution to see what needs to change.Update
subject.luauntil every test passes. Keep the supplied tests unchanged.
Read the starter and tests
subject.lua
exports.read = function(key: string) ctx.cache.get(key) return ctx.cache.get(key) end
lesson.test.lua
local t = require("test")
local subject = require("cococo.subject")
t.it("one request", function()
local s = subject.load()
t.mock.host("ctx.cache.get"):returns(true, "x")
s.read("order")
t.expect(t.mock.spy("ctx.cache.get")):called_once()
end)