In the post on Rails and Selenium I included a rake task for running the tests. For the lazy, here it is again.

<pre lang="ruby">namespace :test do
  Rake::TestTask.new(:selenium) do |t|
    t.libs 
<p>
That is handy if you want to run <i>all</i> your tests, but there are a lot of situations when you really don't want to do that. Like, when you building out new ones as I am doing now.<br></br>
<br></br>
So how do we constrain what gets run? The <a href="http://rake.rubyforge.org/classes/Rake/TestTask.html">TestTask</a> page helps us out by telling us about the TEST argument.<br></br>
</p>
<pre lang="bash">rake test:selenium TEST=selenium/forgot_password_test.rb
<p>
This tells rake to only run test methods in selenium/forgot_password_test.rb. One thing to remember is to include the directory it is under the test one (though I suppose you might be able to change t.libs in the actual task to be test/selenium, but...).<br></br>
<br></br>
Running only a single file is handy, but what if you are following the standard *unit pattern of having a number of logically groups test methods in a single class? By specifying just a filename you get all of them run which is still waaay too long. For this we need to dig a little deeper. Right to the actual test runner in fact.<br></br>
</p>
<pre lang="bash">adam:RB-1.0 adam$ testrb -h
Test::Unit automatic runner.
Usage: /usr/bin/testrb [options] [-- untouched arguments]

    -r, --runner=RUNNER              Use the given RUNNER.
                                     (c[onsole], f[ox], g[tk], g[tk]2, t[k])
    -b, --basedir=DIR                Base directory of test suites.
    -w, --workdir=DIR                Working directory to run tests.
    -a, --add=TORUN                  Add TORUN to the list of things to run;
                                     can be a file or a directory.
    -p, --pattern=PATTERN            Match files to collect against PATTERN.
    -x, --exclude=PATTERN            Ignore files to collect against PATTERN.
    -n, --name=NAME                  Runs tests matching NAME.
                                     (patterns may be used).
    -t, --testcase=TESTCASE          Runs tests in TestCases matching TESTCASE.
                                     (patterns may be used).
    -I, --load-path=DIR[:DIR...]     Appends directory list to $LOAD_PATH.
    -v, --verbose=[LEVEL]            Set the output level (default is verbose).
                                     (s[ilent], p[rogress], n[ormal], v[erbose])
        --                           Stop processing options so that the
                                     remaining options will be passed to the
                                     test.
    -h, --help                       Display this help.

Deprecated options:
        --console                    Console runner (use --runner).
        --gtk                        GTK runner (use --runner).
        --fox                        Fox runner (use --runner).
<p>
Hey! -n looks promising.<br></br>
<br></br>
But how to we get that information through rake to the runner? Going back to the TestTask page there is another argument; TESTOPTS.<br></br>
</p>
<pre lang="bash">rake test:selenium TEST=selenium/forgot_password_test.rb TESTOPTS="--name=test_forgot_password_no_email"
<p>
Eureka! It's a bit of extra typing, but with this you can run a single selenium script through rake.</p>