I have tried the code in the README file, with the addition of a namespace, as per #10:
local assert = require "luassert"
local s = require("say") --our i18n lib, installed through luarocks, included as a luassert dependency
local function has_property(table, prop)
for _, value in pairs(table) do
if value == prop then
return true
end
end
return false, {prop, table}
end
s:set("en", "assertion.has_property.positive", "Expected property %s in:\n%s")
s:set("en", "assertion.has_property.negative", "Expected property %s to not be in:\n%s")
assert:register("assertion", "has_property", has_property, "assertion.has_property.positive", "assertion.has_property.negative")
assert.has_property({ name = "jack" }, "name") -- this should "pass"
assert.has_property({ name = "jack" }, "foo") -- this should "fail"
Unfortunately the error message I get when executing this is empty:
➜ lua lua test_has_property_assertion.lua
lua: /usr/local/share/lua/5.1/luassert/assert.lua:12:
stack traceback:
[C]: in function 'error'
/usr/local/share/lua/5.1/luassert/assert.lua:12: in function 'has_property'
test_has_property_assertion.lua:18: in main chunk
[C]: ?
I expected to see the message "Expected property foo in table #..." somewhere on that text, but it was not.
I have tried the code in the README file, with the addition of a namespace, as per #10:
Unfortunately the error message I get when executing this is empty:
I expected to see the message "Expected property foo in table #..." somewhere on that text, but it was not.