The following answer is based on: How to run a single test from a rails test suite? (stackoverflow)
But very briefly, here is the answer:
ruby -I test test/functional/whatevertest.rb
For a specific functional test, run:
ruby -I test test/functional/whatevertest.rb -n test_should_get_index
Just put underscores in the spaces in the test names (as indicated above) or specify a title as follows:
ruby -I test test/functional/whatevertest.rb -n 'test should get index'
Note that for unit tests, simply replace functional with unit in the examples above. And if you use bundler to manage your gem dependencies of your application, you will need to run tests using bundle exec as follows:
bundle exec ruby -I test test/unit/specific_model_test.rb bundle exec ruby -I test test/unit/specific_model_test.rb -n test_divide_by_zero bundle exec ruby -I test test/unit/specific_model_test.rb -n 'test divide by zero'
Most importantly , note that the argument for the -n switch is the name of the test, and the word "test" is added to it with spaces or underscores, depending on whether you quote the name or not. The reason is that test is a convenience method. The following two methods are equivalent:
test "should get high" do assert true end def test_should_get_high assert true end
... and can be executed as one of the following (they are equivalent):
bundle exec ruby -I test test/integration/misc_test.rb -n 'test should get high' bundle exec ruby -I test test/integration/misc_test.rb -n test_should_get_high
user664833 Nov 02 '11 at 19:35 2011-11-02 19:35
source share