Aleksandrus
Aleksandrus

Reputation: 1754

RSpec - How to get a better error message?

I am used to PHPUnit, so I found RSpec to be inferior when it comes to showing what has gone wrong, where and why.

For example, in PHPUnit, I can get the stack trace when an exception is raised (and even with -b option in RSpec, all I can get is the stack trace of RSpec exceptions, and not Rails's)

Also, when some error occurs, it shows you the ACTUAL value and the EXPECTED value.

Those two features I'd like to achieve in RSpec. Getting a detailed error message that includes the stack trace, in case of an Exception of Ruby or of Rails, and to know what was the actual value.

Any ideas of how to accomplish this?

Upvotes: 2

Views: 1968

Answers (1)

Simone Carletti
Simone Carletti

Reputation: 176352

If you run

rspec --help

you will see all the options you can pass (or configure via RSpec.configure) to the runner. One of the will force RSpec to show the entire backtrace

-b, --backtrace                  Enable full backtrace.

You can also configure the excluded/included lines to control how deep you want the backtrace to go.

As for the actuals vs expected value, this is supported by default in RSpec. See for example

enter image description here

For custom-defined objects, it also print out a diff.

Upvotes: 5

Related Questions