waterlink / spec2.cr

Enhanced `spec` testing library for [Crystal](http://crystal-lang.org/).
MIT License
103 stars 22 forks source link

Printing the backtrace of errored examples fails #59

Open ThunderKey opened 6 years ago

ThunderKey commented 6 years ago

Steps to reproduce

I've added a raise "test" to any test. (For example in "Spec2::Matchers eq(...) passes when values are equal")

Expected behavior

It should print

In example: Spec2::Matchers eq(...) passes when values are equal
    Failure: test
    [Backtrace]

Finished in 3.75 milliseconds
Examples: 60, failures: 1, pending: 0

Actual behavior

It prints

In example: Spec2::Matchers eq(...) passes when values are equal
    Failure: test
Error running at_exit handler: Nil assertion failed

Problem

The reporters do no expect an exception to have no callstack. Eg. src/reporters/default.cr:58

But since the ExpectationNotMet for errored examples never gets raised it does not get a callstack. src/runners/default.cr:37

Possible Solutions

I see two solutions:

  1. Copy the callstack (which I think is pretty hacky)
  2. Only print the backtrace in the reporters if it exists and print the cause if it has one.

In my opinion the second one is the better option, but it must be added in each reporter. Perhaps introducing a report_errors would be an option since both the Default and the Doc Reporters have the same code.

You can tell me which one you would like to use, respectively if you have a better idea and I'll create a pull request.