[rspec-users] Exception handling

Marcos Chicote totochicote at gmail.com
Wed Jun 30 10:29:25 EDT 2010

On Wed, Jun 30, 2010 at 11:12 AM, David Chelimsky <dchelimsky at gmail.com>wrote:

> On Jun 30, 2010, at 9:05 AM, Marcos Chicote <totochicote at gmail.com> wrote:
> I don't think so, but I don't really know how to check it programatically.
> I don't mean exceptions in *before/after *methos, but inside *it()* method
> I would like to write something like this:
> after(:each) do
> if exception_occured_on_it_method?
> do_something
> end
> end
> Is that possible?
> What problem are you trying to solve?

I'm using rspec to build tests using Watir.

On *before(:each)*, I create the browser instance and login lazily to a web
page (if the browser exists, I use that instance, if it does not, I create a
new one). I'm using this lazy approach in order to save the time of openning
a new browser and login for each test (I could close the browser on *
after(:each)* but this is faster).

I most cases (when test are passed), everything works great. The problem is
that sometimes the page I'm trying to access doesn't load (or there is some
other non functional problem), the browser keeps wating and an timer that I
implemented timesout.This timeout raises an exception that makes the test
fail, but does not close the browsers windows (that keeps wating for the
response), making following tests to fail.

If I could handle timeout exception in the way I posted before, I could
close the browser and the next test will open a fresh one.

(Note: this is only and example, there are some other exceptions thay might
occur, html element missing for example, that I want to handle the same way
and that's why I need a unified mechanism)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100630/c93f796b/attachment.html>

More information about the rspec-users mailing list