waterlink / spec2.cr

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

Callstack is not very helpful because the most important line is missing #62

Closed alexanderadam closed 6 years ago

alexanderadam commented 6 years ago

Failed expectations won't show the proper line where the expectation actually failed. In fact: everything but this line shown.

I made a minimal example that shows this:

require "spec2"
require "./spec_helper"

describe MissingCallstackLines do
  it "shows a proper stacktrace" do
    false.should eq(true)
  end
end

Spec2.describe MissingCallstackLines do
  it "does not show a proper stacktrace" do
    expect(false).to eq(true)
  end
end

As you can see integrated spec.cr shows clearly where the expectation failed whereas the "nearest" line of spec2.cr is missing_callstack_lines_spec.cr:10 (although it's still not very helpful if you have a bunch of expectations here) and the other lines of the callstack aren't relevant at all.

screenshot_20180216_155344

alexanderadam commented 6 years ago

I closed it for now because I believe it might be a deeper issue in crystal callstack itself.

But if you know a solution you could solve it anyway of course 😉

rdp commented 4 years ago

So your complaint was that it showed the proper line number only at the top?

 crystal spec spec/missing_callstack_lines_spec.cr:4
F

Failures:

  1) MissingCallstackLines shows a proper stacktrace
     Failure/Error: false.should eq(true)

       Expected: true
            got: false

     # spec/missing_callstack_lines_spec.cr:6

Finished in 119 microseconds
1 examples, 1 failures, 0 errors, 0 pending

Failed examples:

crystal spec spec/missing_callstack_lines_spec.cr:5 # MissingCallstackLines shows a proper stacktrace
F

In example: MissingCallstackLines does not show a proper stacktrace
    Failure: Expected to be equal:
        Expected:    true
        Actual:      false
       # YOU WANTED LINE 6 ALSO HERE?
    lib/spec2/src/expectation.cr:19:7 in 'to'
    spec/missing_callstack_lines_spec.cr:20:11 in 'run'
    lib/spec2/src/runners/default.cr:27:13 in 'run_context'
    lib/spec2/src/runners/default.cr:43:11 in 'run_context'
    lib/spec2/src/high_runner.cr:66:7 in 'run'
    lib/spec2/src/spec2.cr:57:3 in 'run'
    lib/spec2/src/spec2.cr:72:3 in '->'
    /usr/local/Cellar/crystal/0.33.0/src/kernel.cr:255:3 in 'run'
    /usr/local/Cellar/crystal/0.33.0/src/kernel.cr:451:3 in 'run'
    /usr/local/Cellar/crystal/0.33.0/src/kernel.cr:503:3 in 'exit'
    /usr/local/Cellar/crystal/0.33.0/src/spec/dsl.cr:280:5 in 'finish_run'
    /usr/local/Cellar/crystal/0.33.0/src/spec/dsl.cr:273:7 in '->'
    /usr/local/Cellar/crystal/0.33.0/src/kernel.cr:255:3 in 'run'
    /usr/local/Cellar/crystal/0.33.0/src/crystal/main.cr:45:14 in 'main'
    /usr/local/Cellar/crystal/0.33.0/src/crystal/main.cr:115:3 in 'main'

Finished in 48.01 milliseconds
Examples: 1, failures: 1, pending: 0

or did you want line 4 to be mentioned "somewhere"? Just wondering, cheers!

alexanderadam commented 4 years ago

So your complaint was that it showed the proper line number only at the top?

Not at all. Please compare the two specs in the screenshot and it's corresponding source code:

The first example (false.should eq(true)) was just added for comparison reasons and it is working & showing the proper line where the mismatch happened (line 6).

But the second example (expect(false).to eq(true)) with the mismatch in line 12 does not show up at all. It doesn't even show anything about the file missing_callstack_lines_spec.cr. So the stacktrace actually showed internal lines (i.e. kernel.cr and main.cr) which aren't helpful at all but it hides the only thing that would actually be relevant here (missing_callstack_lines_spec.cr:12). It's like the filter about relevant information is inverted.

Back then (2015 - 2018) spec2.cr was the only library that had the newer, non-invasive spec syntax (with expect and other features) but IMHO spec2.cr never really worked properly. However, at some point @icy-arctic-fox created :mega: Spectator — a wonderful and working spec library with all the features you would expect. It doesn't have this particular issue 62 (or any other issues that would bother me). Therefore also this issue isn't relevant for me anymore.