Reputation: 303
I'm working on a project that has legacy tests written in minitest. How do you run just one assertion out of a test file?
Note: I have the answer for my question, I'll post it in a moment. I'm putting this here so that a) it can benefit others, and b) if I either lose track of my answer, or forget that I figured this out, hopefully I'll find this myself. And have a good laugh.
Upvotes: 0
Views: 819
Reputation: 303
Answering my own question, so that others can benefit, and if I forget, hopefully I'll find it...
I discovered two discinct ways to run these tests, as well as how to specify the options. The syntax differs slightly depending on how you run them. However, the most important details are these:
"test: "
and suffix it with ". "
- both of those trailing spaces are critical/whatever/
as a regex-n
or --name
Here are two ways of running a single assertion from a single test file:
bundle exec ruby -Itest path/to_test.rb '--name test_: the exact test name as discovered by running with -v. '
bundle exec rake test TEST=path/to_test.rb TESTOPTS="--name 'test_: the exact test name as discovered by running with -v. '"
And here's how it looks if you use a regex:
bundle exec rake test TEST=path/to_test.rb TESTOPTS="--name '/test name as discovered/'"
Note that there are different ways to deal with the quoting/escaping of course, and it seems you can use -n=value
in addition to -n value
.
Upvotes: 1