Rails3 - How to run only specific tests?

To run all tests:

$ rake test

To run only unit tests:

$ rake test:units

To run only functional tests:

$ rake test:functionals

To run only integration tests:

$ rake test:integration

To run only tests in specific file:

$ ruby -Ilib:test test/unit/user_test.rb

Run only specic test:

$ ruby -Ilib:test test/unit/user_test.rb -n test_should_generate_salt

Run only couple of specic tests:

$ ruby -Ilib:test test/unit/user_test.rb -n /.*password.*/

To see executed methods use verbose mode:

$ ruby -Ilib:test test/unit/user_test.rb -n /.*user.*/ -v
Loaded suite test/unit/user_test
UserTest#test_should_validate_username_length: 0.82 s: .
UserTest#test_should_validate_username_uniqueness: 0.04 s: .

Finished in 0.886984 seconds.

2 tests, 4 assertions, 0 failures, 0 errors, 0 skips

Test run options: --seed 64903 --verbose --name "/.*user.*/"
Milosz Galazka's Picture

About Milosz Galazka

Milosz is a system administrator working for a successful Polish company and a long time supporter of Free Software Foundation and Debian operating system.

Gdansk, Poland https://sleeplessbeastie.eu