Very briefly, there are two things you can do to split your code into separate files.

1. Put your test methods in separate files.
2. Put your custom methods in separate files.

And then after doing this, you have to be able to put it all together again.

You can put test methods in different classes defined in different files. It is best if you put them in classes with different names (but they should all be subclasses of Test::Unit::TestCase).

To stitch them back together again, all you have to do is create a master script that require's each of the test scripts.

You can put your custom methods in a module that is defined in a separate file.

module TestsApplicationFoo
  def custom_method_1
    ...
  end
end

Then you can use the methods thus:

require 'tests_application_foo' # name of the file with TestApplicationFoo module

class MyTests < Test::Unit::TestCase
  include TestsApplicationFoo
  def test_1
    ...
    custom_method_1
  end
end

This is brief, but should set you in the right direction as you read the various Ruby references.

Bret

On 3/2/06, Paul Carvalho <[EMAIL PROTECTED]> wrote:
I have this one script that I'm working on that is just getting bigger as I go along.  I would like to break out some of the smaller chunks/tests into separate script files, but I'm not sure of the logistics of this.  I tried looking at the unittests but I couldn't answer my questions by looking at them.

For example, my one (master) script is set up like the following:
----
#includes
#global variables

class TC_blahblahblah < Test::Unit::TestCase
    def cust_method_1
        ...
    end

    def cust_method_2
        ...
    end

    test_a_somename
        yadda yadda yadda
    end

    test_b_somename
    ....
end
----

Now, if I break out "test_a_somename" into a separate script, what is the correct format for calling/running it from within the master script?

In the new sub-script, do I have to repeat the "class TC_blahblahblah < Test::Unit::TestCase" structure, or just put the "test_a_somename" structure?  Do I have to re-include all the require/include lines that were in the master script?  (I don't think I should, but I'm not sure.)

If I have methods that are defined in the master script, will they be properly called from one of the sub-scripts, or do I have to put them in the sub-scripts too? (I expect it to work if they're only defined in the master script.)

Please forgive these basic questions.  I searched the message archives but I couldn't find anything helpful other than "you should break up large scripts into smaller ones when they get too long (like ~ 1000 lines)".  And I haven't had any success scanning the other Ruby/Watir documentation to give me practical advice on how to do this either.

Paul.


_______________________________________________
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

Reply via email to