Not sure why simple test throws exception


I have been away from Crystal for a couple of month and today I decided to make a new app in Crystal.

I have this stupid simple test where I assert that the given Hash is not empty.

it "should not be empty" do
  hash = # => Hash(String, String)

  hash.empty?.should be_false

This I would expect to just fail with some red text saying expected: this - got: this - I have not implemented the method yet, all I have at this point is

module Foo
  def : Hash(String, String)
    Hash(String, String).new

The test, however, says that everything passes and the throws an exception.


Finished in 48 microseconds
0 examples, 0 failures, 0 errors, 0 pending
Unhandled exception: Expected: false
     got: true (Spec::AssertionFailed)
  from /usr/lib/crystal/spec/ in 'fail'
  from /usr/lib/crystal/spec/ in 'should'
  from eval:5:1 in '__crystal_main'
  from /usr/lib/crystal/crystal/ in 'main_user_code'
  from /usr/lib/crystal/crystal/ in 'main'
  from /usr/lib/crystal/crystal/ in 'main'
  from /usr/lib/ in '__libc_start_main'
  from /home/crystal/.cache/crystal/crystal-run-eval.tmp in '_start'
  from ???

Anyone that has an idea why this throws an exception?

Your playground link isn’t the same as what you provided in the two code example. The gist of it is the Spec module is raising exceptions, which are normally caught within an it block, but since your assertion isn’t wrapped in one, it bubbles up.


Ah I see! I just checked my own tests again and I see that my test was wrapped in a describe instead of an it block.