How can I run a single test from a rails test suite?
rake test ANYTHING
seems to not help.
In rails 5,
I used this way to run single test file(all the tests in one file)
rails test -n /TopicsControllerTest/ -v
look here https://stackoverflow.com/a/41183694/3626659
Rails folder
bundle install
bundle exec ruby -I"activerecord/test" activerecord/test/cases/relation/where_test.rb
Note you need to load appropriate folder: "activerecord/test" (where you have test)
Run a test file:
rake test TEST=tests/functional/accounts_test.rb
Run a single test in a test file:
rake test TEST=tests/functional/accounts_test.rb TESTOPTS="-n /paid accounts/"
(From @Puhlze 's comment.)
In my situation for rake
only works TESTOPTS="-n='/sample/'"
:
bundle exec rake test TEST=test/system/example_test.rb TESTOPTS="-n='/sample/'"
First, access the folder of the lib you want to test(this is important) and then run:
~/Projects/rails/actionview (master)$ ruby -I test test/template/number_helper_test.rb
Thanks to @James, the answer seems to be:
rails test test/models/my_model.rb:22
Assuming 22 is the line number of the given test. According to rails help:
$ rails test --help
You can run a single test by appending a line number to a filename:
bin/rails test test/models/user_test.rb:27
Also, please note that your test should inherit from ActionDispatch::IntegrationTest for this to work (That was my mistake):
class NexApiTest < ActionDispatch::IntegrationTest
.
.
.