Custom error handling

Hello everyone,

I’m currently using rspec2 wit capybara to do some selenium tests. I
want to put this on a CI server and run the tests regularly. capybara
already has a functionality to save a screenshot. I’d like to save a
screenshot whenever a test does not pass.

So my question is:

How do i customize the default error handling of rspec to do some
custom actions, before the test actually fails (getting an id or the
string of the name would also be very cool).