Testing the platform · 49 / 69
Verify the requested key
YOUR TASK
Make this happen
A spy records how a mocked host function was called. Forward the caller’s key unchanged instead of hard-coding a cache key.
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)
return ctx.cache.get("fixed")
end
lesson.test.lua
local t = require("test")
local subject = require("cococo.subject")
t.it("forwards the key", function()
local s = subject.load()
t.mock.host("ctx.cache.get"):returns(true, "x")
s.read("order:42")
t.expect(t.mock.spy("ctx.cache.get")):called_with("order:42")
end)