lunarmodules / busted

Elegant Lua unit testing.
https://lunarmodules.github.io/busted/
MIT License
1.39k stars 184 forks source link

confusing behavior of spy matcher #682

Closed StarlightIbuki closed 1 year ago

StarlightIbuki commented 2 years ago
local function contain(state, arguments)
  local expected = arguments[1]
  return function(value)
    return type(value) == "string" and value:find(expected)
  end
end

assert:register("matcher", "contain", contain)

print(matcher.contain("string")("substring")) -- false

It turns out matcher treats all non-true values as false. It should be written like type(value) == "string" and value:find(expected) and true.

If this is expected, it should be documented. I did not find where to create PR or submit patches for documentation.

There's also a typo "you should should".

Tieske commented 2 years ago

The documentation is in the gh-pages branch