-
-
Notifications
You must be signed in to change notification settings - Fork 397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
should_not raise_error
annoyingly swallows original exception backtrace
#59
Comments
I'd prefer option 2. |
What are the pros of 2? To me, 1 sounds better. |
It's a failed expectation. I think it's more consistent with other failure messages if this gets wrapped up in a failure message rather than bubbling up directly. Why do you like 1 better? |
I haven't got the time to write proper tests etc for it at the moment, but this is a fairly simple version of the RaiseException matcher, but puts the backtrace the message. Probably could do with cleaning out the backtrace etc, but it works (at least with 1.3.2) |
This is in prep for #59--once I had some backtrace info, all of these would fail since they are doing exact string matches.
I took a first pass at implementing number 2 from above, but it's tricky to figure out how to format this correctly. Here's what I've got so far:
I don't think this is a very promising route to take. Thoughts? |
You want to go with #2 so that it is consistent with other expectations, formats nicely in the various reporters, etc I think the formatting you've got there is fine. Perhaps some sort of dividing text between the error message and the failure message? I'm thinking of the spacing getting mangled on people's terminals and it being difficult to decipher exception message vs expectation failure. |
The formatting consistency is a good point. Anyhow, one other option I just thought of: looking at the above, it's clear that the two backtraces are nearly identical except for a few frames. We could set the backtrace on the expectation failure error to the backtrace of the rescued error, so that the user gets the full backtrace as the "main" backtrace while keeping a consistently formatted failure message. Edit: another benefit of this approach is that I don't have to go through gymnastics to filter the backtrace the same as core does. |
So just have it be one long backtrace, originating from the rescued error? |
Yep. The message would be in the existing format, though. Sent from my iPhone On Sep 11, 2012, at 7:04 PM, Pat Maddox notifications@github.com wrote:
|
I've wanted this for so long, it's painful. I think the output in the example is fine. One important variation, though is that the positive matcher should work the same way: expect{ raise "boom"}.to raise_error(ArgumentError) should print the backtrace of the RuntimeError that actually gets raised. @myronmarston - are you onto a PR already? |
Not yet. I've got the code lying around on my machine. There's some refactoring that needs to happen in rspec-core first to make it possible for this to use the same backtrace filtering logic core uses. Thanks for reminding me about this! |
This will be used by rspec/rspec-expectations#59.
This will be used by rspec/rspec-expectations#59.
It's hard to troubleshoot unexpected errors when the backtrace is silenced, as it was previously. Closes #59.
Given a spec like this:
When an error is raised, the spec fails (as it should) but the failure backtrace isn't very useful. The backtrace I care about is for the original error, not the error raised by the
raise_error
matcher. Really, it would be better to useit("does not raise an error") { something }
but the matcher may still be useful in some situations (i.e. to ensure every spec has at least one expectation) and I've got some error reports that have unhelpful backtraces because of this (see this VCR issue, for example).It would be nice to have the
raise_error
matcher preserve the original exception backtrace. A few ideas:raise_error
in theshould_not
case should be pure syntactic sugar that doesn't actually do anything but execute the block? That way the original error (with associated backtrace) will bubble up and get printed. Users can still use the matcher to make it clear what expectation they are setting for the example.full_backtrace
configuration option, although we'd need to find a way to do that in such a way that it doesn't couple rspec-expectations to rspec-core.Myron
The text was updated successfully, but these errors were encountered: