# Spec assertion with custom message?

**URL:** <https://forum.crystal-lang.org/t/spec-assertion-with-custom-message/1781>\
**Category:** Help & Support\
**Created:** [March 1, 2020, 6:00pm UTC](https://forum.crystal-lang.org/t/spec-assertion-with-custom-message/1781 "2020-03-01T18:00:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ejstembler](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/ejstembler/32/553_2.png) [@ejstembler](https://forum.crystal-lang.org/u/ejstembler)\
**Post date:** [March 1, 2020, 6:00pm UTC](https://forum.crystal-lang.org/t/spec-assertion-with-custom-message/1781/1 "2020-03-01T18:00:52Z")

</div>

Is there a way to specify an assertion failure message?

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

```

I know in Ruby RSpec and [MiniTest](https://docs.ruby-lang.org/en/2.1.0/MiniTest/Assertions.html#method-i-assert) you can do this. If there’s nothing like this for Crystal Spec, then that’s fine, I can use `puts` or `stdout`/`stderr`…

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/blacksmoke16/32/1241_2.png) [@Blacksmoke16](https://forum.crystal-lang.org/u/Blacksmoke16)\
**Post date:** [March 1, 2020, 6:13pm UTC](https://forum.crystal-lang.org/t/spec-assertion-with-custom-message/1781/2 "2020-03-01T18:13:48Z")

</div>

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

```auto
fail "#{missing_items.size} missing items" if missing_items.size > 0

```

---

<div class="post-metadata">

**Author:** ![ejstembler](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/ejstembler/32/553_2.png) [@ejstembler](https://forum.crystal-lang.org/u/ejstembler)\
**Post date:** [March 1, 2020, 6:15pm UTC](https://forum.crystal-lang.org/t/spec-assertion-with-custom-message/1781/3 "2020-03-01T18:15:38Z")

</div>

Thanks for pointing that out!

---

<div class="post-metadata">

**Author:** ![asterite](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/asterite/32/60_2.png) [@asterite](https://forum.crystal-lang.org/u/asterite)\
**Post date:** [March 1, 2020, 6:34pm UTC](https://forum.crystal-lang.org/t/spec-assertion-with-custom-message/1781/4 "2020-03-01T18:34:53Z")

</div>

We could add that to spec
