Well, I managed to come up with a solution before getting
any replies to this. Instead of creating full functions with the
begin/rescue included in them, I created functions of just the success actions
and the fail actions. So, instead of having a custom assert statement like
the original e-mail, I now use the stock assert statement and wrap it in the
begin/rescue:
In the include file:
def assert_success
put "It worked as expected, how
boring."
end
def assert_fail
put "New feature
found!"
end
In the specific test script:
begin
assert_match(blah, blah)
assert_success
rescue => e
assert_fail
end
So, I can't use a super-simple assert statement, but in the
end I'm still left with cleaner, easier code.
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Adam Reed
Sent: Wednesday, October 25, 2006 8:42 AM
To: [email protected]
Subject: [Wtr-general] Issue with assert.exists? and failure logging
I have
created a library of common functions that I include into every script I
write. One of these functions integrates common logging into the assert
function so that it doesn't have to be entered every time. If the object
exists, a success should be written to a general log, if it fails,
detailed information should be entered into a separate error
log. The code for that is:
begin
assert(element.exists? )
$scriptLog.puts "## \n## PASS: Test for #{element}"
#puts "PASS."
rescue => e
$error = "** ERROR: Test for #{element} **"
$errorLog = File.open("logs/#{Project}_error.log", File::CREAT|File::APPEND|File::WRONLY)
$errorLog.puts "#############################################"
$errorLog.puts "## One or more errors found in #{$Testname}\n"
$errorLog.puts "## Time: #{$d}"
$errorLog.puts "## \n## #{$error}"
$errorLog.puts "#############################################\n"
$scriptLog.puts "## \n## #{$error}"
puts $error
end
end
The
problem that I'm running into is that even though the function itself is wrapped
in begin/rescue, if I call the function and it fails in my actual testcase, the
script aborts because of the failure. For instance,
if
rc_assert_exists(ie.link(:url, 'google.com')) passes or fails, no information is
written to the log. However, if I get redundant and
use:
begin
rc_assert_exists(ie.link(:url,
'google.com'))
rescue
=> e
puts "failed"
end
The
script does not end when it fails, and "failed" is written to the screen
output.
So, I
assume that begin/rescue only matters to the actual test case that's calling it
and it can't be called from a separate file. What else can I
do?
_______________________________________________ Wtr-general mailing list [email protected] http://rubyforge.org/mailman/listinfo/wtr-general
