Replies in line...

On 2/7/06, Paul Carvalho <[EMAIL PROTECTED]> wrote:
Okay, how that works is voodoo, man.

I understand what you mean by clarity (compared to my not-nil-if-block), but it's unintuitive to me how the next line is magically attached to the "assert" command without some kind of "if" statement.

It is very important that you understand this. I will try to explain, and if it's not clear please keep asking.

What assert does is "raise an exception" -- that is the "voodoo" magic. It is also how modern languages handle errors, so every tester needs to understand the concept.

Consider the following code

    puts "hello"
    raise "Error"
    puts "world"

This code will print "hello", then an exception will be raised. Typically this will exit the program. Or the exception can be "caught" by other code that called this code, in which case it decides what to do. In any case, "world" will never be printed.

All the assert does is raise an error conditionally. So this:

   assert($ie.contains_text("Please try again"))
   puts "TEST PASSED. Found test string: 'Please try again.' "

Is the same as

    if ! $ie.contains_text("Please try again")
       raise "error"
   end
   puts "TEST PASSED. Found test string: 'Please try again.' "


Can you describe how this line coherence works?  I noticed some strange behaviour in one script that I can't figure out yet.  Here's what my script does (in pseudo code):

def test_case_01
    open browser
    goto Reset Password page
    enter incorrect email address
    check that the correct error message appears ("assert" & output here)
    press the "cancel" button to return to the Login page
end

What I noticed is that if the assert line passes, then this script works as expected.  However, if the assert *doesn't* pass (i.e. the "contains_text" fails to find the message), then the next line is skipped.  So the "cancel" button is never pressed and the remaining test cases all break because they're not starting from the correct [login] page.

Right. That is exactly how assert works.
 
To get around this, I moved the "Press the "cancel" button" command to the start of the next test case.  That way it starts from the right place.

Do you know why this line is skipped (no matter how many blank lines I put between them) if the assert line fails?

Hopefully by now, this is clear to you.

One thing you should know is that  the  test/unit testing framework has a special  thing to handle this situation.

The teardown method is always called after each test method. So you might want to try this instead:

def test_case_01
    open browser
    goto Reset Password page
    enter incorrect email address
    check that the correct error message appears ("assert" & output here)
end

def teardown
    press the "cancel" button to return to the Login page
end
_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to