Tweak that RSpec error message
Your tests should make it as easy as possible for you to understand why they failed. Custom matchers help you achieve that, but sometimes they are overkill. If all you need is to tweak the error message just a little bit, you can pass a second argument in your expectation. So, let's say you have this code:
expect(a).to have_something
When the test fails, you will see the following:
Failure/Error: expect(a).to have_something
expected #has_something? to return true, got false
You can change it to
expect(a).to have_something, "Nooo!"
And when the test fails, you will see the following, instead:
Failure/Error: expect(a).to have_something, "Nooo!"
Nooo!
Written by David Leal
Related protips
1 Response
This is awesome, still can't believe this was always there. Wow :)
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#