[Ruby] Forcing exceptions in tests

Tom Lianza tom at lianza.org
Tue Oct 30 23:26:02 PST 2007


Hi all,

I have a case where one of my models ("ProductImage") has a dependency on
RMagick, and certain calls to it will fail if RMagick is not
installed/functioning properly.

I wanted to write some tests such that I can force that exception to happen,
primarily to ensure that other models which make use of ProductImage will
gracefully handle errors if they happen from within it.

Does anyone have any good ideas for how to handle these problems in
general?  My first instinct was to subclass ProductImage with another class
who's equivalent method would automatically throw an error. However, I know
there are a lot of testing gurus on this list so I figured I'd ask if there
was A Better Way.

Thanks,
Tom


More information about the Ruby mailing list