Doug Bryant

Tech thoughts and notes

Another Great Thing About Ruby - the Unit Testing

The more I use ruby, the more I love it. I ran across this today – the ability to run individual unit tests.

You can run an individual test method within a test case by providing the -n switch after the ruby file containing the tests. the -n argument accepts either an absolute test method name or a regular expression which will run all the tests which match the expression.

codepre
ruby test/foo_test.rb
/pre/code
This runs all the tests within foo_test.rb.

codepre
ruby test/foo_test.rb -n test_bar
/pre/code
This runs the individual test method named test_bar within foo_test.rb

codepre
ruby test/foo_test.rb -n /bar/
/pre/code
This runs all the test methods within foo_test.rb which contain the string “bar”.