Testing the platform · 54 / 69
Handle changing responses
YOUR TASK
Make this happen
A sequence mock returns a different tuple on each call. This exposes code that ignores later responses or caches a result incorrectly.
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) local ok, value = ctx.cache.get(key) return "first" end
lesson.test.lua
local t = require("test")
local subject = require("cococo.subject")
t.it("observes both responses", function()
local s = subject.load()
t.mock
.host("ctx.cache.get")
:sequence({ { true, "first" }, { true, "second" } })
t.expect(s.read("job")):eq("first")
t.expect(s.read("job")):eq("second")
end)