Test Driven Development is all about having a quick feedback loop. You know something’s broken immediately because your tests fail.
As projects grow you write more tests, and it takes more time to run your tests. It becomes increasingly important to be able to only run one test or the few tests you care about so you can keep moving with the code.
TextMate has some commands to do this (
Here’s how to do it with
Usually when I’m coding I have Vim open in split screen mode (with
rails.vim installed, of course.) I’ll have a spec file on one side, and the application code on the other.
I have this incredibly handy function and key mapping in my
.vimrc. Credit for this clever implementation goes to Art and Technology Consultant extraordinaire Ian Smith-Heisters.
" Execute open rspec buffer" Thanks to Ian Smith-Heistersfunction! RunSpec(args)if exists("b:rails_root") && filereadable(b:rails_root . "/script/spec")let spec = b:rails_root . "/script/spec"elselet spec = "spec"endlet cmd = ":! " . spec . " % -cfn " . a:argsexecute cmdendfunction" Mappings" run one rspec example or describe block based on cursor positionmap !s :call RunSpec("-l " . <C-r>=line('.')<CR>)" run full rspec filemap !S :call RunSpec("")
When I’m in the spec file I can hit
!s return to execute the example or describe block that the cursor is in.
!S return executes all the examples in that file.
The fancy descriptive output is just one of the nested formatter which comes included with Rspec. They can be specified with the
spec --help has more details on this.