How to attach message to rspec check?

Alexey picture Alexey · Nov 15, 2010 · Viewed 11.6k times · Source

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"

Answer

Chris Johnsen picture Chris Johnsen · Nov 15, 2010

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.

update:

for RSpec 3:

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