Hugh, Hummm... I am convinced that I don't have enough background in RUBY to really go forward in this discussion...
[Thom scrambles to find a good reference and sits down to read for a while...] I will e-mail more questions when I know the questions to ask... Thanks, Thom -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Hugh Sasse Sent: Wednesday, February 08, 2006 5:48 AM To: [email protected] Subject: Re: [Wtr-general] Assertions help On Tue, 7 Feb 2006, Thomas Healy wrote: > Hugh, > > I am a nubie and I understand what you are saying that less is more... > However, Readability of code is important for me... Especially when > explaining the code to others in the office and having others in the > office follow the code six months from now... Agreed. People have asserted that Ruby is very readable, in comparison to languages where everything must be declared up front, for example. They have said it can be used a pseudocode. I can't find that example now, but a google for [Ruby readable] will turn up a lot. > > While you are technically correct, less is more... In my case, > readability is a high priority for me and less is... Well, less. My > goal is to make it compact but readable by others... Tell me which bits are opaque, and it may be that we can express them differently. Some things will boil down to the object oriented nature of ruby and will be part of the syntax. This is Web Application Testing *In Ruby* after all :-) > > An example of the scripts I write is as follows... I would invite > suggestions on making it tighter but still retain the readability so > that 6 months from now when someone else in the office has to update > this script to make it work with changes to the webpage... It will be > easy to update and understand... > > def test_new_user > > #variables > test_site = 'http://a_location' > test_add_url = 'http://another_location' > test_FN_field = 'xxxxx' [other declarations trimmed.] If you use these a lot it might make sense to make the instance variables, declared in one place. Instance variables belong to your testing object, and are shared between methods of that object. They begin with @. Also you can do the setup in a method named setup def setup # do stuff in here that apply to all tests for this testing object # i.e. all methods that are called test_... end > test_CF_value = 'xxxxx' > test_select_index = 'xxxxx' > test_look_text = "This Student ID is already in use. Please select > another Student ID." > > #go to the test page > $ie.goto(test_site) > $ie.goto(test_add_url) The URL is sufficient: it includes the test site, so you can do that in one clear step. > > # add the page details > $ie.text_field(:name, test_FN_field).set(test_FN_value) [...] > $ie.text_field(:name, test_CF_field).set(test_CF_value) > $ie.select_list( :index , 1).select(test_select_index) > > #submit page > $ie.button(:name, "submit").click > > #check for expected text > begin > assert($ie.contains_text(test_look_text) ) > $logger.log("###NEW USER TEST PASSED####' ") > $logger.log_results("test_new_user", test_look_text, > test_look_text, "TEST PASSED.") You don't really need to log those. Collect the output of the whole testing framework with something like C:\> ruby my_tests1.rb > test1_results.txt That way you can use the results any way you like, you keep the details of logging outside the code, you don't need the rescue block because the asserts handle all the "bailing out if something is wrong" for you. Your assertions about what should be there are not mixed up with logging details. If the test passed, you got the expected results, which are already documented in this script, no need to write them out to the log. The framework only writes out differences from what you expect, along with what was expected. That means you can find them easily enough. And leaving out all the $logger lines makes the method shorter. > rescue => e > $logger.log("###NEW USER TEST FAILED####" + e.message + "\n" + > e.backtrace.join("\n")) > $logger.log_results("test_new_user", test_look_text, > test_look_text, "TEST FAILED.") > end > This bit is done after each test so can go in a teardown method: > #return to the admin page > $ie.link(:text, "administration").click def teardown #return to the admin page $ie.link(:text, "administration").click end > > > end # end test_new_user > > > Regards, > > Thom > HTH Hugh _______________________________________________ Wtr-general mailing list [email protected] http://rubyforge.org/mailman/listinfo/wtr-general _______________________________________________ Wtr-general mailing list [email protected] http://rubyforge.org/mailman/listinfo/wtr-general
