Friday, July 20, 2012

Run all tests related to a method you just refactored

$ sudo apt-get install ack-grep

For Ruby:
$ ack-grep "method_foo_bar" -l spec | xargs script/spec

For PHP
$ ack-grep "method_foo_bar" -l tests | xargs phpunit

3 comments:

cweiske said...

What about simply running:

$ phpunit --filter method_name .

Dan said...

That will pick up test names which match.

If you have a test which uses the affected code but has a different purpose, ack-grep should be able to detect it and run the whole suite.

Likely with some test runners (ie: rspec), it'll probably even take ack-greps file+line number format and execute only that block...

Dan said...

ie:
function testFoo() {
bar()
}
$ phpunit --filter bar
$ ack-grep "bar\(" -l | xargs phpunit