-
Notifications
You must be signed in to change notification settings - Fork 1
Test Runs
When running tests, you need to be sure to load in your test framework or your framework's RubyTest adapter. This is usually done via a helper script in the test files, but might also be done via command line options, e.g.
$ rubytest -r lemon -r ae test/test_*.rb
RubyTest supports dotopts out of the
box, so it easy to setup reusable options. For example, a .option file
entry might be:
rubytest
-f progress
-r spectroscope
-r rspecial
spec/spec_*.rb
The command line tool takes various options, use -h/--help to get a list
of all of them.
Sometimes it might not be possible to configure RubyTest properly just via
the command line. You need a way to script it. Generally a test helper script
that's required by every test can do the trick, but adding such a require to
every test isn't particularly DRY. Moreover, you might need to run some code
before the tests themselves being to run. For such cases there is the
-c/--config option which will simple require a file relative to the project's
root directory.
rubytest -c etc/test
In such files it is convenient to use the Test.configure interface.
Test.configure do |run|
run.format = 'progress'
run.files << 'test/test_*.rb'
endAnother way to run tests is via rubytest/autorun.rb script. This creates an
at_exit runner which will automatically run all tests that have been required.
So for example, one could write their own test/runner.rb script.
require 'rubytest/autorun'
require 'microtest'
Dir['test/*_test.rb'].each{ |f| require f }Then tests can be run simply by running this script.
$ ruby test/runner.rb
For convenience, test.rb provides a shortcut to the rubytest/autorun.rb
script so the above could be a little more succinct. It can also be used to
run a quick one off test via the ruby command, e.g.
$ ruby -rtest test/test_foo.rb
In truth it always best to use a build tool to run tests. Since Rake is the most popular build tool in the Rubydom, RubyTest include a pre-built rake task.
require 'rubytest/rake'
Test::RakeTask.new do |run|
run.format = 'tapy'
run.files << 'test/*_test.rb'
end
task :default => :testBy default this will create a task named test, as you can see by the example,
we have attached Rake's default task to it. You can change the name by passing
it in as an argument to the new constructor.
(coming soon)
tester = Detroit::RubyTest.new do |t|
t.format = 'tapy'
t.files << 'test/*_test.rb'
end
tester.test