UPDATE: everything is now on github
Testing a single spec, a single test, a single testcase or a single example is a great timesaver when debugging a small problem while having a large testsuite, or a testsuite with a lot of failures…
- rake test:blog -> only the Blog Testcase
- rake spec:blog -> only the Blog Spec
- rake test:blog:create -> only the tests matching /create/ in Blog
- rake spec:blog:delete -> only the first example matching /create/ in Blog
- rake test:’admin/blogs_con’ -> only BlogsController Test in admin folder
- rake test:xy -> first test matching xy*_test.rb (searched in order: unit,functional,integration,any folder)
It will search in unit/functional/integration (test) and models/controllers/views/helpers(spec).
Idea
Install:
UPDATE: everything is now on github
I use autotest, so I find it easier to use an editor macro that disables all tests apart from the one I’ve got the cursor in, and saves the file.
Then, when autotest picks up the changes, only that one test/spec runs.
D
Sounds good too, but i am not working with textmate and sometimes only with vi from the console so this was no option for me.
@David: I also use autotest. Using the editor to disable all other tests sounds great! I don’t suppose your editor is vi (like mine)? No? Oh, well. 🙂
The best I’ve been able to manage is two abbreviations: one to add ‘if nil ####’ and another for ‘end ###’. One problem is that I use RSpecl, so there are often nesting levels that have to be taken into account.
Any more information about your macro you think might be helpful would be welcome!
///ark
Hi – good post. I solved this same problem but without your plug-in goodness:
http://www.misuse.org/science/2006/12/21/testing-a-single-file-in-ruby-on-rails/
The one thing I added which you don’t have (I think) is testing when a test file changes, and re-running only that test. Feel free to have a look at my code above, and rip out whatever you want for your plugin, if it’s useful!
Oh goodness, that was the old URL. Here’s the new code!
http://www.misuse.org/science/2009/03/25/continuous-testing-and-testing-single-methods-in-ruby-on-rails/
Sorry for the double comment – feel free to edit/consolidate.
ill have a look, im interested how you solved the problem 🙂
generally when i want it to rerun a test after modifications i use autotest, so i might not include this feature…
yep your approach is a bit simpler, without all the file-choosing logic i do, so it runs more files for a given command which can be an advantage. Only sad thing is that it does not support rspec…