Alex Rivera | Logout

How to attach a message to RSpec check?

Asked 2010-11-15T11:02:06.537
46

In RSpec: Can I attach a message to a check the same way as I would do in xUnit style test frameworks? How?

assert_equal value1, value2, 'something is wrong'
Edit
Report

1 Answer

62

For RSpec 3+:

The message could be customized as a string or using a proc(check the reference).

expect(1).to eq(2), 'one is not two!'

Customized message RSpec tries to provide useful failure messages, but for cases in which you want more specific information, you can define your own message right in the example. This works for any matcher other than the operator matchers.

source @ relishapp


For older RSpec versions

should and should_not take a second argument (message) that overrides the matcher’s default message.

1.should be(2), 'one is not two!'

The default messages are usually pretty useful though.

answered 2010-11-15T11:40:38.290

Your Answer