Spec assertion with custom message?

Is there a way to specify an assertion failure message?

missing_items.size.should eq(0), "#{missing_items.size} missing items"

I know in Ruby RSpec and MiniTest you can do this. If there’s nothing like this for Crystal Spec, then that’s fine, I can use puts or stdout/stderr

Would have to use https://crystal-lang.org/api/master/Spec/Methods.html#fail(msg,file=FILE,line=LINE)-instance-method and do like

fail "#{missing_items.size} missing items" if missing_items.size > 0
2 Likes

Thanks for pointing that out!

We could add that to spec

4 Likes