Chris McMahon wrote:
>>from scripts that have errors. Our developers pointed out that
>>providing the HTML source of the page loaded in IE at the time of the
>>error would be great.
>>
>>
>
> begin
> assert(ie.foo == x)
> rescue => e
> puts ie.getHTML
> end
>
>would do it, yes?
>-C
>
>
Yeah, that'll do fine for a single assertion or even a single test_
method if it is wrapped around. You are forced to duplicate the code
around every area that's liable to break.
I think I figure out a solution that is more convenient in terms of
reducing code duplication... here's an example:
class PageSourceError < Test::Unit::Error
def initialize(test_name, exception)
if $ie
begin
@pagesource = $ie.getHTML
rescue
@pagesource = nil
end
end
super
end
def long_display
if @pagesource
return "#{super}\nPage Source: [EMAIL PROTECTED]"
else
return super
end
end
end
class PageSourceTestCase < Test::Unit::TestCase
# Overrides the default add_error method to trap the page source
(if available)
def add_error(exception)
@test_passed = false
@_result.add_error(PageSourceError.new(name, exception))
end
private :add_error
end
You then declare your test cases to inherit from PageSourceTestCase
instead of Test::TestCase and you get error trapping for free.
Note that I have just been playing with this code... it has a few
issues, and isn't ready for prime time yet.
--
Alf Whitehead <[EMAIL PROTECTED]> 416-214-4977 x260
Quality Assurance Specialist
Klick Communications, http://klick.com/
_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general