How do I execute a single test using Ruby test/unit?

pierrotlefou picture pierrotlefou · Jun 29, 2011 · Viewed 18.4k times · Source

Instead of running all the test cases automatically, is there any way to execute a single test under ruby test/unit framework. I know I can achieve that by using Rake but I am not ready to switch to rake at this moment.

ruby unit_test.rb  #this will run all the test case
ruby unit_test.rb test1 #this will only run test1

Answer

Pete picture Pete · Jun 29, 2011

you can pass the -n option on the command line to run a single test:

ruby my_test.rb -n test_my_method

where 'test_my_method' is the name of the test method you would like to run.