Testing a single Example; Spec; Testcase; Test

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

7 thoughts on “Testing a single Example; Spec; Testcase; Test

  1. 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

  2. @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

  3. 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…

  4. 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…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s