Good Code
The good version names the invalid input and asserts the exact error code. A regression in title validation will fail clearly.
Lesson 10
Write Lua tests around observable module behavior instead of only checking that functions return truthy values.
describe("review rules", function()
it("rejects a missing title", function()
-- The fixture names the invalid input the module must reject.
local ok, error = ReviewRules.validate({ title = nil, score = 5 })
assert.is_false(ok)
assert.are.equal("title_required", error.code)
end)
end)describe("review rules", function()
it("validates reviews", function()
-- Truthy checks miss the actual validation contract.
assert.is_truthy(ReviewRules.validate({}))
end)
end)The good version names the invalid input and asserts the exact error code. A regression in title validation will fail clearly.
The bad version only checks for a truthy result. It does not protect the validation contract that callers rely on.