I'm answering into the group directly - maybe someone else finds this also useful.
Think of the helpers as a collection of methods which will be used throughout the tests. You could do many modules. Some modules would be specific to your current application under test and some others would be even more global. So if you start testing some new web application then there are already some modules which you can include and then use those methods from there. In addition you can create a separate module for this project which has it specific methods. So, your idea below is almost correct, but think about it as a hierarchy. Let's say that you have 2 software projects going on - ProjectOne and ProjectTwo. So, i would do something like this: global_helper.rb - this is at some globally accessible place on the filesystem: # put here also all global requires require 'watir' require 'spec' # you may require also this, since some IDE-s allow you to run specs then with their formatter module GlobalHelper def global_method_one # do something end def global_method_two # do something else end end project_one_helper.rb - this is located under ProjectOne: # make sure that you've handled the $LOAD_PATH so you can do like this: require 'global_helper' module ProjectOneHelper include GlobalHelper def project_one_method # do something specific to project_one end end project_two_helper.rb - this is located under ProjectTwo: # make sure that you've handled the $LOAD_PATH so you can do like this: require 'global_helper' module ProjectTwoHelper include GlobalHelper def project_two_method # do something specific to project_two end end project_one_spec.rb - so, now in some ProjectOne test you just have to do like this: require 'project_one_helper' describe "something in ProjectOne" do include ProjectOneHelper # you don't have to include GlobalHelper anymore since it is already included it "does something" do global_one_method project_one_method end end And something similar goes to ProjectTwo specs. So, that's how you can keep your code modularized and hopefully follow the practices of DRY (http://en.wikipedia.org/wiki/Don't_repeat_yourself). But when coming back to your concrete example, then i'd suggest you to read about RSpec Matchers (http://rspec.rubyforge.org/rspec/1.3.0/ classes/Spec/Matchers.html). So, let's say that you are dealing with ProjectTwo, then i would do it something like this - project_two_helper.rb: require 'global_helper' module ProjectTwoHelper include GlobalHelper def setup @browser = Watir::Browser.new @browser.goto "http://url.com" end def header @browser.div(:id => 'header') end def has_correct_header? header.text.should == 'this is the header' end end and in project_two_spec.rb: require 'project_two_helper' describe "ProjectTwo" do before :all do setup end it "has header" do should have_correct_header end end There are some other nifty tricks in RSpec, but i can just recommend you to read RSpec book (http://www.pragprog.com/titles/achbd/the-rspec- book - i haven't read it myself though) or just wander around in it's RDoc http://rspec.rubyforge.org/rspec/1.3.0/ Jarmo On Thu, Feb 25, 2010 at 5:28 PM, Adam Reed <reed...com> wrote: > Jarmo, > > Thank you very much for your insightful reply. You definitely addressed my > weak point with Rspec right now which is the test organization and structure > (modules vs. other constructs). I will certainly subscribe to your RSS > feed! > > I was wondering if I might be able to ask you one more questions here. I've > read about RSpec and have Google searched for a few of these topics, but was > not able to find much help. Learning Watir was definitely a trial-and-error > exercise a few years ago, so I'd like to get a better start with RSpec > without having to go back and redesign everything because of early mistakes! > > In the specific test that I'm writing, for instance, I want to verify some > global elements -- that the page does not show an error (as you described in > your reply to my thread), that the footer exists and is correct, that the > header exists and is correct, etc. All pages and all tests need to include > these. At this point, I'm not sure how to handle those global tests -- my > first inclination was shared_methods/helpers, but it appears that I would be > better served by a module contained in a separate script that can be > required and included in each other script. Would the following be correct? > > Thanks again for your time, > > Adam Reed > > E.g.: > > global.rb: > module GlobalTests > def footer > ... > end > > def header > ... > end > end #module > > sample_test.rb: > require 'global.rb > > (and then, the same content you posted in the reply to my original question) > -- You received this message because you are subscribed to the Google Groups "Watir General" group. To post to this group, send email to watir-general@googlegroups.com Before posting, please read the following guidelines: http://wiki.openqa.org/display/WTR/Support To unsubscribe from this group, send email to watir-general+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/watir-general